I'm trying to replicate this python script to calculate NDVI mean for a feature collection (https://stackoverflow.com/questions/47633088/get-results-in-an-earth-engine-python-script). It seems like the code calculates a result, but a cant see result. This is the code:

import datetime
import ee

#Feature collection
fc = ee.FeatureCollection("ft:1x290vohty0Wgdn5jL3RlpzryK7dfOPtG6yY213e0");
fc_filtered = fc.filter(ee.Filter.equals('NUM_DECS', 1))
#Image collection
Sentinel_collection = (ee.ImageCollection('COPERNICUS/S2')

def GetSeries(feature):
  def NDVIcalc(img):
    red = img.select('B4')
    nir = img.select('B8')
    ndvi = nir.subtract(red).divide(nir.add(red)).rename(['NDVI'])
    return (feature
            .set(ndvi.reduceRegion(ee.Reducer.mean(), feature.geometry(), 10))
            .set('date', img.date().format("YYYYMMdd")))

  series = Sentinel_collection.map(NDVIcalc)
  list = series.reduceColumns(ee.Reducer.toList(2), ['date', 'NDVI']).get('list')
  return feature.set(ee.Dictionary(ee.List(list).flatten()))

result = fc_filtered.map(GetSeries)

Give me this result:

{'columns': {}, 'type': 'FeatureCollection', 'features': [], 'properties': {'name': 'kmltest', 'DocID': '1x290vohty0Wgdn5jL3RlpzryK7dfOPtG6yY213e0'}}

So it does not looks like something is coming out of it?

I havent yet tried the next where the following is included:

# Get all possible dates.
dates = ee.List(Sentinel_collection.map(function(img) {
      return ee.Feature(null, {'date': img.date().format("YYYYMMdd") })

# Make a default value for every date.
header = ee.Feature(null, ee.Dictionary(dates, ee.List.repeat(-1, dates.size())))
output = header.merge(result)

Any suggestions for what a do wrong? Will prefer to have the result in the feature collection or exported as a list.

  • 2
    Are you sure fc_filtered contains any features after this: fc_filtered = fc.filter(ee.Filter.equals('NUM_DECS', 1))? – blindjesse Apr 24 '18 at 18:00
  • Does the NUM_DECS relate to something in the feature collection? – student Apr 24 '18 at 18:25
  • Im not sure it contains anything – student Apr 24 '18 at 18:32
  • 2
    I don't think you want series.reduceColumns(). You might want reduceRegions() on an image, but that is not a method on an ImageCollection. I think you should see this tutorial and modify your example accordingly. – Nicholas Clinton Apr 25 '18 at 16:16
  • 1
    Your Fusion Table is not shared, which is preventing others from replicating your issue. EEException: Collection.loadTable: Permission denied for Fusion Table '1x290vohty0Wgdn5jL3RlpzryK7dfOPtG6yY213e0'. – Tyler Erickson May 1 '18 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.