I would like to understand why I'm getting Null value for some polygons when using reduceRegions
in google earth engine.
Basically, I want to compute median pixel value within watersheds (polygons) and for a reason I would like to understand, after using reduceRegions
, I get Null values for most of them. Here below there is a reproducible code with some watersheds in Belgium. The raster I would like to reduce at watershed scale is one of the soilgrids layers. In this example, I got "Null" values for all the polygons.
var sheds = ee.FeatureCollection("WWF/HydroSHEDS/v1/Basins/hybas_12"),
AOI =
/* color: #98ff00 */
/* displayProperties: [
{
"type": "rectangle"
}
] */
ee.Geometry.Polygon(
[[[4.568615353352863, 50.609274226146866],
[4.568615353352863, 50.51505828131529],
[4.804821408040363, 50.51505828131529],
[4.804821408040363, 50.609274226146866]]], null, false);
// Filter watershed in the area of interest
var sheds_filtered = ee.FeatureCollection("WWF/HydroSHEDS/v1/Basins/hybas_12")
.filterBounds(AOI)
Map.addLayer(sheds_filtered)
// Load soil grid data https://doi.org/10.17027/isric-soilgrids.713396f9-1687-11ea-a7c0-a0481ca9e724
var bdod = ee.Image("projects/soilgrids-isric/bdod_mean")
.clip(sheds_filtered);
// Load another raster which doesn't seem to result with Null value after reduction
var treecover = ee.ImageCollection('MODIS/006/MOD44B')
.select('Percent_Tree_Cover')
.median().clip(sheds_filtered);
// Map the raster layers
Map.centerObject(AOI);
Map.addLayer(bdod);
Map.addLayer(treecover);
// Perform the reduction
var bdod_mean = bdod.reduceRegions(sheds_filtered.select('HYBAS_ID'), ee.Reducer.median(), 10);
var tree_cover_mean = treecover.reduceRegions(sheds_filtered.select('HYBAS_ID'), ee.Reducer.median(), 10);
// Null values for bdod_mean and actual values with MODIS products
print(bdod_mean)
print(tree_cover_mean)