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 [ ]:
Copied!
# !pip install geemap
# !pip install geemap
In [ ]:
Copied!
import ee
import geemap
import ee
import geemap
Create an interactive map¶
In [ ]:
Copied!
Map = geemap.Map(center=(40, -100), zoom=4)
Map
Map = geemap.Map(center=(40, -100), zoom=4)
Map
Add basemaps¶
In [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
In [ ]:
Copied!
Map.add_basemap("HYBRID")
Map.add_basemap("HYBRID")
In [ ]:
Copied!
Map.add_basemap("OpenTopoMap")
Map.add_basemap("OpenTopoMap")
In [ ]:
Copied!
Map = geemap.Map()
Map.basemap_demo()
Map
Map = geemap.Map()
Map.basemap_demo()
Map
Add WMS and XYZ tile layers¶
In [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
In [ ]:
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 [ ]:
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 [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
In [ ]:
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("LANDSAT/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("LANDSAT/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 [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
In [ ]:
Copied!
Map.search_locations
Map.search_locations
In [ ]:
Copied!
Map.search_loc_geom
Map.search_loc_geom
In [ ]:
Copied!
location = Map.search_loc_geom
# print(location.getInfo())
location = Map.search_loc_geom
# print(location.getInfo())
Search Earth Engine API documentation¶
In [ ]:
Copied!
geemap.ee_search()
geemap.ee_search()
Use Inspector tool¶
In [ ]:
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("LANDSAT/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("LANDSAT/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
Use Plotting tool¶
In [ ]:
Copied!
Map = geemap.Map()
landsat7 = ee.Image("LANDSAT/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("LANDSAT/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
In [ ]:
Copied!
Map.set_plot_options(plot_type="bar", add_marker_cluster=True)
Map.set_plot_options(plot_type="bar", add_marker_cluster=True)
Create a split-panel map¶
In [ ]:
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
In [ ]:
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
In [ ]:
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
Add marker cluster¶
In [ ]:
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 [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
In [ ]:
Copied!
file_path = os.path.join(os.getcwd(), "us_cities.json")
if not os.path.exists(file_path):
url = "https://github.com/gee-community/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/gee-community/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 [ ]:
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 [ ]:
Copied!
Map.add_layer(maker_cluster)
Map.add_layer(maker_cluster)
In [ ]:
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 [ ]:
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
In [ ]:
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
In [ ]:
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
In [ ]:
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
Use Drawing tools¶
In [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
In [ ]:
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 [ ]:
Copied!
Map.draw_features
Map.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 grab GEE JavaScripts from GEE Documentation.
In [ ]:
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 [ ]:
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 [ ]:
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
In [ ]:
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
In [ ]:
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
In [ ]:
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 [ ]:
Copied!
geemap.js_snippet_to_py(js_snippet)
geemap.js_snippet_to_py(js_snippet)
In [ ]:
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
In [ ]:
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
In [ ]:
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
Use shapefiles¶
In [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
In [ ]:
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 [ ]:
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 [ ]:
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 [ ]:
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 [ ]:
Copied!
geemap.ee_to_shp(countries, filename="../data/countries_new.shp")
geemap.ee_to_shp(countries, filename="../data/countries_new.shp")
In [ ]:
Copied!
geemap.ee_export_vector(states, filename="../data/states.csv")
geemap.ee_export_vector(states, filename="../data/states.csv")
Create Landsat timelapse¶
In [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
In [ ]:
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",
)
Use time-series inspector¶
In [ ]:
Copied!
naip_ts = geemap.naip_timeseries(start_year=2009, end_year=2018)
naip_ts = geemap.naip_timeseries(start_year=2009, end_year=2018)
In [ ]:
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)
In [ ]:
Copied!
naip_vis = {"bands": ["N", "R", "G"]}
naip_vis = {"bands": ["N", "R", "G"]}
In [ ]:
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
Export images¶
In [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
In [ ]:
Copied!
image = ee.Image("LANDSAT/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("LANDSAT/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 [ ]:
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()
In [ ]:
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 [ ]:
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
)
In [ ]:
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
)
In [ ]:
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 [ ]:
Copied!
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
In [ ]:
Copied!
geemap.ee_export_image_collection(collection, out_dir=out_dir)
geemap.ee_export_image_collection(collection, out_dir=out_dir)