Created
December 25, 2017 21:49
-
-
Save onzag/3ecde6f124fcfdc9a8a8dba023252fc3 to your computer and use it in GitHub Desktop.
This file contains 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
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