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");
Answer
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");
No comments:
Post a Comment