92 plotly
Uncomment the following line to install geemap if needed.
# !pip install geemap
import ee
import geemap.plotlymap as geemap
If you are using a recently implemented geema feature that has not yet been released to PyPI or conda-forge, you can uncomment the following line to install the development version from GitHub.
# geemap.update_package()
If you run into an error saying "FigureWidget - 'mapbox._derived' Value Error" (source), uncomment the following line and run it.
# geemap.fix_widget_error()
Create an interactive map using default settings.
m = geemap.Map()
m
Change default setting when creating a map.
Can be one of string from "open-street-map", "carto-positron", "carto-darkmatter", "stamen-terrain", "stamen-toner" or "stamen-watercolor" .
m = geemap.Map(center=(40, -100), zoom=3, basemap="stamen-terrain", height=500)
m
Set map center and zoom level.
m = geemap.Map(basemap="stamen-watercolor")
m.set_center(lat=20, lon=0, zoom=2)
m
Print out available basemaps.
geemap.basemaps.keys()
Add a basemap.
m = geemap.Map()
m.add_basemap("OpenTopoMap")
m
Add XYZ tile layer.
m = geemap.Map()
tile_url = "https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}"
m.add_tile_layer(tile_url, name="Google Satellite", attribution="Google", opacity=1.0)
m
Add a mapbox tile layer. You will need a mapbox token. The map style can be Can be "basic", "streets", "outdoors", "light", "dark", "satellite", or "satellite-streets".
import os
# os.environ["MAPBOX_TOKEN"] = "your-mapbox-token"
m = geemap.Map()
m.add_mapbox_layer(style="streets")
m
Remove the modebar in the upper-right corner.
m = geemap.Map(basemap="stamen-toner")
m
m.clear_controls()
Add more buttons to the modebar.
m = geemap.Map(basemap="carto-positron")
controls = [
'drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape',
]
m.add_controls(controls)
m
Add Cloud Optimized GeoTIFF.
m = geemap.Map()
url = 'https://opendata.digitalglobe.com/events/california-fire-2020/pre-event/2018-02-16/pine-gulch-fire20/1030010076004E00.tif'
m.add_cog_layer(url, name="Fire (pre-event)")
m
Add a STAC item via HTTP URL.
m = geemap.Map()
url = 'https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json'
m.add_stac_layer(url, bands=['B3', 'B2', 'B1'], name='False color')
m
Add a STAC item from Microsoft Planetary Computer.
collection = "landsat-8-c2-l2"
item = "LC08_L2SP_047027_20201204_02_T1"
m = geemap.Map()
m.add_stac_layer(
collection=collection,
item=item,
bands=["SR_B7", "SR_B5", "SR_B4"],
titiler_endpoint="pc",
)
m
Add a heat map.
url = 'https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv'
m = geemap.Map(basemap="stamen-terrain")
m.add_heatmap(
url, latitude="Latitude", longitude="Longitude", z="Magnitude", name="Earthquake"
)
m
Add a choropleth map.
url = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/countries.geojson"
m = geemap.Map(basemap="stamen-terrain")
m.add_choropleth_map(url, name="Pop", z="POP_EST", colorscale="Viridis")
m
Add Earth Engine layers.
m = geemap.Map()
m.add_basemap("HYBRID")
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(
['B1', 'B2', 'B3', 'B4', 'B5', 'B7']
)
states = ee.FeatureCollection("TIGER/2018/States")
# Set visualization parameters.
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Engine layers to Map
m.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
m.addLayer(
landsat7,
{'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2.0},
'Landsat 7',
)
m.addLayer(states, {}, "US States")
m.show()