1

I'm trying to build a FeatureCollection from 4 differents FeatureCollection in order to export an excel with 4 columns containg the 4 differents lists. Here is an example of the strucuture of each FeatureCollection enter image description here And how I get them :

var chloaFeatures = ee.FeatureCollection(ee.List(chloa_4kmOnly
  .reduceRegion({
    reducer : ee.Reducer.toList(),
    geometry : geometry, 
    crs : ModisProjection
  })
  .get('Chloa_OC3'/*,'SR_B1','SR_B2','SR_B3'*/))
  .map(function(chloa){
    return ee.Feature(null, {chloa_4kmOnly : chloa})
  })
)

var B1Features = ee.FeatureCollection(ee.List(chloa_4kmOnly
  .reduceRegion({
    reducer : ee.Reducer.toList(),
    geometry : geometry, 
    crs : ModisProjection
  })
  .get('SR_B1'))
  .map(function(chloa){
    return ee.Feature(null, {B1 : chloa})
  })
)

var B2Features = ee.FeatureCollection(ee.List(chloa_4kmOnly
  .reduceRegion({
    reducer : ee.Reducer.toList(),
    geometry : geometry, 
    crs : ModisProjection
  })
  .get('SR_B2'))
  .map(function(chloa){
    return ee.Feature(null, {B2 : chloa})
  })
)

var B3Features = ee.FeatureCollection(ee.List(chloa_4kmOnly
  .reduceRegion({
    reducer : ee.Reducer.toList(),
    geometry : geometry, 
    crs : ModisProjection
  })
  .get('SR_B3'))
  .map(function(chloa){
    return ee.Feature(null, {B3 : chloa})
  })
)

You can find my complete code here: https://code.earthengine.google.com/4ceaa4d6f96e1107f2f53af572e3badd

1 Answer 1

1

It is easier (and a lot more efficient) to do a single reduceRegion() and transform the resulting dictionary into your feature collection. That transformation requires a bit of fiddling, but here's a reasonably easy way to do it:

var valuesByBand = chloa_4kmOnly
  .reduceRegion({
    reducer : ee.Reducer.toList(),
    geometry : geometry, 
    crs : ModisProjection
  })

var features = ee.FeatureCollection(
  ee.Array(valuesByBand.values())
    .transpose()
    .toList()
    .map(function (values) {
      return ee.Feature(null, ee.Dictionary.fromLists(
        valuesByBand.keys(), 
        values
      ))
    })
)
Export.table.toDrive({
  collection: features,
  description: 'Features_Landsat',
  folder: 'tanganyika',
  fileFormat: 'CSV',
  selectors: ["Chloa_OC3", "SR_B1", "SR_B2", "SR_B3"]
})

https://code.earthengine.google.com/014c1b5812232b8399d12485c83fdcd2

8
  • Thanks, I got this error when applying it to a new geometry ;Reprojection output too large (7798x20340 pixels). Do you have an idea on how to deal with it ? Commented Oct 16, 2023 at 12:42
  • Can you include a link to the script giving the error? Commented Oct 16, 2023 at 12:56
  • Here you are : code.earthengine.google.com/8240b41282199f07065ce938d1b5d3e6 Commented Oct 16, 2023 at 13:02
  • Can you share your ROI asset? Commented Oct 16, 2023 at 13:29
  • I assume the issue is ee.Reducer.toList(). It will not work for any larger areas. I don't know your use-case for essentially exporting an image as a CSV, but if you need any larger area, you will have to use another data format, such as GeoTIFF. Commented Oct 16, 2023 at 13:32

Your Answer

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