How can i plot a map using Latitude and longitude data in python & Highlight few Latitude and Longitude points in the map ?ints
Asked Answered
I

1

6

I am new in working with python.

I have a question regarding How to plot a map in Python using Latitude and Longitude data ?

What i have done before :

Step 1 : I have a CSV file which contains Information about Vehicle Driving signal.
Step 2 : From the File I have extracted some Latitude and Longitude Data in the form of pandas Data frame.
Step 3 : Now i save that Data frame as CSV File.
Step 4 : After saving, I am giving that file to Online GPS Visualizer, so it generates a Open street map.

[![enter image description here][1]][1]

Requirement No :1

I just want the same map to be plotted in python instead of giving the Lat&Long csv file to Online GPS Visualizer. So which Library I should use ? Base map Library is suited for my work or should i go for another alternative ?

Requirement No : 2

After plotting the map in python i just want to Highlight few Latitude and Longitude points in the map. (As Pointed in the image)

Impracticable answered 31/1, 2019 at 7:48 Comment(1)
try to take a look at folium: pythonhow.com/web-mapping-with-python-and-folium It should be quite easy if you follow the examples you find onlineAlger
A
7

As suggested by this link1 and link2 you can achieve some similar results. Here is what the code looks like for example.

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")
Alger answered 31/1, 2019 at 8:41 Comment(1)
nice answer! I added an example code in case you have csv with lat/long sorted by timestamp: gist.github.com/deparkes/…Shoreline

© 2022 - 2024 — McMap. All rights reserved.