-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
44 lines (34 loc) · 1.06 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import openrouteservice
from openrouteservice import convert
import shapely
import geojson
import os
import json
'''
install ors library:
https://openrouteservice-py.readthedocs.io/en/latest/
get your api key:
https://openrouteservice.org/dev/#/home
paste it into key.txt (keep your key to yourself!)
'''
print(os.getcwd())
routes = []
start = (8.34234,48.23424)
end = (8.34423,48.26424)
coords = (start, end)
keyfile = open('key.txt', 'r')
key = keyfile.read()
client = openrouteservice.Client(key=key) # Specify your personal API key
# decode_polyline needs the geometry only
profile = 'cycling-regular'
extra_info = ['steepness', 'suitability', 'surface', 'waycategory', 'waytype']
response = client.directions(coords, profile = 'cycling-regular', extra_info = extra_info)
print(response)
geometry = response['routes'][0]['geometry']
routes.append(geometry)
with open('response.json', 'w') as outfile:
json.dump(response, outfile)
decoded = convert.decode_polyline(geometry)
with open('route.geojson', 'w') as outfile:
json.dump(decoded, outfile)
#print(decoded)