Skip to content

Iterative Data Reading🔗

osmium.FileProcessor 🔗

A processor that reads an OSM file in a streaming fashion, optionally pre-filters the data, enhances it with geometry information, returning the data via an iterator.

header: osmium.io.Header property 🔗

(read-only) Header information for the file to be read.

node_location_storage: Optional[LocationTable] property 🔗

Node location cache currently in use, if enabled. This can be used to manually look up locations of nodes. Be aware that the nodes must have been read before you can do a lookup via the location storage.

__init__(indata: Union[File, FileBuffer, str, os.PathLike[str]], entities: osmium.osm.osm_entity_bits = osmium.osm.ALL) -> None 🔗

Initialise a new file processor for the given input source indata. This may either be a filename, an instance of File or buffered data in form of a FileBuffer.

The types of objects which will be read from the file can be restricted with the entities parameter. The data will be skipped directly at the source file and will never be passed to any filters including the location and area processors. You usually should not be restricting objects, when using those.

handler_for_filtered(handler: osmium._osmium.HandlerLike) -> FileProcessor 🔗

Set a fallback handler for object that have been filtered out.

Any object that does not pass the filter chain installed with with_filter() will be passed to this handler. This can be useful when the entire contents of a file should be passed to a writer and only some of the objects need to be processed specially in the iterator body.

with_areas(*filters: osmium._osmium.HandlerLike) -> FileProcessor 🔗

Enable area processing. When enabled, then closed ways and relations of type multipolygon will also be returned as an Area type.

Optionally one or more filters can be passed. These filters will be applied in the first pass, when relation candidates for areas are selected. Calling this function multiple times causes more filters to be added to the filter chain.

Calling this function automatically enables location caching if it was not enabled yet using the default storage type. To use a different storage type, call with_locations() explicity with the approriate storage parameter before calling this function.

with_filter(filt: osmium._osmium.HandlerLike) -> FileProcessor 🔗

Add a filter function to the processors filter chain. Filters are called for each prcoessed object in the order they have been installed. Only when the object passes all the filter functions will it be handed to the iterator.

Note that any handler-like object can be installed as a filter. A non-filtering handler simply works like an all-pass filter.

with_locations(storage: str = 'flex_mem') -> FileProcessor 🔗

Enable caching of node locations. The file processor will keep the coordinates of all nodes that are read from the file in memory and automatically enhance the node list of ways with the coordinates from the cache. This information can then be used to create geometries for ways. The node location cache can also be directly queried through the node_location_storage property.

The storage parameter can be used to change the type of cache used to store the coordinates. The default 'flex_mem' is good for small to medium-sized files. For large files you may need to switch to a disk-storage based implementation because the cache can become quite large. See the section on location storage in the user manual for more information.

osmium.OsmFileIterator 🔗

Low-level iterator interface for reading from an OSM source.

__init__(reader: Reader, *handlers: HandlerLike) -> None 🔗

Initialise a new iterator using the given reader as source. Each object is passed through the list of filters given by handlers. If all the filters are passed, the object is returned by next().

set_filtered_handler(handler: object) -> None 🔗

Set a fallback handler for objects that have been filtered out. The objects will be passed to the single handler.

osmium.BufferIterator 🔗

(internal) Iterator interface for reading from a queue of buffers.

This class is needed for pyosmium's internal implementation. There is currently no way to create buffers or add them to the iterator from Python.

__init__(*handlers: HandlerLike) -> None 🔗

Create a new iterator. The iterator will pass each object through the filter chain handlers before returning it.

osmium.zip_processors(*procs: FileProcessor) -> Iterable[List[Optional[OSMEntity]]] 🔗

Return the data from the FileProcessors in parallel such that objects with the same ID are returned at the same time.

The processors must contain sorted data or the results are undefined.