I am trying to create a zonal_statistics
function in Google Earth Engine Python API.
The function should be applied to an object of type ee.Image
and should receive two arguments: an ee.FeatureCollection
and a reducer (e.g. ee.Reducer.mean()
).
The function must return an object of type GeoDataFrame with the statistics of each polygon.
import ee
import geopandas as pd
# image -- is a ee.Image object
# features -- is a ee.FeatureCollection object
zone_stats = image.reduceRegions(collection=features, reducer=ee.Reducer.mean(), scale=10).getInfo()
zone_stats = gpd.GeoDataFrame.from_features(zone_stats, crs='epsg:4326')
How can I integrate this process in a single function?
Best Answer
Just put the code inside def statement