I have two rasters, one of restoration opportunity at 1000m and one of deforestation from 2019-2023 at 30m (Global Forest Watch data). At the end of this, I want to determine how many pixels of restoration opportunity have over 50% coverage by deforestation in this time period. Right now, I am tackling “how do I calculate percent coverage of a coarser resolution raster by a finer resolution raster?”. See below for what I have tried which has resulted in two issues/questions.
- The reported coverage percents per polygon are plausible but strike me as a little small. How can I go about verifying these numbers are correct? Does this method seem sound?
- A more overarching issue is that adjacent pixels are aggregated together at the vectorizing stage. Ideally, I would calculate percent coverage per 1km pixel. Advice on how to achieve that in GEE?
General overview: I converted the 1km raster to polygons, got a pixel area raster of deforestation, created a function that sums up pixel area raster per polygon then divides that by polygon area, and map that over all the polygons. Function shown here, full code is available here
## Function to calculate fractional coverage for each polygon
var calculateCoverage = function(feature) {
// Clip raster to current polygon
var clippedImage = lossYear_2019_2023_area.clip(feature);
// Mask raster to include only the pixels inside the polygon
var imageMasked = clippedImage.updateMask(clippedImage.mask());
// Calculate the area of the polygon (in square meters)
var polygonArea = feature.area({maxError: 1e6}); // in square meters
// Sum up the pixels (area of deforestation) for the polygon
var coverageArea = imageMasked.reduceRegion({
reducer: ee.Reducer.sum(), // Sum of 30m area pixels that are in polygon
geometry: feature.geometry(),
scale: scale, // The resolution of the image (~30m per pixel)
maxPixels: 1e13
});
// Calculate the fractional coverage as a percentage
var fractionalCoverage = ee.Number(coverageArea.get('lossyear')).divide(polygonArea).multiply(100);
// Add the fractional coverage as a new property to the feature
return feature.set('fractionalCoverage', fractionalCoverage);
};
// Apply the function to each polygon in the FeatureCollection
var polygonsWithCoverage = opportunity_vectors.map(calculateCoverage);
// Print the result to check
print('Polygons with fractional coverage:', polygonsWithCoverage.first());