Skip to content

Instantly share code, notes, and snippets.

@seanmtracey
Created March 9, 2014 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanmtracey/9449716 to your computer and use it in GitHub Desktop.
Save seanmtracey/9449716 to your computer and use it in GitHub Desktop.
import sys, os, json, urllib, urllib2, time
f = open('listedBuildings.json')
locations = json.loads(f.read())
coordinates = []
streets = []
thisStreet = ""
for item in locations:
streetName = item["Name"].split(',')[0]
if streetName != thisStreet:
streets.append(item)
thisStreet = streetName
for line in streets:
firstBit = line["Name"].split(',')
q = {"q" : str(firstBit[0]) + ", Bournemouth"}
req = "http://nominatim.openstreetmap.org/search?" + urllib.urlencode(q) + "&format=json&limit=5"
nominatim = json.loads(urllib2.urlopen(req).read())
# print nominatim
if len(nominatim) > 0:
coordinates.append({
"latitude" : nominatim[0]["lat"],
"longitude" : nominatim[0]["lon"],
"name" : firstBit[0]
})
print str(firstBit[0]) + " lat:" + nominatim[0]["lat"] + " long:" + nominatim[0]["lon"] + " found"
else:
print ">>>>> " + str(firstBit[0]) + " not found"
#print urllib2.urlopen(req).read()
w = open("coordinates.json", "w")
w.write(json.dumps(coordinates))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment