mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-12 16:46:50 +02:00
Getting data from OpenStreetMap.
This commit is contained in:
parent
c3efa19ea4
commit
9e7f219b11
3 changed files with 45 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,6 +13,7 @@
|
||||||
*.png
|
*.png
|
||||||
*.pyc
|
*.pyc
|
||||||
*.svg
|
*.svg
|
||||||
|
missed_tags.yml
|
||||||
|
|
||||||
# Test scheme files
|
# Test scheme files
|
||||||
|
|
||||||
|
|
BIN
lib/network.pyc
Normal file
BIN
lib/network.pyc
Normal file
Binary file not shown.
44
osm_getter.py
Normal file
44
osm_getter.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.append('lib')
|
||||||
|
|
||||||
|
import network
|
||||||
|
|
||||||
|
usage = '<box coordinates: left,bottom,right,top>'
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print 'Usage: python ' + sys.argv[0] + ' ' + usage
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
boundary_box = sys.argv[1]
|
||||||
|
|
||||||
|
matcher = re.match('(?P<left>[0-9\\.-]*),(?P<bottom>[0-9\\.-]*),' + \
|
||||||
|
'(?P<right>[0-9\\.-]*),(?P<top>[0-9\\.-]*)', boundary_box)
|
||||||
|
|
||||||
|
def error(message=None):
|
||||||
|
if message:
|
||||||
|
print 'Error: ' + message + '.'
|
||||||
|
else:
|
||||||
|
print 'Error.'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if not matcher:
|
||||||
|
error('invalid boundary box')
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
left = float(matcher.group('left'))
|
||||||
|
bottom = float(matcher.group('bottom'))
|
||||||
|
right = float(matcher.group('right'))
|
||||||
|
top = float(matcher.group('top'))
|
||||||
|
except Exception as e:
|
||||||
|
error('parsing boundary box')
|
||||||
|
if left >= right:
|
||||||
|
error('negative horisontal boundary')
|
||||||
|
if bottom >= top:
|
||||||
|
error('negative vertical boundary')
|
||||||
|
if right - left > 0.5 or top - bottom > 0.5:
|
||||||
|
error('box too big')
|
||||||
|
content = network.get_content('api.openstreetmap.org/api/0.6/map',
|
||||||
|
{'bbox': boundary_box},
|
||||||
|
'map/' + boundary_box + '.xml', 'html')
|
Loading…
Add table
Add a link
Reference in a new issue