Last active
August 29, 2015 14:09
-
-
Save alesegdia/9fd6cd186744b6cf43c9 to your computer and use it in GitHub Desktop.
Get (lat,lon) from address using Nominatim and OSM in Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import json | |
import sys | |
def addr_to_url(addr): | |
return "http://nominatim.openstreetmap.org/?format=json&addressdetails=1&q=" + addr.strip().replace(" ", "+") + "&format=json&limit=1" | |
def addr_to_geo(addr): | |
url = addr_to_url(addr) | |
jsonreq = urllib2.urlopen(url).read() | |
data = json.loads(jsonreq) | |
return { key : data[0][key] for key in { "lat", "lon" } } | |
if len(sys.argv) != 2: | |
print 'Usage: python addr2geo "<address>"' | |
else: | |
print addr_to_geo(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment