TransWikia.com

Export properties of a featureCollection along with features of it in Google Earth Engine

Geographic Information Systems Asked by OverFlow Police on August 31, 2021

I want to read an imageCollection, reduce all images in the collection by the region. and save the result.

However, when I save the result, the properties of the feature Collection is gone. It does not get saved.

Any suggestion?

// Load four 2012 NAIP quarter quads, different locations.
var naip2012 = ee.ImageCollection('USDA/NAIP/DOQQ')
                .filterBounds(ee.Geometry.Rectangle(-71.17965, 42.35125, -71.08824, 42.40584))
                .filterDate('2012-01-01', '2012-12-31');

var reduced = naip2012.map(function(image){
  return image.reduceRegions({
    collection:ee.Feature(ee.Geometry.Rectangle(-71.17965, 42.35125, -71.08824, 42.40584)), 
    reducer:ee.Reducer.mean(), 
    scale: 30
  });
});

reduced = reduced.flatten();
print(reduced);

Export.table.toDrive({
  collection: reduced,
  description:'properties_gone_by_saving',
  fileFormat: 'CSV'
});

One Answer

Convert the reduced to a dictionary. The result of that would be the properties. Add the dictionary to all images of the imageCollection.

Export the result:

// Load four 2012 NAIP quarter quads, different locations.
var naip2012 = ee.ImageCollection('USDA/NAIP/DOQQ')
                .filterBounds(ee.Geometry.Rectangle(-71.17965, 42.35125, -71.08824, 42.40584))
                .filterDate('2012-01-01', '2012-12-31');

var reduced = naip2012.map(function(image){
  return image.reduceRegions({
    collection:ee.Feature(ee.Geometry.Rectangle(-71.17965, 42.35125, -71.08824, 42.40584)), 
    reducer:ee.Reducer.mean(), 
    scale: 30
  });
});

var reduced_flat = reduced.flatten();

Export.table.toDrive({
  collection: reduced_flat,
  description:'properties_gone_by_saving',
  fileFormat: 'CSV'
});

/////// Solution here //
reduced = reduced.toDictionary();
reduced_flat = reduced_flat.map(function(im){return(im.set(reduced))}); 

print(reduced_flat);

Export.table.toDrive({
  collection: reduced_flat,
  description:'properties_not_gone',
  fileFormat: 'CSV'
});

Answered by OverFlow Police on August 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP