Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
with open('connection_lines.geojson') as connection_lines_file:
connection_lines = json.loads(
route_features = []
for line_feature in connection_lines['features']:
origin = {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': line_feature['geometry']['coordinates'][0]}}
destination = {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': line_feature['geometry']['coordinates'][1]}}
directions_service = Directions(
response = directions_service.directions(
[origin, destination], 'mapbox.driving', alternatives=False)
route_feature = response.geojson()['features'][0]
route_feature['properties'] = line_feature['properties']
routes_gdf = gpd.GeoDataFrame.from_features(route_features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment