3

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)

1 Answer 1

2

You're hitting a (known) bug. You can work around it by adding a limit() to the table; just make sure the limit size is sufficiently large to get all your features (you could theoretically use collection.size(), but no reason to wait for that to be computed, just use a large number).

var bdod_mean = bdod.reduceRegions({
  collection: sheds_filtered.select('HYBAS_ID').limit(1000),  
  reducer: ee.Reducer.median(), 
  scale: 30
});
4
  • Thanks! Is a fix for this bug planned?
    – Adrien
    Aug 11, 2021 at 8:42
  • Does this bug come from the high number of features in the source polygon layer ? Or from the presence of null values for the raster in the area of interest? It seems to work as expected with a raster with no null values (see my edits with MODIS raster)
    – Adrien
    Aug 11, 2021 at 8:43
  • 1
    We're slowly tracking down the cause. It has something to do with the table system failing to compute the intersecting tiles properly against the global footprint on the image; if you clip the image before doing the reduceRegions, that also fixes it. (limit 'detaches' the table from the underlying table system). Aug 12, 2021 at 8:23
  • Has this been fixed? We are experiencing what seems to be the same issue.
    – Jon
    Oct 9, 2021 at 18:04

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.