osm module¶
leafmap.osm
¶
The module contains functions for downloading OpenStreetMap data. It wraps the geometries module of the osmnx package (see https://osmnx.readthedocs.io/en/stable/osmnx.html#module-osmnx.geometries). Credits to Geoff Boeing, the developer of the osmnx package. Most functions for downloading OpenStreetMap data require tags of map features. The list of commonly used tags can be found at https://wiki.openstreetmap.org/wiki/Map_features
osm_gdf_from_address(address, tags, dist=1000)
¶
Create GeoDataFrame of OSM entities within some distance N, S, E, W of address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
The address to geocode and use as the central point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame of OSM entities. |
osm_gdf_from_bbox(north, south, east, west, tags)
¶
Create a GeoDataFrame of OSM entities within a N, S, E, W bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
north
|
float
|
Northern latitude of bounding box. |
required |
south
|
float
|
Southern latitude of bounding box. |
required |
east
|
float
|
Eastern longitude of bounding box. |
required |
west
|
float
|
Western longitude of bounding box. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame of OSM entities. |
osm_gdf_from_geocode(query, which_result=None, by_osmid=False, buffer_dist=None)
¶
Retrieves place(s) by name or ID from the Nominatim API as a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
which_result
|
INT
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
by_osmid
|
bool
|
If True, handle query as an OSM ID for lookup rather than text search. Defaults to False. |
False
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoPandas GeoDataFrame. |
osm_gdf_from_place(query, tags, which_result=None, buffer_dist=None)
¶
Create GeoDataFrame of OSM entities within boundaries of geocodable place(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
which_result
|
int
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame of OSM entities. |
osm_gdf_from_point(center_point, tags, dist=1000)
¶
Create GeoDataFrame of OSM entities within some distance N, S, E, W of a point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_point
|
tuple
|
The (lat, lng) center point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame of OSM entities. |
osm_gdf_from_polygon(polygon, tags)
¶
Create GeoDataFrame of OSM entities within boundaries of a (multi)polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
Polygon | MultiPolygon
|
Geographic boundaries to fetch geometries within |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame of OSM entities. |
osm_gdf_from_xml(filepath, polygon=None, tags=None)
¶
Create a GeoDataFrame of OSM entities in an OSM-formatted XML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
File path to file containing OSM XML data |
required |
polygon
|
Polygon
|
Optional geographic boundary to filter objects. Defaults to None. |
None
|
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame of OSM entities. |
osm_geojson_from_address(address, tags, filepath=None, dist=1000)
¶
Download OSM entities within some distance N, S, E, W of address as a GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
The address to geocode and use as the central point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output GeoJSON. Defaults to None. |
None
|
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict
|
A GeoJSON dictionary of OSM entities. |
osm_geojson_from_bbox(north, south, east, west, tags, filepath=None)
¶
Download OSM entities within a N, S, E, W bounding box as a GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
north
|
float
|
Northern latitude of bounding box. |
required |
south
|
float
|
Southern latitude of bounding box. |
required |
east
|
float
|
Eastern longitude of bounding box. |
required |
west
|
float
|
Western longitude of bounding box. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output GeoJSON. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A GeoJSON dictionary of OSM entities. |
osm_geojson_from_geocode(query, filepath, which_result=None, by_osmid=False, buffer_dist=None)
¶
Download place(s) by name or ID from the Nominatim API as a GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
filepath
|
str
|
File path to the output GeoJSON. |
required |
which_result
|
int
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
by_osmid
|
bool
|
If True, handle query as an OSM ID for lookup rather than text search. Defaults to False. |
False
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A GeoJSON dictionary of OSM entities. |
osm_geojson_from_place(query, tags, filepath, which_result=None, buffer_dist=None)
¶
Download OSM entities within boundaries of geocodable place(s) as a GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output shapefile. |
required |
which_result
|
int
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict
|
A GeoJSON dictionary of OSM entities. |
osm_geojson_from_point(center_point, tags, filepath, dist=1000)
¶
Download OSM entities within some distance N, S, E, W of point as a GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_point
|
tuple
|
The (lat, lng) center point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output shapefile. |
required |
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict
|
A GeoJSON dictionary of OSM entities. |
osm_geojson_from_polygon(polygon, tags, filepath=None)
¶
Download OSM entities within boundaries of a (multi)polygon as a GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
Polygon | MultiPolygon
|
Geographic boundaries to fetch geometries within |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output GeoJSON. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict
|
A GeoJSON dictionary of OSM entities. |
osm_shp_from_address(address, tags, filepath, dist=1000)
¶
Download OSM entities within some distance N, S, E, W of address as a shapefile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
The address to geocode and use as the central point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output shapefile. |
required |
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
osm_shp_from_bbox(north, south, east, west, tags, filepath)
¶
Download OSM entities within a N, S, E, W bounding box as a shapefile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
north
|
float
|
Northern latitude of bounding box. |
required |
south
|
float
|
Southern latitude of bounding box. |
required |
east
|
float
|
Eastern longitude of bounding box. |
required |
west
|
float
|
Western longitude of bounding box. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output shapefile. |
required |
osm_shp_from_geocode(query, filepath, which_result=None, by_osmid=False, buffer_dist=None)
¶
Download place(s) by name or ID from the Nominatim API as a shapefile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
filepath
|
str
|
File path to the output shapefile. |
required |
which_result
|
int
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
by_osmid
|
bool
|
If True, handle query as an OSM ID for lookup rather than text search. Defaults to False. |
False
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
osm_shp_from_place(query, tags, filepath, which_result=None, buffer_dist=None)
¶
Download OSM entities within boundaries of geocodable place(s) as a shapefile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output shapefile. |
required |
which_result
|
int
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
osm_shp_from_point(center_point, tags, filepath, dist=1000)
¶
Download OSM entities within some distance N, S, E, W of point as a shapefile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_point
|
tuple
|
The (lat, lng) center point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output shapefile. |
required |
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
osm_shp_from_polygon(polygon, tags, filepath)
¶
Download OSM entities within boundaries of a (multi)polygon as a shapefile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
Polygon | MultiPolygon
|
Geographic boundaries to fetch geometries within |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
filepath
|
str
|
File path to the output shapefile. |
required |
osm_tags_list()
¶
Open a browser to see all tags of OSM features.
quackosm_gdf_from_bbox(bbox, tags=None, verbosity_mode='transient', **kwargs)
¶
Download OSM data for a bounding box using QuackOSM.
QuackOSM is a high-performance library for reading OpenStreetMap data using DuckDB. It automatically downloads the required PBF files and converts them to GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
tuple or list
|
Bounding box as (west, south, east, north) or (minx, miny, maxx, maxy) in WGS84 coordinates. |
required |
tags
|
dict
|
Dict of tags used for filtering OSM features. The dict keys should be OSM tags (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. Defaults to None (all features). |
None
|
verbosity_mode
|
str
|
Verbosity mode for progress output. Options are "verbose", "transient", or "silent". Defaults to "transient". |
'transient'
|
**kwargs
|
Additional keyword arguments passed to QuackOSM's convert_geometry_to_geodataframe. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame containing OSM features with 'tags' and 'geometry' columns. |
quackosm_gdf_from_geometry(geometry, tags=None, verbosity_mode='transient', **kwargs)
¶
Download OSM data for a geometry using QuackOSM.
QuackOSM is a high-performance library for reading OpenStreetMap data using DuckDB. It automatically downloads the required PBF files and converts them to GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
A Shapely geometry (Polygon, MultiPolygon), WKT string, GeoJSON dict, or a GeoDataFrame. The geometry defines the area of interest. |
required | |
tags
|
dict
|
Dict of tags used for filtering OSM features. The dict keys should be OSM tags (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. Defaults to None (all features). |
None
|
verbosity_mode
|
str
|
Verbosity mode for progress output. Options are "verbose", "transient", or "silent". Defaults to "transient". |
'transient'
|
**kwargs
|
Additional keyword arguments passed to QuackOSM's convert_geometry_to_geodataframe. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame containing OSM features with 'tags' and 'geometry' columns. |
Example
import leafmap.osm as osm from shapely.geometry import box
Download OSM features for a custom geometry¶
geometry = box(7.41, 43.73, 7.43, 43.75) # Monaco area gdf = osm.quackosm_gdf_from_geometry(geometry)
Download only water features¶
gdf = osm.quackosm_gdf_from_geometry(geometry, tags={"natural": "water"})
quackosm_gdf_from_pbf(pbf_path, tags=None, geometry=None, verbosity_mode='transient', **kwargs)
¶
Load OSM data from a local PBF file using QuackOSM.
QuackOSM is a high-performance library for reading OpenStreetMap data using DuckDB. This function reads a local PBF file and converts it to a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pbf_path
|
str
|
Path to the local PBF file. |
required |
tags
|
dict
|
Dict of tags used for filtering OSM features. The dict keys should be OSM tags (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. Defaults to None (all features). |
None
|
geometry
|
Optional Shapely geometry to clip the data to. Defaults to None. |
None
|
|
verbosity_mode
|
str
|
Verbosity mode for progress output. Options are "verbose", "transient", or "silent". Defaults to "transient". |
'transient'
|
**kwargs
|
Additional keyword arguments passed to QuackOSM's convert_pbf_to_geodataframe. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame containing OSM features with 'tags' and 'geometry' columns. |
quackosm_gdf_from_place(query, tags=None, osm_extract_source=None, verbosity_mode='transient', **kwargs)
¶
Download OSM data for a place name using QuackOSM.
QuackOSM is a high-performance library for reading OpenStreetMap data using DuckDB. It automatically downloads the required PBF files and converts them to GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Place name to geocode (e.g., "Vatican City", "Monaco", "Manhattan, New York"). |
required |
tags
|
dict
|
Dict of tags used for filtering OSM features. The dict keys should be OSM tags (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {'building': True} would return all building footprints in the area. tags = {'amenity': True, 'highway': 'bus_stop'} would return all amenities and highway=bus_stop features. Defaults to None (all features). |
None
|
osm_extract_source
|
str
|
Source for OSM extracts. Options include "geofabrik", "osmfr", "bbbike", etc. If None, QuackOSM will automatically select the best source. Defaults to None. |
None
|
verbosity_mode
|
str
|
Verbosity mode for progress output. Options are "verbose", "transient", or "silent". Defaults to "transient". |
'transient'
|
**kwargs
|
Additional keyword arguments passed to QuackOSM's convert_osm_extract_to_geodataframe or convert_geometry_to_geodataframe functions. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
GeoDataFrame |
GeoDataFrame
|
A GeoDataFrame containing OSM features with 'tags' and 'geometry' columns. |
Example
import leafmap.osm as osm
Download all OSM features for Monaco¶
gdf = osm.quackosm_gdf_from_place("Monaco")
Download only buildings¶
gdf = osm.quackosm_gdf_from_place("Monaco", tags={"building": True})
Download amenities and shops¶
gdf = osm.quackosm_gdf_from_place("Monaco", tags={"amenity": True, "shop": True})
quackosm_to_parquet(source, output_path, tags=None, verbosity_mode='transient', **kwargs)
¶
Download OSM data and save to GeoParquet format using QuackOSM.
QuackOSM can efficiently save OSM data directly to GeoParquet format, which is optimized for cloud storage and analytical workflows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Union[str, Tuple, GeoDataFrame]
|
The data source. Can be: - A place name string (e.g., "Monaco") - A bounding box tuple (west, south, east, north) - A Shapely geometry - A GeoDataFrame |
required |
output_path
|
str
|
Path to save the output GeoParquet file. |
required |
tags
|
dict
|
Dict of tags used for filtering OSM features. Defaults to None. |
None
|
verbosity_mode
|
str
|
Verbosity mode for progress output. Defaults to "transient". |
'transient'
|
**kwargs
|
Additional keyword arguments passed to QuackOSM functions. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the saved GeoParquet file. |
Example
import leafmap.osm as osm
Save Monaco buildings to GeoParquet¶
path = osm.quackosm_to_parquet("Monaco", "monaco_buildings.parquet", tags={"building": True})