Skip to content

Instantly share code, notes, and snippets.

@onzag
Created December 25, 2017 21:49
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 onzag/3ecde6f124fcfdc9a8a8dba023252fc3 to your computer and use it in GitHub Desktop.
Save onzag/3ecde6f124fcfdc9a8a8dba023252fc3 to your computer and use it in GitHub Desktop.
def load(self, lng, lat, distance=1):
left = lng - self.diff
right = lng + self.diff
top = lat + self.diff
bottom = lat - self.diff
oResponse = requests.get(self.oEndpoint, params={
'bbox': ",".join([str(left),str(bottom),str(right),str(top)])
}, stream=True)
oResponse.raw.decode_content = True
data = {
'nodes': {},
'structures': {}
}
for event, element in ET.iterparse(oResponse.raw):
print(element.tag)
if element.tag == "bounds":
pass
elif element.tag == "node":
data.nodes[element.attrib.id] = MapNode(element.attrib.lon, element.attrib.lat)
elif element.tag == "way":
nodes = []
for subelement in element:
if subelement.tag == "nd":
nodes.append(data.nodes[subelement.attrib.ref])
data.structures[element.attrib.id] = MapNodeCompound(*nodes)
if not str(lng) in self.data:
self.data[str(lng)] = {}
self.data[str(lng)][str(lat)] = data
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment