Last active
April 28, 2018 10:28
-
-
Save ustroetz/4c0ba2b133ef76008c6efa7f0ca41f02 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
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