I am extracting values from a Feature Collection over the MODIS Terra NDSI image collection using reduceRegions. I commented out the .filter(ee.Filter.neq('mean', null)) because I do want the null values. However, when I do, only some of the points have mean (the NDSI value) has a property. Do I need to add the mean value as it's own property in order to also extract null values?
I tried this: Google Earth Engine – add label to feature collection table/CSV and: GEE check only one sentinel tile instead of checking all of them when the featurecollection is in many tiles apporaches but no luck.
I am using a sample feature collection to make debugging easier. Below is the code:
var features = [
ee.Feature(ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {name: 'Voronoi'}),
ee.Feature(ee.Geometry.Point(-73.96, 40.781), {name: 'Thiessen'}),
ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {name: 'Dirichlet'})
];
var fromList = ee.FeatureCollection(features);
print('fromList',fromList);
var MOD10A1 = ee.ImageCollection('MODIS/006/MOD10A1')
.filter(ee.Filter.date('2018-01-01', '2018-05-30'))
.select(['NDSI_Snow_Cover']);
var results = MOD10A1.map(function(image) {
return image.reduceRegions({
collection: fromList,
reducer: ee.Reducer.mean(),
scale: 30
})//.filter(ee.Filter.neq('mean', null)) //** i think this is why I was getting weird values for the GEE extraction
.map(function(f) {
return f.set('imageId', image.date());
});
}).flatten()
print(results)
Export.table.toDrive({
collection: results,
description: 'results',
fileFormat: 'CSV'
});
Best Answer
There's no difference between a null value in a feature and no value. If you want an "empty" property in the export where there was no result from the reduceRegions, then you can map over the results and add a default value. This is probably easiest by converting to a dictionary first and using combine with overwrite=false.