-
Notifications
You must be signed in to change notification settings - Fork 0
/
nominatim.py
26 lines (23 loc) · 1.06 KB
/
nominatim.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
__author__ = 'marcos'
import re
import json
import urllib2
class Nominatim():
def __init__(self):
pass
@staticmethod
def nominatim_get_bounding_box_of(street=None, city=None, county=None, state=None,
postalcode=None, country=None, polygon=True):
assert street or city or county or state or postalcode or country, "input we weed"
parameters = ['street', 'city', 'county', 'state', 'postalcode', 'country']
input_parameters = [street, city, county, state, postalcode, country]
url_input = [parameters[i] + "=" + str(re.sub(" ", "+", input_parameters[i]))
for i in range(len(parameters)) if input_parameters[i] is not None]
url_input = "http://nominatim.openstreetmap.org/search?" + "&".join(url_input) + "&format=json"
url_open = urllib2.urlopen(url_input)
result = json.load(url_open)
if polygon:
if len(result) > 0:
bb = map(float, result[0]['boundingbox'])
result = bb[:4]
return result