4

I'm trying to export a frequency histogram table of a classified image for a region.

function country (image) {var c = image.reduceRegion({
  geometry: image.geometry(),
  reducer: ee.Reducer.frequencyHistogram(),
  scale: 30,
  maxPixels: 1e12,
}); return ee.Feature(c.select(['classification']))}

// export function
function export_table (table, description, date) { 
  var em = Export.table.toDrive({
    collection: ee.FeatureCollection(table),
    description: region+'_'+description+'_'+date,
    folder: region,
});return em}

But I get the error: Error: Invalid argument: 'collection' must be a FeatureCollection.

I've set the FeatureCollection in the export function, so I don't know what's happening here.

Link to code: https://code.earthengine.google.com/582da4a11433f1645b359b8ae2086c86

2 Answers 2

1

Try replacing collection: ee.FeatureCollection(table) with collection: em

and setting var em to ee.FeatureCollection(table)

I'm using the GGE - Exporting Data as reference. Under exporting to Drive.

To export a FeatureCollection to your Drive account, use Export.table.toDrive(). For example:

// Make a collection of points.
var features = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(30.41, 59.933), {name: 'Voronoi'}),
  ee.Feature(ee.Geometry.Point(-73.96, 40.781), {name: 'Thiessen'}),
  ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {name: 'Dirichlet'})
]);

// Export the FeatureCollection to a KML file.
Export.table.toDrive({
collection: features,
description:'vectorsToDriveExample',
fileFormat: 'KML'
});

Note that the output format is specified as KML to handle geographic data (SHP would also be appropriate for exporting a table with geometry). To export just a table of data, without any geographic information, export features with null geometry in CSV format. The following demonstrates using Export.table.toDrive() to get the results of a potentially long running reduction:

0

I tried yours and still code the same error, so instead I tried this and it worked.

Export.table.toDrive({
  collection: ee.FeatureCollection(May_2023), // Convert geometry to a feature collection if necessary
  description: 'exported_geometry', // Name of the exported file
  fileFormat: 'SHP' // Specify the export format (GeoJSON, Shapefile, etc.)
});

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.