-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosm_from_extents.py
More file actions
54 lines (41 loc) · 1.2 KB
/
osm_from_extents.py
File metadata and controls
54 lines (41 loc) · 1.2 KB
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
45
46
47
48
49
50
51
52
53
54
# function for downloading osm data given extents
import subprocess
import csv
def dl_osm_from_extents(xmax, xmin, ymax, ymin):
url = 'http://overpass-api.de/api/map?bbox=' + str(xmin) + ',' + str(ymin) + ',' + str(xmax) + ',' + str(ymax)
subprocess.call(["wget", url])
temp_name = 'map?bbox=' + str(xmin) + ',' + str(ymin) + ',' + str(xmax) + ',' + str(ymax)
# rename to map.osm.xml
subprocess.call(["mv", temp_name, "osrm/map.osm.xml"])
# e.g.
dl_osm_from_extents(-77.5,-78,46,45.5)
# ---------------------------
# alternative for downloading via coordinate extents in a .csv file
# # grabbing all blocks from csv and put into an array
# db = []
# with open('db.csv','r') as csvfile:
# reader = csv.reader(csvfile)
# for row in reader:
# header = row
# break
# for row in reader:
# if row != header:
# db.append(row)
#
# # print header for erf
# print header
#
# X = []
# Y = []
# for row in db:
# X.append(float(row[0]))
# Y.append(float(row[1]))
#
# print min(Y)
# print max(Y)
# print min(X)
# print max(X)
#
# # then grab the data, accordingly
# dl_osm_from_extents(max(X) + 0.02, min(X) - 0.02, max(Y) + 0.02, min(Y) - 0.02)
##########