I am trying and failing to extract any building details from a downloaded OSM PBF file.
My current function below returns node ids that don't seem to exist in the locationTable. The node object has no other accessible attributes such as node.location or node.ref.location. Am I doing something wrong here or is my data invalid? For reference I have downloaded the PBF file from https://www.geofabrik.de/data/download.html
location_table = osmium.index.create_map(map_type="sparse_file_array")
class OSMHandler(osmium.SimpleHandler):
def __init__(self):
super(OSMHandler, self).__init__()
self.buildings = []
self.locationTable = location_table
def way(self, w):
if 'building' in w.tags:
if w.tags['building'] not in ['no', 'dismantled', 'collapsed', 'roof']:
valid_coords = []
for node_ref in w.nodes:
print(node_ref.location)
location = location_table.get(node_ref.ref)
Example error below.
invalid
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-60-429adc0340b1> in <module>
1 handler = OSMHandler()
----> 2 handler.apply_file(input_file)
3
4
<ipython-input-59-c3dbbf320491> in way(self, w)
16
17 for node_ref in w.nodes:
---> 18 location = location_table.get(node_ref.ref)
19
20
KeyError: 'id 13878221 not found'