Table of Contents
- 1 Create an interactive map
- 2 Add basemaps
- 3 Add WMS and XYZ tile layers
- 4 Add Earth Engine data layers
- 5 Search Earth Engine data catalog
- 6 Search Earth Engine API documentation
- 7 Use Inspector tool
- 8 Use Plotting tool
- 9 Create a split-panel map
- 10 Add marker cluster
- 11 Add customized legends
- 12 Use Drawing tools
- 13 Convert JavaScripts to Python
- 14 Use shapefiles
- 15 Create Landsat timelapse
- 16 Use time-series inspector
- 17 Export images
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import ee
import geemap
import ee
import geemap
Create an interactive map¶
In [3]:
Copied!
Map = geemap.Map(center=(40, -100), zoom=4)
Map
Map = geemap.Map(center=(40, -100), zoom=4)
Map
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add basemaps¶
In [4]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [5]:
Copied!
Map.add_basemap('HYBRID')
Map.add_basemap('HYBRID')
In [6]:
Copied!
Map.add_basemap('OpenTopoMap')
Map.add_basemap('OpenTopoMap')
In [7]:
Copied!
Map = geemap.Map()
Map.basemap_demo()
Map
Map = geemap.Map()
Map.basemap_demo()
Map
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [7], in <cell line: 2>() 1 Map = geemap.Map() ----> 2 Map.basemap_demo() 3 Map AttributeError: 'Map' object has no attribute 'basemap_demo'
Add WMS and XYZ tile layers¶
In [8]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [9]:
Copied!
# https://viewer.nationalmap.gov/services/
url = 'https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}'
Map.add_tile_layer(url, name='Google Satellite', attribution='Google')
# https://viewer.nationalmap.gov/services/
url = 'https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}'
Map.add_tile_layer(url, name='Google Satellite', attribution='Google')
In [10]:
Copied!
naip_url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'
Map.add_wms_layer(
url=naip_url, layers='0', name='NAIP Imagery', format='image/png', shown=True
)
naip_url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'
Map.add_wms_layer(
url=naip_url, layers='0', name='NAIP Imagery', format='image/png', shown=True
)
Add Earth Engine data layers¶
In [11]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[11]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [12]:
Copied!
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
landcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover')
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003')
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
Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
Map.addLayer(landcover, {}, 'Land cover')
Map.addLayer(
landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7'
)
Map.addLayer(states, {}, "US States")
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
landcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover')
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003')
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
Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
Map.addLayer(landcover, {}, 'Land cover')
Map.addLayer(
landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7'
)
Map.addLayer(states, {}, "US States")
Search Earth Engine data catalog¶
In [13]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[13]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [14]:
Copied!
Map.search_locations
Map.search_locations
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [14], in <cell line: 1>() ----> 1 Map.search_locations AttributeError: 'Map' object has no attribute 'search_locations'
In [15]:
Copied!
Map.search_loc_geom
Map.search_loc_geom
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [15], in <cell line: 1>() ----> 1 Map.search_loc_geom AttributeError: 'Map' object has no attribute 'search_loc_geom'
In [16]:
Copied!
location = Map.search_loc_geom
# print(location.getInfo())
location = Map.search_loc_geom
# print(location.getInfo())
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [16], in <cell line: 1>() ----> 1 location = Map.search_loc_geom AttributeError: 'Map' object has no attribute 'search_loc_geom'
Search Earth Engine API documentation¶
In [17]:
Copied!
geemap.ee_search()
geemap.ee_search()
Use Inspector tool¶
In [18]:
Copied!
Map = geemap.Map()
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
landcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover')
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003')
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
Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
Map.addLayer(landcover, {}, 'Land cover')
Map.addLayer(
landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7'
)
Map.addLayer(states, {}, "US States")
Map
Map = geemap.Map()
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
landcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover')
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003')
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
Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
Map.addLayer(landcover, {}, 'Land cover')
Map.addLayer(
landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7'
)
Map.addLayer(states, {}, "US States")
Map
Out[18]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Use Plotting tool¶
In [19]:
Copied!
Map = geemap.Map()
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003').select([0, 1, 2, 3, 4, 6])
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
Map.addLayer(landsat7, landsat_vis, "LE7_TOA_5YEAR/1999_2003")
hyperion = ee.ImageCollection('EO1/HYPERION').filter(
ee.Filter.date('2016-01-01', '2017-03-01')
)
hyperion_vis = {
'min': 1000.0,
'max': 14000.0,
'gamma': 2.5,
}
Map.addLayer(hyperion, hyperion_vis, 'EO1/HYPERION')
Map
Map = geemap.Map()
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003').select([0, 1, 2, 3, 4, 6])
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
Map.addLayer(landsat7, landsat_vis, "LE7_TOA_5YEAR/1999_2003")
hyperion = ee.ImageCollection('EO1/HYPERION').filter(
ee.Filter.date('2016-01-01', '2017-03-01')
)
hyperion_vis = {
'min': 1000.0,
'max': 14000.0,
'gamma': 2.5,
}
Map.addLayer(hyperion, hyperion_vis, 'EO1/HYPERION')
Map
Out[19]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [20]:
Copied!
Map.set_plot_options(plot_type='bar', add_marker_cluster=True)
Map.set_plot_options(plot_type='bar', add_marker_cluster=True)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [20], in <cell line: 1>() ----> 1 Map.set_plot_options(plot_type='bar', add_marker_cluster=True) AttributeError: 'Map' object has no attribute 'set_plot_options'
Create a split-panel map¶
In [21]:
Copied!
Map = geemap.Map()
Map.split_map(left_layer='HYBRID', right_layer='ROADMAP')
Map
Map = geemap.Map()
Map.split_map(left_layer='HYBRID', right_layer='ROADMAP')
Map
Out[21]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [22]:
Copied!
Map = geemap.Map()
Map.split_map(
left_layer='NLCD 2016 CONUS Land Cover', right_layer='NLCD 2001 CONUS Land Cover'
)
Map
Map = geemap.Map()
Map.split_map(
left_layer='NLCD 2016 CONUS Land Cover', right_layer='NLCD 2001 CONUS Land Cover'
)
Map
Out[22]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [23]:
Copied!
nlcd_2001 = ee.Image('USGS/NLCD/NLCD2001').select('landcover')
nlcd_2016 = ee.Image('USGS/NLCD/NLCD2016').select('landcover')
left_layer = geemap.ee_tile_layer(nlcd_2001, {}, 'NLCD 2001')
right_layer = geemap.ee_tile_layer(nlcd_2016, {}, 'NLCD 2016')
Map = geemap.Map()
Map.split_map(left_layer, right_layer)
Map
nlcd_2001 = ee.Image('USGS/NLCD/NLCD2001').select('landcover')
nlcd_2016 = ee.Image('USGS/NLCD/NLCD2016').select('landcover')
left_layer = geemap.ee_tile_layer(nlcd_2001, {}, 'NLCD 2001')
right_layer = geemap.ee_tile_layer(nlcd_2016, {}, 'NLCD 2016')
Map = geemap.Map()
Map.split_map(left_layer, right_layer)
Map
Out[23]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add marker cluster¶
In [24]:
Copied!
import geemap
import json
import os
import requests
from geemap import geojson_to_ee, ee_to_geojson
from ipyleaflet import GeoJSON, Marker, MarkerCluster
import geemap
import json
import os
import requests
from geemap import geojson_to_ee, ee_to_geojson
from ipyleaflet import GeoJSON, Marker, MarkerCluster
In [25]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[25]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [26]:
Copied!
file_path = os.path.join(os.getcwd(), 'us-cities.json')
if not os.path.exists(file_path):
url = 'https://github.com/giswqs/geemap/raw/master/examples/data/us-cities.json'
r = requests.get(url)
with open(file_path, 'w') as f:
f.write(r.content.decode("utf-8"))
with open(file_path) as f:
json_data = json.load(f)
file_path = os.path.join(os.getcwd(), 'us-cities.json')
if not os.path.exists(file_path):
url = 'https://github.com/giswqs/geemap/raw/master/examples/data/us-cities.json'
r = requests.get(url)
with open(file_path, 'w') as f:
f.write(r.content.decode("utf-8"))
with open(file_path) as f:
json_data = json.load(f)
In [27]:
Copied!
maker_cluster = MarkerCluster(
markers=[
Marker(location=feature['geometry']['coordinates'][::-1])
for feature in json_data['features']
],
name='Markers',
)
maker_cluster = MarkerCluster(
markers=[
Marker(location=feature['geometry']['coordinates'][::-1])
for feature in json_data['features']
],
name='Markers',
)
In [28]:
Copied!
Map.add_layer(maker_cluster)
Map.add_layer(maker_cluster)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [28], in <cell line: 1>() ----> 1 Map.add_layer(maker_cluster) File ~/.local/lib/python3.9/site-packages/geemap/foliumap.py:195, in Map.add_layer(self, ee_object, vis_params, name, shown, opacity, **kwargs) 187 if ( 188 not isinstance(ee_object, ee.Image) 189 and not isinstance(ee_object, ee.ImageCollection) (...) 192 and not isinstance(ee_object, ee.Geometry) 193 ): 194 err_str = "\n\nThe image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection." --> 195 raise AttributeError(err_str) 197 if ( 198 isinstance(ee_object, ee.geometry.Geometry) 199 or isinstance(ee_object, ee.feature.Feature) 200 or isinstance(ee_object, ee.featurecollection.FeatureCollection) 201 ): 202 features = ee.FeatureCollection(ee_object) AttributeError: The image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection.
In [29]:
Copied!
ee_fc = geojson_to_ee(json_data)
Map.addLayer(ee_fc, {}, "US Cities EE")
ee_fc = geojson_to_ee(json_data)
Map.addLayer(ee_fc, {}, "US Cities EE")
Add customized legends¶
In [30]:
Copied!
Map = geemap.Map()
Map.add_basemap('HYBRID')
landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')
Map.addLayer(landcover, {}, 'NLCD Land Cover')
Map.add_legend(builtin_legend='NLCD')
Map
Map = geemap.Map()
Map.add_basemap('HYBRID')
landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')
Map.addLayer(landcover, {}, 'NLCD Land Cover')
Map.add_legend(builtin_legend='NLCD')
Map
Out[30]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [31]:
Copied!
Map = geemap.Map()
Map.add_basemap('HYBRID')
Map.add_basemap('FWS NWI Wetlands')
Map.add_legend(builtin_legend='NWI')
Map
Map = geemap.Map()
Map.add_basemap('HYBRID')
Map.add_basemap('FWS NWI Wetlands')
Map.add_legend(builtin_legend='NWI')
Map
Out[31]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [32]:
Copied!
Map = geemap.Map()
legend_dict = {
'11 Open Water': '466b9f',
'12 Perennial Ice/Snow': 'd1def8',
'21 Developed, Open Space': 'dec5c5',
'22 Developed, Low Intensity': 'd99282',
'23 Developed, Medium Intensity': 'eb0000',
'24 Developed High Intensity': 'ab0000',
'31 Barren Land (Rock/Sand/Clay)': 'b3ac9f',
'41 Deciduous Forest': '68ab5f',
'42 Evergreen Forest': '1c5f2c',
'43 Mixed Forest': 'b5c58f',
'51 Dwarf Scrub': 'af963c',
'52 Shrub/Scrub': 'ccb879',
'71 Grassland/Herbaceous': 'dfdfc2',
'72 Sedge/Herbaceous': 'd1d182',
'73 Lichens': 'a3cc51',
'74 Moss': '82ba9e',
'81 Pasture/Hay': 'dcd939',
'82 Cultivated Crops': 'ab6c28',
'90 Woody Wetlands': 'b8d9eb',
'95 Emergent Herbaceous Wetlands': '6c9fb8',
}
landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')
Map.addLayer(landcover, {}, 'NLCD Land Cover')
Map.add_legend(legend_title="NLCD Land Cover Classification", legend_dict=legend_dict)
Map
Map = geemap.Map()
legend_dict = {
'11 Open Water': '466b9f',
'12 Perennial Ice/Snow': 'd1def8',
'21 Developed, Open Space': 'dec5c5',
'22 Developed, Low Intensity': 'd99282',
'23 Developed, Medium Intensity': 'eb0000',
'24 Developed High Intensity': 'ab0000',
'31 Barren Land (Rock/Sand/Clay)': 'b3ac9f',
'41 Deciduous Forest': '68ab5f',
'42 Evergreen Forest': '1c5f2c',
'43 Mixed Forest': 'b5c58f',
'51 Dwarf Scrub': 'af963c',
'52 Shrub/Scrub': 'ccb879',
'71 Grassland/Herbaceous': 'dfdfc2',
'72 Sedge/Herbaceous': 'd1d182',
'73 Lichens': 'a3cc51',
'74 Moss': '82ba9e',
'81 Pasture/Hay': 'dcd939',
'82 Cultivated Crops': 'ab6c28',
'90 Woody Wetlands': 'b8d9eb',
'95 Emergent Herbaceous Wetlands': '6c9fb8',
}
landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')
Map.addLayer(landcover, {}, 'NLCD Land Cover')
Map.add_legend(legend_title="NLCD Land Cover Classification", legend_dict=legend_dict)
Map
Out[32]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [33]:
Copied!
# https://developers.google.com/earth-engine/datasets/catalog/MODIS_051_MCD12Q1
Map = geemap.Map()
ee_class_table = """
Value Color Description
0 1c0dff Water
1 05450a Evergreen needleleaf forest
2 086a10 Evergreen broadleaf forest
3 54a708 Deciduous needleleaf forest
4 78d203 Deciduous broadleaf forest
5 009900 Mixed forest
6 c6b044 Closed shrublands
7 dcd159 Open shrublands
8 dade48 Woody savannas
9 fbff13 Savannas
10 b6ff05 Grasslands
11 27ff87 Permanent wetlands
12 c24f44 Croplands
13 a5a5a5 Urban and built-up
14 ff6d4c Cropland/natural vegetation mosaic
15 69fff8 Snow and ice
16 f9ffa4 Barren or sparsely vegetated
254 ffffff Unclassified
"""
landcover = ee.Image('MODIS/051/MCD12Q1/2013_01_01').select('Land_Cover_Type_1')
Map.setCenter(6.746, 46.529, 2)
Map.addLayer(landcover, {}, 'MODIS Land Cover')
legend_dict = geemap.legend_from_ee(ee_class_table)
Map.add_legend(legend_title="MODIS Global Land Cover", legend_dict=legend_dict)
Map
# https://developers.google.com/earth-engine/datasets/catalog/MODIS_051_MCD12Q1
Map = geemap.Map()
ee_class_table = """
Value Color Description
0 1c0dff Water
1 05450a Evergreen needleleaf forest
2 086a10 Evergreen broadleaf forest
3 54a708 Deciduous needleleaf forest
4 78d203 Deciduous broadleaf forest
5 009900 Mixed forest
6 c6b044 Closed shrublands
7 dcd159 Open shrublands
8 dade48 Woody savannas
9 fbff13 Savannas
10 b6ff05 Grasslands
11 27ff87 Permanent wetlands
12 c24f44 Croplands
13 a5a5a5 Urban and built-up
14 ff6d4c Cropland/natural vegetation mosaic
15 69fff8 Snow and ice
16 f9ffa4 Barren or sparsely vegetated
254 ffffff Unclassified
"""
landcover = ee.Image('MODIS/051/MCD12Q1/2013_01_01').select('Land_Cover_Type_1')
Map.setCenter(6.746, 46.529, 2)
Map.addLayer(landcover, {}, 'MODIS Land Cover')
legend_dict = geemap.legend_from_ee(ee_class_table)
Map.add_legend(legend_title="MODIS Global Land Cover", legend_dict=legend_dict)
Map
Out[33]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Use Drawing tools¶
In [34]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[34]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [35]:
Copied!
# Add Earth Engine dataset
image = ee.Image('USGS/SRTMGL1_003')
# Set visualization parameters.
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Engine DEM to map
Map.addLayer(image, vis_params, 'SRTM DEM')
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, 'US States')
# Add Earth Engine dataset
image = ee.Image('USGS/SRTMGL1_003')
# Set visualization parameters.
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Engine DEM to map
Map.addLayer(image, vis_params, 'SRTM DEM')
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, 'US States')
In [36]:
Copied!
Map.draw_features
Map.draw_features
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [36], in <cell line: 1>() ----> 1 Map.draw_features AttributeError: 'Map' object has no attribute 'draw_features'
Convert JavaScripts to Python¶
You can simply copy and paste your GEE JavaScripts into a code block wrapped with trip quotes and pass it to a variable.
For example, you can grap GEE JavaScripts from GEE Documentation.
In [37]:
Copied!
js_snippet = """
// Load an image.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');
// Define the visualization parameters.
var vizParams = {
bands: ['B5', 'B4', 'B3'],
min: 0,
max: 0.5,
gamma: [0.95, 1.1, 1]
};
// Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10); // San Francisco Bay
Map.addLayer(image, vizParams, 'false color composite');
"""
js_snippet = """
// Load an image.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');
// Define the visualization parameters.
var vizParams = {
bands: ['B5', 'B4', 'B3'],
min: 0,
max: 0.5,
gamma: [0.95, 1.1, 1]
};
// Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10); // San Francisco Bay
Map.addLayer(image, vizParams, 'false color composite');
"""
In [38]:
Copied!
geemap.js_snippet_to_py(
js_snippet, add_new_cell=True, import_ee=True, import_geemap=True, show_map=True
)
geemap.js_snippet_to_py(
js_snippet, add_new_cell=True, import_ee=True, import_geemap=True, show_map=True
)
In [39]:
Copied!
import ee
import geemap
Map = geemap.Map()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Define the visualization parameters.
vizParams = {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5, 'gamma': [0.95, 1.1, 1]}
# Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10)
# San Francisco Bay
Map.addLayer(image, vizParams, 'False color composite')
Map
import ee
import geemap
Map = geemap.Map()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Define the visualization parameters.
vizParams = {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5, 'gamma': [0.95, 1.1, 1]}
# Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10)
# San Francisco Bay
Map.addLayer(image, vizParams, 'False color composite')
Map
Out[39]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [40]:
Copied!
import ee
import geemap
Map = geemap.Map()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Define the visualization parameters.
vizParams = {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5, 'gamma': [0.95, 1.1, 1]}
# Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10)
# San Francisco Bay
Map.addLayer(image, vizParams, 'False color composite')
Map
import ee
import geemap
Map = geemap.Map()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Define the visualization parameters.
vizParams = {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5, 'gamma': [0.95, 1.1, 1]}
# Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10)
# San Francisco Bay
Map.addLayer(image, vizParams, 'False color composite')
Map
Out[40]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [41]:
Copied!
import ee
import geemap
Map = geemap.Map()
ee.Initialize()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Define the visualization parameters.
vizParams = {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5, 'gamma': [0.95, 1.1, 1]}
# Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10)
# San Francisco Bay
Map.addLayer(image, vizParams, 'False color composite')
Map
import ee
import geemap
Map = geemap.Map()
ee.Initialize()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Define the visualization parameters.
vizParams = {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5, 'gamma': [0.95, 1.1, 1]}
# Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10)
# San Francisco Bay
Map.addLayer(image, vizParams, 'False color composite')
Map
Out[41]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [42]:
Copied!
js_snippet = """
// Load an image.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');
// Create an NDWI image, define visualization parameters and display.
var ndwi = image.normalizedDifference(['B3', 'B5']);
var ndwiViz = {min: 0.5, max: 1, palette: ['00FFFF', '0000FF']};
Map.addLayer(ndwi, ndwiViz, 'NDWI', false);
"""
js_snippet = """
// Load an image.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');
// Create an NDWI image, define visualization parameters and display.
var ndwi = image.normalizedDifference(['B3', 'B5']);
var ndwiViz = {min: 0.5, max: 1, palette: ['00FFFF', '0000FF']};
Map.addLayer(ndwi, ndwiViz, 'NDWI', false);
"""
In [43]:
Copied!
geemap.js_snippet_to_py(js_snippet)
geemap.js_snippet_to_py(js_snippet)
In [44]:
Copied!
import ee
import geemap
Map = geemap.Map()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Create an NDWI image, define visualization parameters and display.
ndwi = image.normalizedDifference(['B3', 'B5'])
ndwiViz = {'min': 0.5, 'max': 1, 'palette': ['00FFFF', '0000FF']}
Map.addLayer(ndwi, ndwiViz, 'NDWI', False)
Map
import ee
import geemap
Map = geemap.Map()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Create an NDWI image, define visualization parameters and display.
ndwi = image.normalizedDifference(['B3', 'B5'])
ndwiViz = {'min': 0.5, 'max': 1, 'palette': ['00FFFF', '0000FF']}
Map.addLayer(ndwi, ndwiViz, 'NDWI', False)
Map
Out[44]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [45]:
Copied!
import ee
import geemap
Map = geemap.Map()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Create an NDWI image, define visualization parameters and display.
ndwi = image.normalizedDifference(['B3', 'B5'])
ndwiViz = {'min': 0.5, 'max': 1, 'palette': ['00FFFF', '0000FF']}
Map.addLayer(ndwi, ndwiViz, 'NDWI', False)
Map
import ee
import geemap
Map = geemap.Map()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Create an NDWI image, define visualization parameters and display.
ndwi = image.normalizedDifference(['B3', 'B5'])
ndwiViz = {'min': 0.5, 'max': 1, 'palette': ['00FFFF', '0000FF']}
Map.addLayer(ndwi, ndwiViz, 'NDWI', False)
Map
Out[45]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [46]:
Copied!
import ee
import geemap
Map = geemap.Map()
ee.Initialize()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Create an NDWI image, define visualization parameters and display.
ndwi = image.normalizedDifference(['B3', 'B5'])
ndwiViz = {'min': 0.5, 'max': 1, 'palette': ['00FFFF', '0000FF']}
Map.addLayer(ndwi, ndwiViz, 'NDWI', False)
Map
import ee
import geemap
Map = geemap.Map()
ee.Initialize()
# Load an image.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
# Create an NDWI image, define visualization parameters and display.
ndwi = image.normalizedDifference(['B3', 'B5'])
ndwiViz = {'min': 0.5, 'max': 1, 'palette': ['00FFFF', '0000FF']}
Map.addLayer(ndwi, ndwiViz, 'NDWI', False)
Map
Out[46]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Use shapefiles¶
In [47]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[47]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [48]:
Copied!
countries_shp = '../data/countries.shp'
countries = geemap.shp_to_ee(countries_shp)
countries_shp = '../data/countries.shp'
countries = geemap.shp_to_ee(countries_shp)
In [49]:
Copied!
countries_shp = '../data/countries.shp'
countries = geemap.shp_to_ee(countries_shp)
Map.addLayer(countries, {}, 'Countries')
countries_shp = '../data/countries.shp'
countries = geemap.shp_to_ee(countries_shp)
Map.addLayer(countries, {}, 'Countries')
In [50]:
Copied!
states_shp = '../data/us-states.shp'
states = geemap.shp_to_ee(states_shp)
Map.addLayer(states, {}, 'US States')
states_shp = '../data/us-states.shp'
states = geemap.shp_to_ee(states_shp)
Map.addLayer(states, {}, 'US States')
In [51]:
Copied!
cities_shp = '../data/us-cities.shp'
cities = geemap.shp_to_ee(cities_shp)
Map.addLayer(cities, {}, 'US Cities')
cities_shp = '../data/us-cities.shp'
cities = geemap.shp_to_ee(cities_shp)
Map.addLayer(cities, {}, 'US Cities')
In [52]:
Copied!
geemap.ee_to_shp(countries, filename='../data/countries_new.shp')
geemap.ee_to_shp(countries, filename='../data/countries_new.shp')
Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/1391b86faf955d685a65db3904763e8f-7a91c16a2cfa29431384e2e93f052151:getFeatures Please wait ... Data downloaded to /home/runner/work/geospatial-notebooks/geospatial-notebooks/docs/data/countries_new.shp
In [53]:
Copied!
geemap.ee_export_vector(states, filename='../data/states.csv')
geemap.ee_export_vector(states, filename='../data/states.csv')
Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/c9b5e2525d7240bbe4dc6348a67948e7-87429718162b71eec5be277de43fc1a2:getFeatures Please wait ... Data downloaded to /home/runner/work/geospatial-notebooks/geospatial-notebooks/docs/data/states.csv
Create Landsat timelapse¶
In [54]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[54]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [55]:
Copied!
label = 'Urban Growth in Las Vegas'
Map.add_landsat_ts_gif(
label=label,
start_year=1985,
bands=['Red', 'Green', 'Blue'],
font_color='white',
frames_per_second=10,
progress_bar_color='blue',
)
label = 'Urban Growth in Las Vegas'
Map.add_landsat_ts_gif(
label=label,
start_year=1985,
bands=['Red', 'Green', 'Blue'],
font_color='white',
frames_per_second=10,
progress_bar_color='blue',
)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [55], in <cell line: 2>() 1 label = 'Urban Growth in Las Vegas' ----> 2 Map.add_landsat_ts_gif( 3 label=label, 4 start_year=1985, 5 bands=['Red', 'Green', 'Blue'], 6 font_color='white', 7 frames_per_second=10, 8 progress_bar_color='blue', 9 ) AttributeError: 'Map' object has no attribute 'add_landsat_ts_gif'
Use time-series inspector¶
In [56]:
Copied!
naip_ts = geemap.naip_timeseries(start_year=2009, end_year=2018)
naip_ts = geemap.naip_timeseries(start_year=2009, end_year=2018)
In [57]:
Copied!
layer_names = ['NAIP ' + str(year) for year in range(2009, 2019)]
print(layer_names)
layer_names = ['NAIP ' + str(year) for year in range(2009, 2019)]
print(layer_names)
['NAIP 2009', 'NAIP 2010', 'NAIP 2011', 'NAIP 2012', 'NAIP 2013', 'NAIP 2014', 'NAIP 2015', 'NAIP 2016', 'NAIP 2017', 'NAIP 2018']
In [58]:
Copied!
naip_vis = {'bands': ['N', 'R', 'G']}
naip_vis = {'bands': ['N', 'R', 'G']}
In [59]:
Copied!
Map = geemap.Map()
Map.ts_inspector(
left_ts=naip_ts,
right_ts=naip_ts,
left_names=layer_names,
right_names=layer_names,
left_vis=naip_vis,
right_vis=naip_vis,
)
Map
Map = geemap.Map()
Map.ts_inspector(
left_ts=naip_ts,
right_ts=naip_ts,
left_names=layer_names,
right_names=layer_names,
left_vis=naip_vis,
right_vis=naip_vis,
)
Map
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [59], in <cell line: 2>() 1 Map = geemap.Map() ----> 2 Map.ts_inspector( 3 left_ts=naip_ts, 4 right_ts=naip_ts, 5 left_names=layer_names, 6 right_names=layer_names, 7 left_vis=naip_vis, 8 right_vis=naip_vis, 9 ) 10 Map AttributeError: 'Map' object has no attribute 'ts_inspector'
Export images¶
In [60]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[60]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [61]:
Copied!
image = ee.Image('LE7_TOA_5YEAR/1999_2003')
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
Map.addLayer(image, landsat_vis, "LE7_TOA_5YEAR/1999_2003", True, 0.7)
image = ee.Image('LE7_TOA_5YEAR/1999_2003')
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
Map.addLayer(image, landsat_vis, "LE7_TOA_5YEAR/1999_2003", True, 0.7)
In [62]:
Copied!
# Draw any shapes on the map using the Drawing tools before executing this code block
feature = Map.draw_last_feature
if feature is None:
geom = ee.Geometry.Polygon(
[
[
[-115.413031, 35.889467],
[-115.413031, 36.543157],
[-114.034328, 36.543157],
[-114.034328, 35.889467],
[-115.413031, 35.889467],
]
]
)
feature = ee.Feature(geom, {})
roi = feature.geometry()
# Draw any shapes on the map using the Drawing tools before executing this code block
feature = Map.draw_last_feature
if feature is None:
geom = ee.Geometry.Polygon(
[
[
[-115.413031, 35.889467],
[-115.413031, 36.543157],
[-114.034328, 36.543157],
[-114.034328, 35.889467],
[-115.413031, 35.889467],
]
]
)
feature = ee.Feature(geom, {})
roi = feature.geometry()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [62], in <cell line: 2>() 1 # Draw any shapes on the map using the Drawing tools before executing this code block ----> 2 feature = Map.draw_last_feature 4 if feature is None: 5 geom = ee.Geometry.Polygon( 6 [ 7 [ (...) 14 ] 15 ) AttributeError: 'Map' object has no attribute 'draw_last_feature'
In [63]:
Copied!
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
filename = os.path.join(out_dir, 'landsat.tif')
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
filename = os.path.join(out_dir, 'landsat.tif')
In [64]:
Copied!
geemap.ee_export_image(
image, filename=filename, scale=90, region=roi, file_per_band=False
)
geemap.ee_export_image(
image, filename=filename, scale=90, region=roi, file_per_band=False
)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [64], in <cell line: 1>() 1 geemap.ee_export_image( ----> 2 image, filename=filename, scale=90, region=roi, file_per_band=False 3 ) NameError: name 'roi' is not defined
In [65]:
Copied!
geemap.ee_export_image(
image, filename=filename, scale=90, region=roi, file_per_band=True
)
geemap.ee_export_image(
image, filename=filename, scale=90, region=roi, file_per_band=True
)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [65], in <cell line: 1>() 1 geemap.ee_export_image( ----> 2 image, filename=filename, scale=90, region=roi, file_per_band=True 3 ) NameError: name 'roi' is not defined
In [66]:
Copied!
loc = ee.Geometry.Point(-99.2222, 46.7816)
collection = (
ee.ImageCollection('USDA/NAIP/DOQQ')
.filterBounds(loc)
.filterDate('2008-01-01', '2020-01-01')
.filter(ee.Filter.listContains("system:band_names", "N"))
)
loc = ee.Geometry.Point(-99.2222, 46.7816)
collection = (
ee.ImageCollection('USDA/NAIP/DOQQ')
.filterBounds(loc)
.filterDate('2008-01-01', '2020-01-01')
.filter(ee.Filter.listContains("system:band_names", "N"))
)
In [67]:
Copied!
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
In [68]:
Copied!
geemap.ee_export_image_collection(collection, out_dir=out_dir)
geemap.ee_export_image_collection(collection, out_dir=out_dir)
Total number of images: 9 Exporting 1/9: m_4609915_sw_14_060_20180902_20181213.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/12dba27394c3260fc731c0d6229e43a5-517354cb2075fd1f8c58085c59322400:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_060_20180902_20181213.tif Exporting 2/9: m_4609915_sw_14_060_20190626.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/a05dd6d80c920403e8f1f943da8c4174-df1841cb57984e730391cf4052c6dd57:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_060_20190626.tif Exporting 3/9: m_4609915_sw_14_1_20090818.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/e0218e3dbca864608a201086538782b5-b0130f33534a50d82bf1252a6f90287b:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20090818.tif Exporting 4/9: m_4609915_sw_14_1_20100629.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/e8b801d6cba914811034b6a836fa64e8-8930c9bfd6bbc89876a2e4ed802cecff:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20100629.tif Exporting 5/9: m_4609915_sw_14_1_20120714.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/a2835ac668b547edc38f2c74320168d8-d79f0ab39a33f6092bb5889aa7e961a6:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20120714.tif Exporting 6/9: m_4609915_sw_14_1_20140901.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/dfc26d0ec2aa00709a488938a348c954-31193e2893aea344b5f6c46232496466:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20140901.tif Exporting 7/9: m_4609915_sw_14_1_20150926.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/a3f09592597bb46998d6ca0905a1b1e2-ee7221d05eb3c52c7dc695faca0726ef:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20150926.tif Exporting 8/9: m_4609915_sw_14_h_20160704.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/0df29ebae58261ebc7edbe5743f785f7-75128b561e26d37a1f9201279f45cb96:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_h_20160704.tif Exporting 9/9: m_4609915_sw_14_h_20170703.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/b8e7221f77039b3b23cd347962c1a654-540cc892694681cdcf1d93471bed99f4:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_h_20170703.tif
Last update:
2022-03-14