12 zonal statistics
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 os
import ee
import geemap
import os
In [3]:
Copied!
geemap.show_youtube('ou-Xm3CLitM')
geemap.show_youtube('ou-Xm3CLitM')
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!
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
# Set visualization parameters.
dem_vis = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Engine DEM to map
Map.addLayer(dem, dem_vis, 'SRTM DEM')
# Add Landsat data to map
landsat = ee.Image('LE7_TOA_5YEAR/1999_2003')
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
Map.addLayer(landsat, landsat_vis, "LE7_TOA_5YEAR/1999_2003")
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, 'US States')
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
# Set visualization parameters.
dem_vis = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Engine DEM to map
Map.addLayer(dem, dem_vis, 'SRTM DEM')
# Add Landsat data to map
landsat = ee.Image('LE7_TOA_5YEAR/1999_2003')
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
Map.addLayer(landsat, landsat_vis, "LE7_TOA_5YEAR/1999_2003")
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, 'US States')
In [6]:
Copied!
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
out_dem_stats = os.path.join(out_dir, 'dem_stats.csv')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
# Allowed output formats: csv, shp, json, kml, kmz
# Allowed statistics type: MEAN, MAXIMUM, MINIMUM, MEDIAN, STD, MIN_MAX, VARIANCE, SUM
geemap.zonal_statistics(dem, states, out_dem_stats, statistics_type='MEAN', scale=1000)
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
out_dem_stats = os.path.join(out_dir, 'dem_stats.csv')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
# Allowed output formats: csv, shp, json, kml, kmz
# Allowed statistics type: MEAN, MAXIMUM, MINIMUM, MEDIAN, STD, MIN_MAX, VARIANCE, SUM
geemap.zonal_statistics(dem, states, out_dem_stats, statistics_type='MEAN', scale=1000)
Computing statistics ... Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/04e8c7b138ea4c98a9a99871c8737598-6da27b68234dfc3e2c9423450756acb6:getFeatures Please wait ... Data downloaded to /home/runner/Downloads/dem_stats.csv
In [7]:
Copied!
out_landsat_stats = os.path.join(out_dir, 'landsat_stats.csv')
geemap.zonal_statistics(
landsat, states, out_landsat_stats, statistics_type='SUM', scale=1000
)
out_landsat_stats = os.path.join(out_dir, 'landsat_stats.csv')
geemap.zonal_statistics(
landsat, states, out_landsat_stats, statistics_type='SUM', scale=1000
)
Computing statistics ... Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/ef7da058fa8cecffdece8d714da68ec8-a3ba713230ea7585cad1cc311425f2b3:getFeatures Please wait ... Data downloaded to /home/runner/Downloads/landsat_stats.csv
In [8]:
Copied!
geemap.create_download_link(out_dem_stats)
geemap.create_download_link(out_dem_stats)
In [9]:
Copied!
geemap.create_download_link(out_landsat_stats)
geemap.create_download_link(out_landsat_stats)
Last update:
2022-03-14