137 create grid
Creating a rectangular grid covering a region of interest for computing zonal statistics
Uncomment the following line to install geemap if needed.
In [ ]:
Copied!
# %pip install git+https://github.com/gee-community/geemap.git
# %pip install git+https://github.com/gee-community/geemap.git
Import libraries
In [ ]:
Copied!
import ee
import geemap
import ee
import geemap
Update the package and restart the kernel if you run into errors.
In [ ]:
Copied!
# geemap.update_package()
# geemap.update_package()
Add temperature data.
In [ ]:
Copied!
Map = geemap.Map(center=[40, -100], zoom=4)
image = ee.ImageCollection('NOAA/GFS0P25').first().select('temperature_2m_above_ground')
vis_params = {
'min': -40.0,
'max': 35.0,
'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red'],
}
Map.addLayer(image, vis_params, 'Temperature')
Map.add_colorbar(vis_params, label="Temperature (°C)")
Map
Map = geemap.Map(center=[40, -100], zoom=4)
image = ee.ImageCollection('NOAA/GFS0P25').first().select('temperature_2m_above_ground')
vis_params = {
'min': -40.0,
'max': 35.0,
'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red'],
}
Map.addLayer(image, vis_params, 'Temperature')
Map.add_colorbar(vis_params, label="Temperature (°C)")
Map
Create a grid covering the area of interest.
In [ ]:
Copied!
geometry = ee.Geometry.BBox(-130, 24, -68, 50)
grid = geemap.create_grid(geometry, 2e5)
Map.addLayer(grid, {}, 'Grid')
geometry = ee.Geometry.BBox(-130, 24, -68, 50)
grid = geemap.create_grid(geometry, 2e5)
Map.addLayer(grid, {}, 'Grid')
Compute zonal statistics based on the image and grid. In this case, we are computing the mean temperature for each grid cell.
In [ ]:
Copied!
stats = geemap.zonal_stats(
image, grid, statistics_type='MEAN', scale=2e5, return_fc=True
)
stats = geemap.zonal_stats(
image, grid, statistics_type='MEAN', scale=2e5, return_fc=True
)
In [ ]:
Copied!
stats
stats
Add the mean temperature grid to the map.
In [ ]:
Copied!
Map.add_styled_vector(
stats, column="mean", palette='coolwarm', layer_name="Mean Temperature"
)
Map.add_layer_manager()
Map
Map.add_styled_vector(
stats, column="mean", palette='coolwarm', layer_name="Mean Temperature"
)
Map.add_layer_manager()
Map