1

I am working out the area (in hectares) of a land cover class in the counties of California using google earth engine. So far, I have created a featurecollection that works, but when I try to use the export to table function I get the following error:

Error: Feature, argument 'metadata': Invalid type. Expected: Dictionary. Actual: FeatureCollection.

I don't mind if the export is CSV or SHP - whichever is easiest as I will then analyze my data in R/arcpy.

My code is as follows:

print('starting...');
// Load a FeatureCollection of US Counties.
var Counties = ee.FeatureCollection("TIGER/2016/Counties");

//Imports NLCD Land Cover Data
var LandCover = ee.Image('USGS/NLCD/NLCD2011')

var cali = Counties.filter(ee.Filter.eq('STATEFP','06'));
Map.addLayer(cali, {}, 'cali');

// Clip the image to the polygon geometry
var LandCover = LandCover.clip(cali);


// Extract the landcover band
var landcover = LandCover.select('landcover');
Map.addLayer(landcover, {}, 'landcover');

// create masks for each class, then covert into area by multiplying by pixel
// area and dividing by class #, then sum reduce over the counties
// then export each as a table (if you can aggregate into one table)
// https://gis.stackexchange.com/questions/230774/extracting-land-cover-type-in-google-earth-engine

var lc11 = landcover.eq(52);
var mask11 = landcover.mask(lc11);
var pixarea = ee.Image.pixelArea();

var pix2area11 = mask11.select('landcover').multiply(pixarea.select('area')).divide(520000);

Map.addLayer(pix2area11, {}, 'pix2area11');

pix2area11 = pix2area11.select('landcover');
var area11 = pix2area11.reduceRegions({
  collection: cali,
  reducer: ee.Reducer.sum(),
  scale: 30,
});
// Print the first feature, to illustrate the result.
print(ee.Feature(area11.first()));

// Translate feature collection to table with necessary identifiers

area11 = area11.select(['sum', 'COUNTYFP', 'STATEFP']);


print(area11);
Map.addLayer(area11, {}, 'area11');

// Make a feature without geometry and set the properties to the dictionary of area11.
var feature = ee.Feature(null, area11);

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

// Export the FeatureCollection.
Export.table.toDrive({
  collection: featureCollection,
  description: 'area11',
  fileFormat: 'CSV'
});
// https://developers.google.com/earth-engine/exporting

print('done');

0

The second argument of ee.Feature must be

properties (Object, optional): A dictionary of metadata properties. If the first parameter is a Feature (instead of a geometry), this is unused.

but you are using a ee.Feature instead of an Object (dictionary). What I understand is that you want to get rid of the geometry and only export the properties. Otherwise you could just export area11.

For exporting the collection without the geometries you can do:

// Wrap the Feature in a FeatureCollection for export.
var featureCollection = area11.map(function(feat){
  var nullfeat = ee.Feature(null)
  return nullfeat.copyProperties(feat)
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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