API reference#

The OSM class is the main entry point: construct it once from a PBF file, then call a feature method to read a layer into a GeoDataFrame, export a network to a graph, or write data back to PBF. Module-level helpers download PBF extracts and simplify graphs.

OSM reader#

Constructor#

OSM(filepath[, bounding_box, keep_metadata, ...])

OpenStreetMap PBF reader object.

Reading OSM features#

OSM.get_network([network_type, ...])

Parses street networks from OSM for walking, driving, and cycling.

OSM.get_buildings([custom_filter, ...])

Parses buildings from OSM.

OSM.get_pois([custom_filter, ...])

Parse Point of Interest (POI) from OSM.

OSM.get_landuse([custom_filter, ...])

Parses landuse from OSM.

OSM.get_natural([custom_filter, ...])

Parses natural from OSM.

OSM.get_boundaries([boundary_type, name, ...])

Parses boundaries from OSM.

OSM.get_data_by_custom_criteria([...])

Parse OSM data based on custom criteria.

Exporting to a graph#

OSM.to_graph(nodes, edges[, graph_type, ...])

Export OSM network to routable graph.

Saving and cropping to PBF#

OSM.to_pbf([output_path, keep_relations, ...])

Crop the source PBF by this object's bounding_box and write a valid, re-readable *.osm.pbf to disk.

OSM.write_pbf(data, output_path[, subset_only])

Write the OSM data this object holds back to a valid, re-readable *.osm.pbf, applying attribute/tag edits from a (modified) GeoDataFrame.

Cache and downloads#

OSM.list_cache([filepath])

List the out-of-core engine's cached layer files -- the GeoParquet files that engine="out_of_core" reads write under <tempdir>/pyrosm/cache.

OSM.list_downloads()

List the PBF files downloaded by get_data in the default download directory (<tempdir>/pyrosm).

OSM.clear_cache([filepath])

Remove the out-of-core engine's result cache -- the GeoParquet files that engine="out_of_core" reads write under <tempdir>/pyrosm/cache.

OSM.clear_downloads([filepath])

Remove PBF files downloaded by get_data from the default download directory (<tempdir>/pyrosm).

Downloading data#

get_data(dataset[, update, directory])

Get the path to a PBF data file, and download the data if needed.

get_data_by_bbox(bbox[, crop, download, ...])

Download (and by default crop) the OSM data covering a bounding box.

geocode(query[, polygon, base_url, user_agent])

Geocode a place name to a Shapely polygon via Nominatim.

get_data_by_geocoding(query[, crop, ...])

Download (and by default crop) the OSM data for a geocoded place name.

Graph simplification#

simplify_graph(nodes, directed_edges, *[, ...])

Topologically simplify pyrosm's directed graph-export edges.