I am trying to export a feature collection of histogram data for an image collection as a table in GEE. The image collection has three bands, NDSI_Snow_Cover, NDVI, and "remapped," which contains counts for 0, 1, 2, null values. The final table would have four columns: [system:index, 0, 1, 2, null], where the values under the 0, 1, 2, and null correspond to the histogram values from the remapped band.
I used the following link to get the histogram info: Exporting frequency histogram result as CSV in GEE?
But because I have an image collection, when I try to add the information to an empty feature collection the result is an empty variable. Instead, I add it as a property using .set(), but then it is harder to work with it as a property. Do I need to declare my null feature collection outside of my .map function? Is there a better way to get it into a feature collection or to export this information?
// COUNT EACH PIXEL VALUE FREQUENCY (ZONAL STATS)
var Hist_featureCollection = Collection.map(function(image){
var stats = image.reduceRegion({
reducer: ee.Reducer.frequencyHistogram(),
geometry: geometry,
scale: 30,
maxPixels: 1e15})
var image_Stats = image.set('pixelCount', stats)
var featurestats = ee.Feature(null, stats);
var FeatStats = ee.FeatureCollection([featurestats]);
return image_Stats // if i return FeatStats and export, the data table is empty
});
print(Hist_featureCollection)
// this is the right info but not as a feature collection
var pixelCountList = Hist_featureCollection.aggregate_array('pixelCount');
print(pixelCountList)
// Get a list of the dates.
Export.table.toDrive({
collection: Hist_featureCollection,
folder: 'GEE',
description:'pixelHist',
fileFormat: 'CSV'
});