-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatd_osrm.py
40 lines (36 loc) · 1.54 KB
/
atd_osrm.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
import csv
import urllib.request, json
from geojson import Point, Feature, FeatureCollection, dump
features = []
mode = "routed-car" #routed-bike
with open('allthedocks_list.tsv') as csvfile:
rows = csv.reader(csvfile, delimiter='\t')
currstage = 'cmt'
currcoords = ''
coordslist = []
for row in rows:
stage = row[5].split('.')[0]
if stage == 'cmt':
continue
if currstage != stage and currstage != 'cmt':
coordstr = ';'.join(coordslist)
print(currstage + ': ' + coordstr)
with urllib.request.urlopen("https://routing.openstreetmap.de/" + mode + "/trip/v1/driving/" + coordstr + "?overview=full&roundtrip=false&source=first&destination=last&geometries=geojson") as url:
data = json.load(url)
geom = data['trips'][0]['geometry']
features.append(Feature(geometry=geom, properties={"stage": currstage}))
coordslist = []
coordslist.append(currcoords) #Previous stage's last location.
currcoords = row[3] + ',' + row[2]
coordslist.append(currcoords)
currstage = stage
#Do the final one
coordstr = ';'.join(coordslist)
print(currstage + ': ' + coordstr)
with urllib.request.urlopen("https://routing.openstreetmap.de/" + mode + "/trip/v1/driving/" + coordstr + "?overview=full&roundtrip=false&source=first&destination=last&geometries=geojson") as url:
data = json.load(url)
geom = data['trips'][0]['geometry']
features.append(Feature(geometry=geom, properties={"stage": currstage}))
feature_collection = FeatureCollection(features)
with open('atd2osrm_' + mode + '.geojson', 'w') as f:
dump(feature_collection, f)