Repository navigation
Expand file tree
/
Copy pathdownloadOSM.py
More file actions
66 lines (48 loc) · 2.24 KB
/
Copy pathdownloadOSM.py
File metadata and controls
66 lines (48 loc) · 2.24 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
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import urllib
import urllib2
import subprocess
from subprocess import Popen, PIPE
def download(map_file, extent):
url = 'http://api.openstreetmap.org/api/0.6/map'
encoded_url = '{0}?bbox={1}'.format(url, extent)
print encoded_url
response = urllib2.urlopen(encoded_url)
with open(map_file, 'w') as writeable:
writeable.write(response.read())
def osm2pgrouting(map_file, config_file, database, username, password):
osm2pgrouting = 'osm2pgrouting'
upload_command = 'osm2pgrouting -file {0} -conf {1} -dbname {2} -user {3} -passwd {4}'.format(map_file,
config_file,
database,
username,
password)
print upload_command
subprocess.call(upload_command)
#upload_response = subprocess.Popen(upload_command, stdout=PIPE)
#output, errors = upload_response.communicate()
print output
def osm2pgsql(map_file, style_file, database, username, password):
upload_command = 'osm2pgsql'
hostname = 'localhost'
upload_command = '{0} -c -d {1} -U {2} -H {3} -S {4} {5}'.format(upload_command, database, username, hostname, style_file, map_file)
print upload_command
subprocess.call(upload_command)
#output, errors = upload_response.communicate()
#print output
if __name__ == '__main__':
extent = sys.argv[1]
map_file = sys.argv[2]
config_file = sys.argv[3]
style_file = sys.argv[4]
database = sys.argv[5]
username = sys.argv[6]
password = sys.argv[7]
if not map_file:
raise InputError('Output file required')
if not (extent or len(extent.split(',')) == 4):
raise InputError('Extent is required in format XMIN,YMIN,XMAX,YMAX')
print extent, map_file, config_file, style_file
#download(map_file, extent)
#osm2pgrouting(map_file, config_file, database, username, password)
osm2pgsql(map_file, style_file, database, username, password)