2

I am trying to use earth engine to reduce the USGS land cover dataset and calculate the frequency of specific land cover types in several regions. The output that I am getting creates a single dictionary with a list of land cover types and values for each county (region).

I am curious if I can break this dictionary up to allow a table to be exported to google drive with each land cover type having a unique column?

Here is my code:

// Load a FeatureCollection of Maine Counties.
var Counties = ee.FeatureCollection('ft:1S4EB6319wWW2sWQDPhDvmSBIVrD3iEmCLYB7nMM').filter(ee.Filter.eq('StateName', 'Maine'));

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

// Clip the image to the polygon geometry
var LandCover2011 = LandCover2011.clip(Counties);

// Extract the landcover band
var landcover = LandCover2011.select('landcover');


// Print out the frequency of landcover occurrence for each county
var frequency = landcover.reduceRegions({
  collection: Counties,
  reducer:ee.Reducer.frequencyHistogram(),
  scale:30
});

//Prints Feature collection
print(frequency);

//Exports table to drive
//Export.table.toDrive(frequency, "MaineLandCoverData");
4

You can get the "histogram" property (resulting from the reducer) as a Dictionary which can be used to set the landcover:frequency pairs as new properties for a county feature. Then just map that function over all counties in the FeatureCollection.

// Print out the frequency of landcover occurrence for each county
//...

// Optional for debugging: Drop other properties and geometry > simpler looking csv.
frequency = frequency.select(['histogram'], null, false)

var frequency = frequency.map(function(feature){
  var dict = ee.Dictionary(feature.toDictionary().get('histogram'))
  feature = feature.set(dict)
  return feature
})
print('per class landcover frequency properties', frequency)

//Exports table to drive
Export.table.toDrive(frequency, "MaineLandCoverData");
  • Thanks Christoph I wonder as this seems to be counting pixels - how can it be accurate to area please? I'm trying to do this for all US counties and sensitive to the measurements used (e.g. will need to know in acres, hectares, or similar). – BB88 Jul 7 '19 at 17:41
  • As you said, the histogram reducer counts pixels. As you know the projection and scale you can transform that info to an area measurement. Best you open a new questions, not really ontopic here. – Christoph Rieke Jul 7 '19 at 18:39

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.