Last active
March 24, 2019 08:06
-
-
Save Sangarshanan/ccdc9d65c7ebd5a17974ef15b548d037 to your computer and use it in GitHub Desktop.
This file contains 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 pandas as pd | |
import urllib.request | |
### GRAPHOPPER API ### | |
urlStart = 'http://localhost:8989/route/?' | |
point = 'point=' | |
urlEnd = '&type=gpx&instructions=false&vehicle=car' | |
separator = '%2C' | |
### SOURCE POINT ### | |
startY = '12.9716' | |
startX = '77.5946' | |
### DESTINATION POINT ### | |
start1X = '12.95296573' | |
start1Y = '77.70433044' | |
req = urlStart + point + startY + separator + startX + '&' + point + start1X + separator + start1Y + urlEnd | |
resp = urllib.request.urlopen(req) | |
gpxData = str(resp.read(),'utf-8') | |
#save it as a gpx file | |
fileName = 'roadpath' | |
saveFile = open('{0}.gpx'.format(fileName), 'w') | |
saveFile.write(gpxData) | |
saveFile.close() | |
### CONTINUE FROM HERE IF YOU ALREADY HAVE THE GPX FILE ### | |
import gpxpy | |
gpx_file = open('roadpath.gpx', 'r') | |
gpx = gpxpy.parse(gpx_file) | |
#EXTRACT THE LATLONGS IN THE GPX FILE | |
latlongs = [] | |
for track in gpx.tracks: | |
for segment in track.segments: | |
for point in segment.points: | |
latlongs.append((point.latitude,point.longitude)) | |
from ipyleaflet import Map, Polyline, Marker | |
center = latlongs[int(len(latlongs)/2)] | |
### RUN THIS ON JUPYTER TO PLOT THE ROAD PATH ### | |
line = Polyline( | |
locations = latlongs, | |
color = "green" , | |
) | |
m = Map(center = center, zoom =12) | |
m.add_layer(line) | |
m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment