Skip to content

Indexes🔗

osmium.IdTracker 🔗

Class to keep track of node, way and relation IDs.

Ids can be added to the to the tracker in various ways: by adding IDs directly, by adding the IDs of referenced IDs in an OSM object or by extracting the referenced IDs from an input file.

The tracker can then be used as a filter to select objects based on whether they are contained in the tracker's ID lists.

__init__() -> None 🔗

Initialise a new empty tracker.

add_node(node: int) -> None 🔗

Add the given node ID to the tracker.

add_references(obj: object) -> None 🔗

Add all IDs referenced by the input object obj.

The function will track the IDs of node lists from Way objects or Python objects with a nodes attribute, which must be a sequence of ints. It also tracks the IDs of relation members from Relation objects or Python objects with a members attribute with an equivalent content. Input objects that do not fall into any of these categories are silently ignored.

add_relation(relation: int) -> None 🔗

Add the given relation ID to the tracker.

add_way(way: int) -> None 🔗

Add the given way ID to the tracker.

complete_backward_references(filename: Union[str, os.PathLike[str], File, FileBuffer], relation_depth: int = ...) -> None 🔗

Make the IDs in the tracker reference-complete by adding all referenced IDs for objects whose IDs are already tracked.

The function scans through the reference file filename, finds all the objects this tracker references and applies add_references() to them. The reference file is expected to be sorted.

The relation_depth parameter controls how nested relations are handled. When set to 0 then only way and node references of relations that are already tracked are completed. If the parameter is larger than 0, the function will make at a maximum relation_depth passes through the reference file, to find nested relation. That means, that nested relations with a nesting depth up to relation_depth are guaranteed to be included. Relations that are nested more deeply, may or may not appear.

complete_forward_references(filename: Union[str, os.PathLike[str], File, FileBuffer], relation_depth: int = ...) -> None 🔗

Add to the tracker all IDs of object that reference any ID already tracked.

The function scans through the reference file filename, checks all objects in the file with the contains_any_references() function and adds the object ID to the tracker if the check is positive.

The relation_depth parameter controls how nested relations are handled. When set to a value smaller than 0, then relations will no be added at all to the tracker. When set to 0, then only relations are added that reference a node or way already in the tracker. When set to a strictly positive value, then nested relations are tacken into account as well. The function will make at a maximum relation_depth passes to complete relations with relation members.

contains_any_references(obj: object) -> bool 🔗

Check if the given input object obj contains any references to IDs tracked by this tracker.

The function will check the IDs of node lists from Way objects or Python objects with a nodes attribute, which must be a sequence of ints. It also tracks the IDs of relation members from Relation objects or Python objects with a members attribute with an equivalent content. All other object kinds will return False.

contains_filter() -> IdTrackerContainsFilter 🔗

Return a filter object that lets all ways and relations pass which reference any of the object IDs tracked by this tracker.

You may change the tracker while the filter is in use. Such a change is then immediately reflected in the filter.

The filter has no effect on nodes, areas and changesets.

id_filter() -> IdTrackerIdFilter 🔗

Return a filter object which lets all nodes, ways and relations pass that are being tracked in this tracker.

You may change the tracker while the filter is in use. Such a change is then immediately reflected in the filter.

The filter has no effect on areas and changesets.

node_ids() -> IdSet 🔗

Return a view of the set of node ids. The returned object is mutable. You may call operations like unset() and clear() on it, which then have a direct effect on the tracker.

relation_ids() -> IdSet 🔗

Return a view of the set of relation ids. The returned object is mutable. You may call operations like unset() and clear() on it, which then have a direct effect on the tracker.

way_ids() -> IdSet 🔗

Return a view of the set of way ids.The returned object is mutable. You may call operations like unset() and clear() on it, which then have a direct effect on the tracker.

osmium.index.IdSet 🔗

Compact storage for a set of IDs.

__init__() -> None 🔗

Initialise an empty set.

clear() -> None 🔗

Remove all IDs from the set.

empty() -> bool 🔗

Check if no IDs are stored yet.

get(id: int) -> bool 🔗

Check if the given ID is in the storage.

set(id: int) -> None 🔗

Add an ID to the storage. Does nothing if the ID is already contained.

unset(id: int) -> None 🔗

Remove an ID from the storage. Does nothing if the ID is not in the storage.

osmium.index.LocationTable 🔗

A map from a node ID to a location object. Location can be set and queried using the standard [] notation for dicts. This implementation works only with positive node IDs.

clear() -> None 🔗

Remove all entries from the location table..

get(id: int) -> osmium.osm.Location 🔗

Get the location for the given node ID. Raises a KeyError when there is no location for the given id.

set(id: int, loc: osmium.osm.Location) -> None 🔗

Set the location for the given node ID.

used_memory() -> int 🔗

Return the size (in bytes) currently allocated by this location table.

Index creation functions🔗

osmium.index.map_types() -> List[str] 🔗

Return a list of strings with valid types for the location table.

osmium.index.create_map(map_type: str) -> LocationTable 🔗

Create a new location store. Use the map_type parameter to choose a concrete implementation. Some implementations take additiona configuration parameters, which can also be set through the map_type argument. For example, to create an array cache backed by a file 'foo.store', the map_type needs to be set to dense_file_array,foo.store. Read the section on location storage in the user manual for more information about the different implementations.