0

I have an image with land surface temperatures (LST) and polygons with administrative boundaries (adm3) and want to extract and export spatial statistics as a shapefile of said polyogns so that each feature contains the average raster value.

This works for the mean reducer

// Apply mean reducer 
 var means = LST.reduceRegions({
  collection: adm3,
  scale: 30,
  reducer: ee.Reducer.mean()
});

// Create empty feature
var feature = ee.Feature(null, means);

// Wrap the Feature in a FeatureCollection for export.
var featureCollection = ee.FeatureCollection([feature]);

// Export the FeatureCollection.
Export.table.toDrive({
  collection: featureCollection,
  folder: 'GEE_VN',
  description: 'adm3_LST_mean',
  fileFormat: 'SHP'
});

However, when I want to apply a percentile reducer (10 and 90 percent), the export fails

var p10 = LST.reduceRegions({
  collection: adm3,
  scale: 30,
  reducer: ee.Reducer.percentile([10]) 
});

This is the error message and I see that this is because the percentile reducer returns a dictionary, but I can't manage to address the 10p percentile correctly.

Error: Feature, argument 'metadata': Invalid type. Expected type: Dicationary<Object>. Actual type: FeatureCollection (Error code: 3)

Where do I have to convert the dictionary to a collection?

1 Answer 1

1

The output of reduceRegions with a percentile reduce ris already a featureCollection, so no need (and not possible) to define it as a feature and featureCollection. You can just export it directly:

Export.table.toDrive({
  collection: p10,
  folder: 'GEE_VN',
  description: 'adm3_LST_mean',
  fileFormat: 'SHP'
});

With a working example: https://code.earthengine.google.com/1a7916d16dff7991a52bb264e5150c0b

1
  • Thank you, you are right. I probably falsely copied this part from another script assuming it is necessary. This solves my problem.
    – AndyB
    Sep 23, 2021 at 10:46

Your Answer

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

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