Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ustroetz
Last active April 28, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ustroetz/4c0ba2b133ef76008c6efa7f0ca41f02 to your computer and use it in GitHub Desktop.
Save ustroetz/4c0ba2b133ef76008c6efa7f0ca41f02 to your computer and use it in GitHub Desktop.
with open('connection_lines.geojson') as connection_lines_file:
connection_lines = json.loads(connection_lines_file.read())
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(
access_token=os.environ['MAPBOX_ACCESS_TOKEN'])
response = directions_service.directions(
[origin, destination], 'mapbox.driving', alternatives=False)
route_feature = response.geojson()['features'][0]
route_feature['properties'] = line_feature['properties']
route_features.append(route_feature)
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