Skip to content

osm module

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

A GeoDataFrame of OSM entities.

Source code in geemap/osm.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def osm_gdf_from_address(address, tags, dist=1000):
    """Create GeoDataFrame of OSM entities within some distance N, S, E, W of address.

    Args:
        address (str): The address to geocode and use as the central point around which
            to get the geometries.
        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.
        dist (int, optional): Distance in meters. Defaults to 1000.

    Returns:
        GeoDataFrame: A GeoDataFrame of OSM entities.
    """
    common.check_package(
        "osmnx", "https://osmnx.readthedocs.io/en/stable/#installation"
    )
    import osmnx as ox

    gdf = ox.features.features_from_address(address, tags, dist)
    return gdf

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

A GeoDataFrame of OSM entities.

Source code in geemap/osm.py
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
def osm_gdf_from_bbox(north, south, east, west, tags):
    """Create a GeoDataFrame of OSM entities within a N, S, E, W bounding box.

    Args:
        north (float): Northern latitude of bounding box.
        south (float): Southern latitude of bounding box.
        east (float): Eastern longitude of bounding box.
        west (float): Western longitude of bounding box.
        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.

    Returns:
        GeoDataFrame: A GeoDataFrame of OSM entities.
    """
    common.check_package(
        "osmnx", "https://osmnx.readthedocs.io/en/stable/#installation"
    )
    import osmnx as ox

    gdf = ox.features.features_from_bbox(north, south, east, west, tags)
    return gdf

osm_gdf_from_geocode(query, which_result=None, by_osmid=False)

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

Returns:

Name Type Description
GeoDataFrame

A GeoPandas GeoDataFrame.

Source code in geemap/osm.py
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
def osm_gdf_from_geocode(
    query,
    which_result=None,
    by_osmid=False,
):
    """Retrieves place(s) by name or ID from the Nominatim API as a GeoDataFrame.

    Args:
        query (str | dict | list): Query string(s) or structured dict(s) to geocode.
        which_result (int, optional): 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.
        by_osmid (bool, optional): If True, handle query as an OSM ID for lookup rather
            than text search. Defaults to False.

    Returns:
        GeoDataFrame: A GeoPandas GeoDataFrame.
    """
    common.check_package("osmnx", "https://osmnx.readthedocs.io/en/stable/")

    import osmnx as ox

    gdf = ox.geocoder.geocode_to_gdf(
        query, which_result=which_result, by_osmid=by_osmid
    )
    return gdf

