1

I try to add a list of Features into a FeatureCollection with ee.FeatureCollection but it raises the following Error: *

"FeatureCollection (Error)
Collection, argument 'features': Invalid type. Expected: List<Element>. Actual: List<List<Object>>"

I don't understand the difference between Object and Element. It is necessary to convert the single Features Object into an single Feature Element?

var s2aprop = ee.FeatureCollection([
ee.Feature(s2a_p.aggregate_array("CLOUDY_PIXEL_PERCENTAGE"),{name:'Cloudy_Percentage'}),
ee.Feature(s2a_p.aggregate_array("PRODUCT_ID"),{name:'Product_Id'}),
ee.Feature(s2a_p.aggregate_array("SENSING_ORBIT_DIRECTION"),{name:'Orbit_Direction'}),
ee.Feature(s2a_p.aggregate_array("SENSING_ORBIT_NUMBER"),{name:'Orbit_Number'}),
ee.Feature(s2a_p.aggregate_array("SNOW_ICE_PERCENTAGE"),{name:'Snow_Ice_Percentage'}),
ee.Feature(s2a_p.aggregate_array("VEGETATION_PERCENTAGE"),{name:'Vegetation_Percentage'}),
ee.Feature(s2a_p.aggregate_array("WATER_PERCENTAGE"),{name:'Water_Percentage'}),
ee.Feature(s2a_p.aggregate_array("UNCLASSIFIED_PERCENTAGE"),{name:'Uncalssified_Percentage'}),
ee.Feature(s2a_p.aggregate_array("SPACECRAFT_NAME"),{name:'Spacecraft'})
])

var s2aprops = ee.FeatureCollection(s2aprop)
print (s2aprop)

https://code.earthengine.google.com/ca44d644303c7212c4a11e4c00f752a9 Line 161-174

1 Answer 1

1

Note that the return value of aggregate_array() is an ee.List(), which you can discover by printing it (the docs are not obvious about this). The ee.Feature constructor expects an ee.Geometry and optionally properties. You're not supplying that, which is why it's not working. Here's an example of how to fix that:

var s2aprop = ee.FeatureCollection([
  ee.Feature(null, {
    name: 'Cloudy_Percentage',
    array: s2a_p.aggregate_array("CLOUDY_PIXEL_PERCENTAGE")
  })

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.