I'm trying to find the lowest 20th percentile figure and corresponding area across different geographies defined by an image.
The image is obtained from the multiplication of 2 images, which has produced many disparate polygons in brown (soil taxonomy and slope). See below.
var img1a = soiltaxa.eq(389).and(slope0206Mask);
Map.addLayer(img1a.updateMask(img1a),{palette:'brown'},'1a');
Separately, I created a single band for soil carbon below in black.
var SOC = socc.multiply(bd)
.multiply(5*0.1*10000/(250*250))
.clip(region);
var imgSOC30 = ee.Image(SOC.select('b0','b10','b30'));
var SOC30 = imgSOC30.reduce('sum');
Map.addLayer(SOC30,{min:12,max:242},'SOC30',0);
I want to find the lowest 20th percentile and corresponding area of the single band represented in the bottom picture in monochrome (soil carbon) for just the brown geographies in the top picture.
The issue seems to be that the brown polygons in the top picture are an Image. How do I use Google Earth Engine to calculate the the lowest 20th percentile soil carbon and corresponding area for just the brown polygons?
The code below works if I substitute "img1a" for a geometry, but when I use "img1a", I get an error message saying: Dictionary (Error) Image.reduceRegion, argument 'geometry': Invalid type. Expected type: Geometry. Actual type: Image<[grtgroup]>.
var SOC30percgeo = SOC30.reduceRegion({
reducer: ee.Reducer.percentile([20,50,80]),
geometry: img1a,
scale: 250, // Resolution in meters.
maxPixels: 1e9});
print('SOC30 percentiles for geo',SOC30percgeo);
// Get lowest 20th percentile SOC30 for geo.
var DegradedSOC30geo = SOC30.clip(img1a).lte(ee.Number(SOC30percgeo.get('sum_p20')));
Map.addLayer(DegradedSOC30geo.updateMask(DegradedSOC30geo),{palette:'red'},'Degraded SOC30 geo');
// Get pixel area for geo degraded and convert to ha.
var DegradedSOC30geoArea = DegradedSOC30geo.multiply(ee.Image.pixelArea()).divide(10000);
// Sum pixels for geo degraded.
var DegradedSOC30geoSize = DegradedSOC30geoArea.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: img1a,
scale: 250, // Resolution in meters
maxPixels: 1e9
});
print('degraded area in geo: ',DegradedSOC30geoSize,'ha');