osm_gdf_from_place(query, tags, which_result=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

Returns:

Name Type Description
GeoDataFrame

A GeoDataFrame of OSM entities.

Source code in geemap/osm.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def osm_gdf_from_place(query, tags, which_result=None):
    """Create GeoDataFrame of OSM entities within boundaries of geocodable place(s).

    Args:
        query (str | dict | list): Query string(s) or structured dict(s) to geocode.
        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.
        which_result (int, optional): 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.

    Returns:
        GeoDataFrame: A GeoDataFrame of OSM entities.
    """
    common.check_package(
        "osmnx", "https://osmnx.readthedocs.io/en/stable/#installation"
    )
    import osmnx as ox

    ox.config(use_cache=True, log_console=True)

    gdf = ox.features.features_from_place(query, tags, which_result)
    return gdf

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

A GeoDataFrame of OSM entities.

Source code in geemap/osm.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
def osm_gdf_from_point(center_point, tags, dist=1000):
    """Create GeoDataFrame of OSM entities within some distance N, S, E, W of a point.

    Args:
        center_point (tuple): The (lat, lng) center point around which to get the geometries.
        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.
        dist (int, optional): Distance in meters. Defaults to 1000.

    Returns:
        GeoDataFrame: A GeoDataFrame of OSM entities.
    """
    common.check_package(
        "osmnx", "https://osmnx.readthedocs.io/en/stable/#installation"
    )
    import osmnx as ox

    gdf = ox.features.features_from_point(center_point, tags, dist)
    return gdf

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

A GeoDataFrame of OSM entities.

Source code in geemap/osm.py
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
def osm_gdf_from_polygon(polygon, tags):
    """Create GeoDataFrame of OSM entities within boundaries of a (multi)polygon.

    Args:
        polygon (shapely.geometry.Polygon | shapely.geometry.MultiPolygon): Geographic
          boundaries to fetch geometries within
        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.

    Returns:
        GeoDataFrame: A GeoDataFrame of OSM entities.
    """
    common.check_package(
        "osmnx", "https://osmnx.readthedocs.io/en/stable/#installation"
    )
    import osmnx as ox

    gdf = ox.features.features_from_polygon(polygon, tags)
    return gdf

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

A GeoDataFrame of OSM entities.

Source code in geemap/osm.py
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
def osm_gdf_from_xml(filepath, polygon=None, tags=None):
    """Create a GeoDataFrame of OSM entities in an OSM-formatted XML file.

    Args:
        filepath (str): File path to file containing OSM XML data
        polygon (shapely.geometry.Polygon, optional): Optional geographic boundary to
            filter objects. Defaults to 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.

    Returns:
        GeoDataFrame: A GeoDataFrame of OSM entities.
    """
    common.check_package(
        "osmnx", "https://osmnx.readthedocs.io/en/stable/#installation"
    )
    import osmnx as ox

    gdf = ox.features.features_from_xml(filepath, polygon, tags)
    return gdf

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[str, Any]

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 | None

File path to the output GeoJSON. Defaults to None.

None
dist int

Distance in meters. Defaults to 1000.

1000

Returns:

Type Description
dict[str, Any]

A GeoJSON dictionary of OSM entities.

Source code in geemap/osm.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def osm_geojson_from_address(
    address: str, tags: dict[str, Any], filepath: str | None = None, dist: int = 1000
) -> dict[str, Any]:
    """Download OSM entities within some distance N, S, E, W of address as a GeoJSON.

    Args:
        address: The address to geocode and use as the central point around which to get
            the geometries.
        tags: 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.
        filepath: File path to the output GeoJSON. Defaults to None.
        dist: Distance in meters. Defaults to 1000.

    Returns:
       A GeoJSON dictionary of OSM entities.
    """
    gdf = osm_gdf_from_address(address, tags, dist)
    if filepath is not None:
        gdf.to_file(filepath, driver="GeoJSON")
    else:
        return gdf.__geo_interface__

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.

Source code in geemap/osm.py
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
def 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.

    Args:
        north (float): Northern latitude of bounding box.
        south (float): Southern latitude of bounding box.
        east (float): Eastern longitude of bounding box.
        west (float): Western longitude of bounding box.
        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.
        filepath (str, optional): File path to the output GeoJSON.

    Returns:
        dict: A GeoJSON dictionary of OSM entities.
    """
    gdf = osm_gdf_from_bbox(north, south, east, west, tags)
    if filepath is not None:
        gdf.to_file(filepath, driver="GeoJSON")
    else:
        return gdf.__geo_interface__

osm_geojson_from_geocode(query, filepath=None, which_result=None, by_osmid=False)

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.

None
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

Returns:

Name Type Description
dict

A GeoJSON dictionary of OSM entities.

Source code in geemap/osm.py
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
def osm_geojson_from_geocode(
    query,
    filepath=None,
    which_result=None,
    by_osmid=False,
):
    """Download place(s) by name or ID from the Nominatim API as a GeoJSON.

    Args:
        query (str | dict | list): Query string(s) or structured dict(s) to geocode.
        filepath (str): File path to the output GeoJSON.
        which_result (int, optional): 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.
        by_osmid (bool, optional): If True, handle query as an OSM ID for lookup rather
            than text search. Defaults to False.

    Returns:
        dict: A GeoJSON dictionary of OSM entities.
    """
    gdf = osm_gdf_from_geocode(query, which_result, by_osmid)
    if filepath is not None:
        gdf.to_file(filepath, driver="GeoJSON")
    else:
        return gdf.__geo_interface__

osm_geojson_from_place(query, tags, filepath=None, which_result=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.

None
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

Returns:

Name Type Description
dict

A GeoJSON dictionary of OSM entities.

Source code in geemap/osm.py
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def osm_geojson_from_place(query, tags, filepath=None, which_result=None):
    """Download OSM entities within boundaries of geocodable place(s) as a GeoJSON.

    Args:
        query (str | dict | list): Query string(s) or structured dict(s) to geocode.
        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.
        filepath (str): File path to the output shapefile.
        which_result (int, optional): 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.

    Returns:
        dict: A GeoJSON dictionary of OSM entities.
    """

    gdf = osm_gdf_from_place(query, tags, which_result)
    if filepath is not None:
        gdf.to_file(filepath, driver="GeoJSON")
    else:
        return gdf.__geo_interface__

osm_geojson_from_point(center_point, tags, filepath=None, 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.

None
dist int

Distance in meters. Defaults to 1000.

1000

Returns:

Name Type Description
dict

A GeoJSON dictionary of OSM entities.

Source code in geemap/osm.py
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
def osm_geojson_from_point(center_point, tags, filepath=None, dist=1000):
    """Download OSM entities within some distance N, S, E, W of point as a GeoJSON.

    Args:
        center_point (tuple): The (lat, lng) center point around which to get the
            geometries.
        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.
        filepath (str): File path to the output shapefile.
        dist (int, optional): Distance in meters. Defaults to 1000.

    Returns:
        dict: A GeoJSON dictionary of OSM entities.
    """
    gdf = osm_gdf_from_point(center_point, tags, dist)
    if filepath is not None:
        gdf.to_file(filepath, driver="GeoJSON")
    else:
        return gdf.__geo_interface__

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

A GeoJSON dictionary of OSM entities.

Source code in geemap/osm.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
def osm_geojson_from_polygon(polygon, tags, filepath=None):
    """Download OSM entities within boundaries of a (multi)polygon as a GeoJSON.

    Args:
        polygon (shapely.geometry.Polygon | shapely.geometry.MultiPolygon): Geographic
            boundaries to fetch geometries within
        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.
        filepath (str, optional): File path to the output GeoJSON.

    Returns:
        dict: A GeoJSON dictionary of OSM entities.
    """
    gdf = osm_gdf_from_polygon(polygon, tags)
    if filepath is not None:
        gdf.to_file(filepath, driver="GeoJSON")
    else:
        return gdf.__geo_interface__

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[str, Any]

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
Source code in geemap/osm.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def osm_shp_from_address(
    address: str, tags: dict[str, Any], filepath: str, dist: int = 1000
) -> None:
    """Download OSM entities within some distance N, S, E, W of address as a shapefile.

    Args:
        address: The address to geocode and use as the central point around which to get
            the geometries.

        tags: 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.
        filepath: File path to the output shapefile.
        dist: Distance in meters. Defaults to 1000.
    """
    gdf = osm_gdf_from_address(address, tags, dist)
    gdf.to_file(filepath)

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
Source code in geemap/osm.py
393
394
395
396
397
398
399
400
401
402
403
404
405
def osm_shp_from_bbox(north, south, east, west, tags, filepath):
    """Download OSM entities within a N, S, E, W bounding box as a shapefile.

    Args:
        north (float): Northern latitude of bounding box.
        south (float): Southern latitude of bounding box.
        east (float): Eastern longitude of bounding box.
        west (float): Western longitude of bounding box.
        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.
        filepath (str): File path to the output shapefile.
    """
    gdf = osm_gdf_from_bbox(north, south, east, west, tags)
    gdf.to_file(filepath)

osm_shp_from_geocode(query, filepath, which_result=None, by_osmid=False)

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
Source code in geemap/osm.py
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
def osm_shp_from_geocode(
    query,
    filepath,
    which_result=None,
    by_osmid=False,
):
    """Download place(s) by name or ID from the Nominatim API as a shapefile.

    Args:
        query (str | dict | list): Query string(s) or structured dict(s) to geocode.
        filepath (str): File path to the output shapefile.
        which_result (int, optional): 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.
        by_osmid (bool, optional): If True, handle query as an OSM ID for lookup rather
            than text search. Defaults to False.
    """
    gdf = osm_gdf_from_geocode(query, which_result, by_osmid)
    gdf.to_file(filepath)

osm_shp_from_place(query, tags, filepath, which_result=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
Source code in geemap/osm.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
def osm_shp_from_place(query, tags, filepath, which_result=None):
    """Download OSM entities within boundaries of geocodable place(s) as a shapefile.

    Args:
        query (str | dict | list): Query string(s) or structured dict(s) to geocode.
        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.
        filepath (str): File path to the output shapefile.
        which_result (int, optional): 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.
    """
    gdf = osm_gdf_from_place(query, tags, which_result)
    gdf.to_file(filepath)

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[float, float]

The (lat, lng) center point around which to get the geometries.

required
tags dict[str, Any]

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
Source code in geemap/osm.py
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
def osm_shp_from_point(
    center_point: tuple[float, float],
    tags: dict[str, Any],
    filepath: str,
    dist: int = 1000,
) -> None:
    """Download OSM entities within some distance N, S, E, W of point as a shapefile.

    Args:
        center_point: The (lat, lng) center point around which to get the geometries.
        tags: 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.
        filepath: File path to the output shapefile.
        dist: Distance in meters. Defaults to 1000.
    """
    gdf = osm_gdf_from_point(center_point, tags, dist)
    gdf.to_file(filepath)

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
Source code in geemap/osm.py
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
def osm_shp_from_polygon(polygon, tags, filepath):
    """Download OSM entities within boundaries of a (multi)polygon as a shapefile.

    Args:
        polygon (shapely.geometry.Polygon | shapely.geometry.MultiPolygon): Geographic
            boundaries to fetch geometries within
        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.
        filepath (str): File path to the output shapefile.
    """
    gdf = osm_gdf_from_polygon(polygon, tags)
    gdf.to_file(filepath)

osm_tags_list()

Open a browser to see all tags of OSM features.

Source code in geemap/osm.py
547
548
549
550
551
def osm_tags_list() -> None:
    """Open a browser to see all tags of OSM features."""
    import webbrowser

    webbrowser.open_new_tab("https://wiki.openstreetmap.org/wiki/Map_features")