admin管理员组文章数量:1434904
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());
本文标签: javascriptCalculating percent coverage of 1000m raster by 30m rasterStack Overflow
版权声明:本文标题:javascript - Calculating percent coverage of 1000m raster by 30m raster - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745643706a2668008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论