osmcode / pyosmium

Python bindings for libosmium
https://osmcode.org/pyosmium
BSD 2-Clause "Simplified" License
318 stars 65 forks source link

Introduce iterative processing #245

Closed lonvia closed 8 months ago

lonvia commented 8 months ago

Introduces a new class FileProcessor, which can be used to read a file iteratively:

for obj in osmium.FileProcessor('foo.osm.xml'):
    if obj.is_node():
        print(f'Found node {obj.id}')

Location handling, area processing and the new filter classes can be used with the processor. The same scope restrictions apply as for handlers: an object can only be accessed inside the loop. If you need to keep data, you need to copy it out.

There is no documentation yet. Refer to the refurbished examples and new tests for an idea how this is supposed to work. This is still a bit experimental and the interface might still slightly change.