pyrosm.OSM.get_data_by_custom_criteria#
- OSM.get_data_by_custom_criteria(custom_filter=None, osm_keys_to_keep=None, filter_type='keep', tags_as_columns=None, keep_nodes=True, keep_ways=True, keep_relations=True, extra_attributes=None, keep_other_tags=True, timestamp=None, tags_to_keep=None)#
Parse OSM data based on custom criteria.
- Parameters:
custom_filter (dict (optional)) – A custom filter to filter only specific elements from OpenStreetMap. If
None(the default), every tagged element is returned without key/value filtering (tagged nodes, ways, and relations); standalone ways with no tags are dropped. Reading everything is memory-heavy on large extracts, so prefer a pre-filtered PBF and/or a bounding box.filter_typeis ignored in this mode. Withosm_keys_to_keep, the elements with one of those keys are returned. A tag keyedidis filtered asid_tag, the column it is returned in;idis the element’s OSM id and not a filter key.osm_keys_to_keep (str | list) – The keys an element must have one of to be returned: the first level of filtering, before
custom_filter.filter_type (str) – “keep” | “exclude” Whether the filters should be used to keep or exclude the data from OSM.
tags_as_columns (list) – Which tags should be kept as columns in the resulting GeoDataFrame. The keys of the filter (and of
osm_keys_to_keep) are always columns too, so each row shows what it was selected by.keep_nodes (bool) – Whether or not the nodes should be kept in the resulting GeoDataFrame if they are found.
keep_ways (bool) – Whether or not the ways should be kept in the resulting GeoDataFrame if they are found.
keep_relations (bool) – Whether or not the relations should be kept in the resulting GeoDataFrame if they are found.
extra_attributes (list (optional)) – Additional OSM tag keys that will be converted into columns in the resulting GeoDataFrame.
keep_other_tags (bool) – By default (
True) every tag is parsed:tags_as_columnsbecome their own columns and the rest are kept in a JSONtagscolumn.Falseresolves only the requested tags (tags_as_columnsplus the filter keys) and drops the JSONtagscolumn, so the read does minimal tag work. Only supported by the out-of-core engine (OSM(..., engine='out_of_core')), and not for history reads (an.osh.pbffile or atimestamp), which use the in-memory reader.timestamp (str | datetime | int) –
If provided, the data from given moment of time will be returned. The time should be provided in UTC. Note: This functionality only works with OSH.PBF files that can be downloaded manually e.g. from Geofabrik (requires login with OSM account).
The logic: the closest version of each element up to given timestamp will be selected to the result. This means that elements can be older than the given timestamp (the most up-to-date version is selected), but not newer (records having exactly the selected timestamp will be kept). In case only a date is given, the time will represent midnight of the given day, such as “2021-01-01 00:00:00”.
tags_to_keep (list (optional)) – The name the other readers give
tags_as_columns: the tags kept as columns. Give one of the two.