Exporting NDVI for multiPoint Geometry in Python API of Google Earth Engine

google-earth-enginendvipythonsentinel-2

I have a list of mine coordinates and I want to export the mean NDVI of the region 5 km around the mine area. I was able to plot the mines, the region of interest and calculation of NDVI on map, but when I tried exporting those regions, I only got a single value instead of mean NDVI for all the mines.

This is how my code currently looks like. Because I don't get any error in the code, I am unable to figure out where the logical error in the code lies.

mine_coordinates = [[77.3384, 28.6902], [74.5921, 28.7081], [72.0131, 24.6037], [86.5405, 25.0426], [82.7497, 22.3285]] #sample coordinates only
mine_area = ee.Geometry.MultiPoint(mine_coordinates).buffer(5000) #circular region of 5 kms radius around the point

def getNDVI(image):
    return image.normalizedDifference(['B8', 'B4'])

image_left = ee.ImageCollection('COPERNICUS/S2_SR').filterDate('2020-11-01', '2020-11-30').median().clip(mine_area)

ndvi_left = getNDVI(image_left) #input and output are images
ndviParams = {'min': 0,
               'max': 0.5,
               'palette': ['#d73027', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850']}

mine_map = gm.Map(center = [24.922695, 77.531718], zoom = 6, lite_mode = True)
mine_map.addLayer(mine_area, {'color': 'red'})
mine_map.addLayer(ndvi_left, ndviParams, 'NDVI')
mine_map.addLayerControl()
mine_map

mineMeansFeatures = ndvi_left.reduceRegions(
    collection = mine_area,
    reducer = ee.Reducer.mean(),
    scale = 30,
)

ee.batch.Export.table.toDrive(collection = mineMeansFeatures, description = 'mineNDVI', fileFormat = 'CSV').start()

I get the following result after running this code.
NDVI around mines

But, in the output CSV I get a table with a single row like this
system:index mean .geo
0 0.2423464309 {"type":"MultiPolygon","coordinates":[multiple coordiantes here]}

What I am looking at is something like this

Location Mean_NDVI
A 0.25
B 0.56
C 0.42

Best Answer

A Multipoint is considered a single geometry and you're reducing all the pixel in each geometry to a single value. Instead, you want multiple features, each with a single point in it.

locations = ee.List([[77.3384, 28.6902], [74.5921, 28.7081], [72.0131, 24.6037], [86.5405, 25.0426], [82.7497, 22.3285]])
    .map(lambda coords : ee.Feature(ee.Geometry.Point(coords).buffer(5000)))
mine_area = ee.FeatureCollection(locations)
Related Question