76 osm to ee
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# %%capture
# # optional
# ! sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
# ! sudo apt-get update
# ! sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev
# ! sudo apt-get install libprotobuf-dev protobuf-compiler libv8-dev libjq-dev
# # packages
# ! pip install geopandas cartopy osmnx geemap
# %%capture
# # optional
# ! sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
# ! sudo apt-get update
# ! sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev
# ! sudo apt-get install libprotobuf-dev protobuf-compiler libv8-dev libjq-dev
# # packages
# ! pip install geopandas cartopy osmnx geemap
Converting OpenStreetMap data to ee.FeatureCollection¶
Credits to Erik Seras for making this feature request and providing examples.
In [2]:
Copied!
import geemap
import geemap
In [3]:
Copied!
# geemap.update_package()
# geemap.update_package()
In [4]:
Copied!
Map = geemap.Map()
fc = geemap.osm_to_ee("Provincia de Lima, Lima, Perú")
Map.addLayer(fc, {}, "Lima, Peru")
Map.centerObject(fc, 9)
Map
Map = geemap.Map()
fc = geemap.osm_to_ee("Provincia de Lima, Lima, Perú")
Map.addLayer(fc, {}, "Lima, Peru")
Map.centerObject(fc, 9)
Map
/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)) /home/runner/.local/lib/python3.9/site-packages/geopandas/io/file.py:362: FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead. pd.Int64Index,
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [5]:
Copied!
geemap.osm_to_geopandas("Provincia de Lima, Lima, Perú")
geemap.osm_to_geopandas("Provincia de Lima, Lima, Perú")
/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[5]:
geometry | bbox_north | bbox_south | bbox_east | bbox_west | place_id | osm_type | osm_id | lat | lon | display_name | class | type | importance | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | MULTIPOLYGON (((-77.19921 -11.69372, -77.19921... | -11.572436 | -12.519932 | -76.620824 | -77.199213 | 282722041 | relation | 1944670 | -11.99997 | -76.833224 | Province of Lima, Lima Metropolitan Area, Lima... | boundary | administrative | 0.703484 |
In [6]:
Copied!
# geemap.osm_to_geojson("Provincia de Lima, Lima, Perú")
# geemap.osm_to_geojson("Provincia de Lima, Lima, Perú")
In [7]:
Copied!
Map = geemap.Map()
Map.add_osm("Provincia de Lima, Lima, Perú", layer_name="Lima, Peru")
Map
Map = geemap.Map()
Map.add_osm("Provincia de Lima, Lima, Perú", layer_name="Lima, Peru")
Map
/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[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [8]:
Copied!
Map = geemap.Map()
Map.add_osm("Provincia de Lima, Lima, Perú", layer_name="Lima, Peru", to_ee=True)
Map
Map = geemap.Map()
Map.add_osm("Provincia de Lima, Lima, Perú", layer_name="Lima, Peru", to_ee=True)
Map
/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[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [9]:
Copied!
Map = geemap.Map()
Map.add_osm("('京都市, 日本国')", layer_name='Kyoto, Japan')
Map
Map = geemap.Map()
Map.add_osm("('京都市, 日本国')", layer_name='Kyoto, Japan')
Map
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) File ~/.local/lib/python3.9/site-packages/geemap/common.py:7536, in osm_to_gdf(query, which_result, by_osmid, buffer_dist) 7534 import osmnx as ox -> 7536 gdf = ox.geocode_to_gdf(query, which_result, by_osmid, buffer_dist) 7537 return gdf File ~/.local/lib/python3.9/site-packages/osmnx/geocoder.py:110, in geocode_to_gdf(query, which_result, by_osmid, buffer_dist) 109 for q, wr in zip(query, which_result): --> 110 gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid)) 112 # reset GeoDataFrame index and set its CRS File ~/.local/lib/python3.9/site-packages/osmnx/geocoder.py:166, in _geocode_query_to_gdf(query, which_result, by_osmid) 164 elif which_result is None: 165 # else, if which_result=None, auto-select the first (Multi)Polygon --> 166 result = _get_first_polygon(results, query) 168 elif len(results) >= which_result: 169 # else, if we got at least which_result results, choose that one File ~/.local/lib/python3.9/site-packages/osmnx/geocoder.py:230, in _get_first_polygon(results, query) 229 # if we never found a polygon, throw an error --> 230 raise ValueError(f'Nominatim could not geocode query "{query}" to polygonal boundaries') ValueError: Nominatim could not geocode query "('京都市, 日本国')" to polygonal boundaries During handling of the above exception, another exception occurred: Exception Traceback (most recent call last) Input In [9], in <cell line: 3>() 1 Map = geemap.Map() ----> 3 Map.add_osm("('京都市, 日本国')", layer_name='Kyoto, Japan') 5 Map File ~/.local/lib/python3.9/site-packages/geemap/foliumap.py:1079, in Map.add_osm(self, query, layer_name, which_result, by_osmid, buffer_dist, to_ee, geodesic, **kwargs) 1054 def add_osm( 1055 self, 1056 query, (...) 1063 **kwargs, 1064 ): 1065 """Adds OSM data to the map. 1066 1067 Args: (...) 1076 1077 """ -> 1079 gdf = osm_to_gdf( 1080 query, which_result=which_result, by_osmid=by_osmid, buffer_dist=buffer_dist 1081 ) 1082 geojson = gdf.__geo_interface__ 1084 if to_ee: File ~/.local/lib/python3.9/site-packages/geemap/common.py:7539, in osm_to_gdf(query, which_result, by_osmid, buffer_dist) 7537 return gdf 7538 except Exception as e: -> 7539 raise Exception(e) Exception: Nominatim could not geocode query "('京都市, 日本国')" to polygonal boundaries
In [10]:
Copied!
Map = geemap.Map()
Map.add_osm("Knoxville, Tennessee", layer_name='Knoxville, TN')
Map
Map = geemap.Map()
Map.add_osm("Knoxville, Tennessee", layer_name='Knoxville, TN')
Map
/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[10]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Last update:
2022-03-14