Created
May 2, 2016 13:18
-
-
Save deparkes/9a0b45c69beb9a614f54d13bc7c551b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gpxpy | |
import gpxpy.gpx | |
import folium | |
gpx_file = open('path_to_gpx_file.gpx', 'r') | |
gpx = gpxpy.parse(gpx_file) | |
points = [] | |
for track in gpx.tracks: | |
for segment in track.segments: | |
for point in segment.points: | |
points.append(tuple([point.latitude, point.longitude])) | |
print(points) | |
ave_lat = sum(p[0] for p in points)/len(points) | |
ave_lon = sum(p[1] for p in points)/len(points) | |
# Load map centred on average coordinates | |
my_map = folium.Map(location=[ave_lat, ave_lon], zoom_start=14) | |
#add a markers | |
for each in points: | |
folium.Marker(each).add_to(my_map) | |
#fadd lines | |
folium.PolyLine(points, color="red", weight=2.5, opacity=1).add_to(my_map) | |
# Save map | |
my_map.save("./gpx_berlin_withmarker.html") |
Hi @angelomalfitano - it seems like it's an issue with your CSV. Can you upload it?
Hello @philshem recreate .csv and it works without any issue! thank you Angelo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello philshem, thank you for your code. I've a problem with line 5. I named correctly the colums in file in.csv but I receive this message:
Traceback (most recent call last):
File "C:\Users\angelo\Desktop\map\gpslatlong.py", line 5, in
df = df[['latitude','longitude']] # change to your column names, assume the columns are sorted by time
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\frame.py", line 3511, in getitem
indexer = self.columns._get_indexer_strict(key, "columns")[1]
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 5782, in _get_indexer_strict
self._raise_if_missing(keyarr, indexer, axis_name)
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 5842, in _raise_if_missing
raise KeyError(f"None of [{key}] are in the [{axis_name}]")
KeyError: "None of [Index(['latitude', 'longitude'], dtype='object')] are in the [columns]"
Do you have any ideas?
Thank you
Angelo