[GIS] Calculate total area of umnasked pixels of a raster image in Google Earth Engine

geoprocessinggoogle-earth-engineraster

I have a partially masked image, and my goal it to compute an area of all unmasked pixels. The way how they describe process of area calculation in this example is by using a vector mask.

So do I have to vectorise all those unmasked pixels and then calculate an area of the raster within that vector, or is there an easier way?

var alos_dem = ee.Image("JAXA/ALOS/AW3D30_V1_1"),
    imageVisParam = {"opacity":1,"bands":["AVE_MSK"],"max":8,"gamma":1};

// Get the target layer
var alos_ave = alos_dem.select('AVE_MSK');
// Select only pixels with value 1
var alos_mask_cond = alos_ave.eq(1);
// Mask out all other values
var alos_mask = alos_mask_cond.updateMask(alos_mask_cond);

// calculate area in square meters here

Best Answer

Your image is unbounded, so you have to specify some region (as geometry), but that region does not have to be exactly the area that you want to measure. Masked pixels within the region won't be counted, so if you apply the mask you have to the pixelArea image you will get the area value you're looking for — or rather, the portion of it that falls within within the given region.

var maskedArea = ee.Image.pixelArea().mask(alos_mask_cond);
print(maskedArea.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: /* insert appropriate region */,
  scale: /* insert appropriate scale */
}).get('area'));
Related Question