1

I have a feature collection (samplePlots) with 2755 features. When I use the code below, I expect a list with 2755 elements, but the result is a list with only 2515 elements. What would be the reason? Unfortunately I can't share the feature collection.

image.reduceRegion({
  reducer: ee.Reducer.toList(),
  geometry: samplePlots,
  scale: 30
})

1 Answer 1

1

You are using reduceRegion, which does not do anything in particular about feature collections; it takes a geometry. Or, it can also accept a feature and use the feature's geometry. A feature collection is considered a kind of feature, and its geometry is the union of the geometries of its features.

So, you're asking reduceRegion to find every pixel in the image which is intersected by your collection (which I assume is made of points). This process will:

  • report a pixel only once if more than one point are inside its bounds, and
  • omit all fully masked pixels.

Instead, you should use reduceRegions, which actually takes a feature collection, and returns a feature collection, having the same features but with added properties corresponding to the reducer outputs. This will be guaranteed to have the same number of outputs as inputs. (The reducer can be almost anything, in this case, since it always gets at most one input when the feature is a point; ee.Reducer.median() might be a good choice, for example.)

Then, if you specifically need a ee.List instead of a feature collection, you can use .reduceColumns(ee.Reducer.toList(), ['name_of_band_goes_here']) to get that out of the feature collection. But, working with feature collections as much as possible will give you better performance when the number of features is large.

1
  • Thanks for the quick and well explained answer, I believe that with this information I can solve my problem. I was working with lists because I thought it was easier to export the information and work on it in R. Commented Sep 2, 2020 at 0:09

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.