1

I'm trying to calculate the mean soil moisture value for a particular polygon over a period of time by using ee.Reducer.mean() in ee.reduceRegion() The polygon is initially loaded as a feature; however, in reduceRegion, I am specifying feature.geometry() for the geometry parameter. When I run my code, I get the error:

Element (Error) Collection.first: Error in map(ID=0000000000000000b79f): Image.reduceRegion: Provide 'geometry' parameter when aggregating over an unbounded image.

After receiving the error, I tried clipping smam, but it gave me the error:

"The geometry for image clipping must be bounded."

I tried looking at GEE Error: Provide 'geometry' parameter when aggregating over an unbounded image but both solutions provided for the problem unfortunately did not work for me. Currently, I suspect that the feature.geometry() for the polygon may be too large, but I do not see how this could happen as I have used .filterBounds(table) (table is a shapefile of an administrative region I imported) for my region of interest.

Would anyone have any idea what might be causing this error?

My code is:

var dataset = ee.FeatureCollection('JRC/GWIS/GlobFire/v2/FinalPerimeters').filter(ee.Filter.gte('IDate', 155725210000)).filterBounds(table);
var soilmoisture = ee.ImageCollection("NASA/SMAP/SPL3SMP_E/005").filterBounds(table);

var compute = function(feature) {
  var keepProperties = ['Id', 'IDate', 'FDate', 'system:index'];
  
  var final = ee.Feature(feature).copyProperties(feature, keepProperties);
  
  var start = ee.Number(feature.get('IDate')).subtract(604800000);
  var end = ee.Number(feature.get('IDate'));
  
  var geom = feature.geometry();
  
  var smam = soilmoisture.filterBounds(geom).filterDate(start, end).select('soil_moisture_am').mean();
  
  var reduced = smam.reduceRegion({reducer: ee.Reducer.mean(), geometry: geom, scale: 9000, maxPixels: 1e9});
  final = final.set('soil_moisture_am', reduced.get('soil_moisture_am'));
  
  return final;
};

var final_dataset = dataset.map(compute);
print(final_dataset.first());

1 Answer 1

0

That issue is produced due bad geometries in dataset Feature Collection. That was already considered here. However, there are another issue related to soilmoisture Image Collection. You need to use a conditional statement to prevent complete masked images at Feature area. On the other hand, you don't need to use .filterBounds method because images are displayed on global scale.

Your fixed code looks as follows:

var dataset = ee.FeatureCollection('JRC/GWIS/GlobFire/v2/FinalPerimeters')
  .filter(ee.Filter.gte('IDate', 155725210000))
  .filterBounds(table)
  .filter(ee.Filter.intersects(".geo", ee.Geometry.Point([0,0])).not());

//Map.addLayer(dataset);
Map.centerObject(dataset, 10);

var soilmoisture = ee.ImageCollection("NASA/SMAP/SPL3SMP_E/005").filterBounds(table);

var compute = function(feature) {
  var keepProperties = ['Id', 'IDate', 'FDate', 'system:index'];
  
  var final = ee.Feature(feature).copyProperties(feature, keepProperties);
  
  var start = ee.Number(ee.Feature(feature).get('IDate')).subtract(604800000);
  var end = ee.Number(ee.Feature(feature).get('IDate'));
  
  var geom = ee.Feature(feature).geometry();
  
  var smam = soilmoisture.filterDate(start, end).select('soil_moisture_am').mean();
  
  var reduced = smam.reduceRegion({reducer: ee.Reducer.mean(), geometry: geom, scale: 9000, maxPixels: 1e9});

  return ee.Algorithms.If(ee.Number(smam.bandNames().size()).gt(0), 
                          final.set('soil_moisture_am', reduced.get('soil_moisture_am')), 
                          final.set('soil_moisture_am', 'not available'));

};

var final_dataset = dataset.map(compute);

print(final_dataset);

Map.addLayer(final_dataset, {}, 'final_dataset');

var final_dataset_areas = final_dataset.toList(final_dataset.size()).map(function (ele) {
  
  return ee.Feature(ele).geometry().area();
  
});

print(final_dataset_areas);

var test = ee.List(final_dataset.toList(final_dataset.size())).get(229); //95, 119

print("test", test);

Map.addLayer(ee.Feature(test), {color: 'yellow'}, 'test');
Map.addLayer(table, {color: 'red'}, 'table');

Considering an arbitrary geometry (table) in Asia, I got following result after running complete code at GEE code editor. It can be observed that there are 602 features in final_dataset intersecting table area. I placed one of the larger ones on the map canvas (yellow color) for comparison purposes.

enter image description here

1
  • Thank you so much!
    – rxc_3049
    Jul 11, 2023 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.