1

I am new to Google Earth Engine and QGIS. I have a Polygon of a city and I have a CSV file for 30000 unique geocode (belonging to the participants who were entered in the study) I want to obtain the value of the NDVI at each location at the start time of the study (which is 2014) and then I want to have the mean NDVI for the period 2014-2016 at each location. I mean I should have two values for the NDVI.

here is the code but I don't know how to change it to have min, max, and mean NDVI in 30000 geocode. I mean is it possible to have "min, max, and mean NDVI" just in the desired location?


Map.centerObject(geometry);
Map.addLayer(geometry, {color: 'FF0000'}, 'geodesic polygon');

var imagecol = ee.ImageCollection("LANDSAT/LE07/C01/T1_SR")
  .filterDate('2014-05-01', '2016-07-31')
  .filter(ee.Filter.calendarRange(5, 7, 'month'))
  .filterBounds(geometry)
  .sort('CLOUD_COVER', false)

var getNDVI = function(image) {
  var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
  return image.addBands(ndvi);
};

var withNDVI = imagecol.map(getNDVI);

var greenest = withNDVI.qualityMosaic('NDVI');
var NDVI = greenest.select('NDVI');

var NDVI = NDVI.clipToCollection(geometry);

var zonalNDVI = NDVI.reduceRegions({
  collection: geometry,
  reducer: ee.Reducer.mean(),
  scale: 30,
  crs: 'EPSG:3310',
});

print(zonalNDVI);
Export.table.toDrive({collection: zonalNDVI, fileFormat: 'GeoJSON'}); ```
1
  • Why is there a QGIS-tag on the question?
    – Erik
    Mar 31, 2022 at 6:51

1 Answer 1

0

Depending on how your geometry looks like you can map over each feature and select the ndvi of the entire period and your first image with these two functions:

  var ndviFirstImage = withNDVI.first().select('NDVI').reduceRegion({
    geometry: point.geometry(),
    reducer: ee.Reducer.mean(),
    scale: 30,
    crs: 'EPSG:3310'
  }).get('NDVI')
  // print(ndviFirstImage, 'ndviFirstImage')
  
  var ndviTotal = NDVI.reduceRegion({
    geometry: point.geometry(),
    reducer: ee.Reducer.mean(),
    scale: 30,
    crs: 'EPSG:3310'
  }).get('NDVI')

See the link for the full mapped function: https://code.earthengine.google.com/b59b1eda0c521322fea31c7ee1375f1d

EDIT Forgot to change the export function:

Export.table.toDrive({collection: mappedFunction.flatten(), fileFormat: 'GeoJSON'}); 

https://code.earthengine.google.com/d4e679acf04ff44d99f38577d96cf947

3
  • Sorry I forgot to change the file to export, I edited the answer. Does it work now? Can't ofcourse tell if it works for your csv because I don't have it.
    – Jobbo90
    Mar 31, 2022 at 9:09
  • Thanks for your help. I apologize if my question is stupid. As I am a public health researcher and it is a little difficult for me to understand the coding context. I added the CSV file as an asset but when I click on it to see the asset detail I see this "The table may not have valid geometries." the file has 3 columns including PID, X, and, Y (PID 1078 X 37°57'33.0 Y 55°31'02.0) @Jobbo90
    – fary
    Mar 31, 2022 at 9:54
  • Upon uploading you need to specify which columns contain the x,y coordinates and make sure the format of your values are understandable. Often degree symbols are not a readable format.
    – Jobbo90
    Mar 31, 2022 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.