84 openstreetmap
Downloading OpenStreetMap data with a single line of code
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geopandas osmnx geemap
# !pip install geopandas osmnx geemap
In [2]:
Copied!
import geemap.foliumap as geemap
import geemap.foliumap as geemap
Add OSM data of place(s) by name or ID to the map. Note that the geemap custom layer control does not support GeoJSON, we need to use the ipyleaflet built-in layer control.
In [3]:
Copied!
m = geemap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("New York City", layer_name='NYC')
m
m = geemap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("New York City", layer_name='NYC')
m
/home/runner/.local/lib/python3.9/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [4]:
Copied!
m = geemap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("Chicago, Illinois", layer_name='Chicago, IL')
m
m = geemap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("Chicago, Illinois", layer_name='Chicago, IL')
m
/home/runner/.local/lib/python3.9/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add OSM entities within boundaries of geocodable place(s) to the map.
In [5]:
Copied!
m = geemap.Map(toolbar_control=False, layers_control=True)
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
m.add_osm_from_place(place, tags, layer_name="Los Angeles, CA")
m
m = geemap.Map(toolbar_control=False, layers_control=True)
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
m.add_osm_from_place(place, tags, layer_name="Los Angeles, CA")
m
2022-03-14 04:23:54 Configured OSMnx 1.1.2 2022-03-14 04:23:54 HTTP response caching is on 2022-03-14 04:23:54 Pausing 1 seconds before making HTTP GET request 2022-03-14 04:23:55 Get https://nominatim.openstreetmap.org/search?format=json&polygon_geojson=1&dedupe=0&limit=50&q=Bunker+Hill%2C+Los+Angeles%2C+California with timeout=180 2022-03-14 04:23:55 Resolved nominatim.openstreetmap.org to 140.211.167.100 2022-03-14 04:23:56 Downloaded 1.2kB from nominatim.openstreetmap.org 2022-03-14 04:23:56 Saved response to cache file "cache/8d8366ad6b96fa854a9d6d038c022b8bdcdb6fe6.json" 2022-03-14 04:23:56 Created GeoDataFrame with 1 rows from 1 queries 2022-03-14 04:23:56 Constructed place geometry polygon(s) to query API 2022-03-14 04:23:56 Projected GeoDataFrame to +proj=utm +zone=11 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2022-03-14 04:23:56 Projected GeoDataFrame to epsg:4326 2022-03-14 04:23:56 Requesting data within polygon from API in 1 request(s) 2022-03-14 04:23:56 Resolved overpass-api.de to 178.63.11.215
/home/runner/.local/lib/python3.9/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
2022-03-14 04:23:56 Pausing 0 seconds before making HTTP POST request 2022-03-14 04:23:56 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27building%27%5D%28poly%3A%2734.056122+-118.256052+34.054233+-118.253149+34.050990+-118.248100+34.053625+-118.245628+34.058656+-118.253434+34.057132+-118.255014+34.056122+-118.256052%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27building%27%5D%28poly%3A%2734.056122+-118.256052+34.054233+-118.253149+34.050990+-118.248100+34.053625+-118.245628+34.058656+-118.253434+34.057132+-118.255014+34.056122+-118.256052%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27building%27%5D%28poly%3A%2734.056122+-118.256052+34.054233+-118.253149+34.050990+-118.248100+34.053625+-118.245628+34.058656+-118.253434+34.057132+-118.255014+34.056122+-118.256052%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2022-03-14 04:23:56 Resolved overpass-api.de to 178.63.11.215 2022-03-14 04:24:05 Downloaded 162.9kB from overpass-api.de 2022-03-14 04:24:05 Saved response to cache file "cache/3063abeb36c57d92b80fe38fd9a33fcf0e02c542.json" 2022-03-14 04:24:05 Got all geometries data within polygon from API in 1 request(s) 2022-03-14 04:24:05 Converting 1414 elements in JSON responses to geometries 2022-03-14 04:24:05 77 geometries created in the dict 2022-03-14 04:24:05 13 untagged geometries removed 2022-03-14 04:24:05 Created r-tree spatial index for 64 geometries 2022-03-14 04:24:05 Identified 64 geometries inside polygon 2022-03-14 04:24:05 0 geometries removed by the polygon filter 2022-03-14 04:24:05 8 geometries removed by the tag filter 2022-03-14 04:24:05 56 geometries in the final GeoDataFrame
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Show OSM feature tags.
In [6]:
Copied!
# geemap.osm_tags_list()
# geemap.osm_tags_list()
Add OSM entities within some distance N, S, E, W of address to the map.
In [7]:
Copied!
m = geemap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City", tags={"amenity": "bar"}, dist=1500, layer_name="NYC bars"
)
m
m = geemap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City", tags={"amenity": "bar"}, dist=1500, layer_name="NYC bars"
)
m
2022-03-14 04:24:05 Pausing 1 seconds before making HTTP GET request 2022-03-14 04:24:06 Get https://nominatim.openstreetmap.org/search?format=json&limit=1&dedupe=0&q=New+York+City with timeout=180 2022-03-14 04:24:06 Resolved nominatim.openstreetmap.org to 140.211.167.100 2022-03-14 04:24:06 Downloaded 0.5kB from nominatim.openstreetmap.org 2022-03-14 04:24:06 Saved response to cache file "cache/78258c318356c20c380e1fed844176f90c053cf7.json" 2022-03-14 04:24:06 Geocoded "New York City" to (40.7127281, -74.0060152) 2022-03-14 04:24:06 Created bbox 1500 m from (40.7127281, -74.0060152): 40.72621790503239,40.69923829496761,-73.98821837587228,-74.02381202412771 2022-03-14 04:24:06 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2022-03-14 04:24:06 Projected GeoDataFrame to epsg:4326 2022-03-14 04:24:06 Requesting data within polygon from API in 1 request(s) 2022-03-14 04:24:06 Resolved overpass-api.de to 178.63.48.217 2022-03-14 04:24:06 Pausing 0 seconds before making HTTP POST request 2022-03-14 04:24:06 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2022-03-14 04:24:06 Resolved overpass-api.de to 178.63.48.217 2022-03-14 04:24:10 Downloaded 37.3kB from overpass-api.de 2022-03-14 04:24:10 Saved response to cache file "cache/7d10c2e8d50f39407dda671d56290ea2808b3d4a.json" 2022-03-14 04:24:10 Got all geometries data within polygon from API in 1 request(s) 2022-03-14 04:24:10 Converting 108 elements in JSON responses to geometries 2022-03-14 04:24:10 99 geometries created in the dict 2022-03-14 04:24:10 0 untagged geometries removed 2022-03-14 04:24:10 Created r-tree spatial index for 99 geometries 2022-03-14 04:24:10 Identified 99 geometries inside polygon 2022-03-14 04:24:10 0 geometries removed by the polygon filter 2022-03-14 04:24:10 0 geometries removed by the tag filter 2022-03-14 04:24:10 99 geometries in the final GeoDataFrame
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [8]:
Copied!
m = geemap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={"landuse": ["retail", "commercial"], "building": True},
dist=1000,
layer_name="NYC buildings",
)
m
m = geemap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={"landuse": ["retail", "commercial"], "building": True},
dist=1000,
layer_name="NYC buildings",
)
m
2022-03-14 04:24:10 Retrieved response from cache file "cache/78258c318356c20c380e1fed844176f90c053cf7.json" 2022-03-14 04:24:10 Geocoded "New York City" to (40.7127281, -74.0060152) 2022-03-14 04:24:10 Created bbox 1000 m from (40.7127281, -74.0060152): 40.721721303354926,40.703734896645074,-73.99415065058152,-74.01787974941847 2022-03-14 04:24:10 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2022-03-14 04:24:10 Projected GeoDataFrame to epsg:4326 2022-03-14 04:24:10 Requesting data within polygon from API in 1 request(s) 2022-03-14 04:24:10 Resolved overpass-api.de to 178.63.48.217 2022-03-14 04:24:10 Pausing 0 seconds before making HTTP POST request 2022-03-14 04:24:10 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28node%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28node%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2022-03-14 04:24:10 Resolved overpass-api.de to 178.63.48.217 2022-03-14 04:24:20 Downloaded 2,727.8kB from overpass-api.de 2022-03-14 04:24:20 Saved response to cache file "cache/2c876f231fa35ebe028236a3fb06b51de7794ae0.json" 2022-03-14 04:24:20 Got all geometries data within polygon from API in 1 request(s) 2022-03-14 04:24:20 Converting 21012 elements in JSON responses to geometries 2022-03-14 04:24:20 2964 geometries created in the dict 2022-03-14 04:24:20 74 untagged geometries removed 2022-03-14 04:24:21 Created r-tree spatial index for 2890 geometries 2022-03-14 04:24:21 Identified 2883 geometries inside polygon 2022-03-14 04:24:21 7 geometries removed by the polygon filter 2022-03-14 04:24:21 137 geometries removed by the tag filter 2022-03-14 04:24:21 2753 geometries in the final GeoDataFrame
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook