Table of Contents
The answer to the above question really depends on how you decide which pixels are within the polygon and if so, do you consider them to be fully or partially inside. Different geospatial software account for these differently.
QGIS
QGIS considers only the pixels whose centroid is within the region and assigns a weight of 1 to these pixels and 0 to others. There is no support for partial pixels. Users need to vectorize the rasters and perform analysis in vector space if they need accurate weighted statistics. This may not be feasible for large rasters. Check this stackexchange post for more details.
Python
Popular packages such as rasterstats considers all pixels whose centroid is within the region as weight 1 and ignores others. rasterio is similar but has an option all_touched which includes all pixels that are touched by the region.
XVec is an XArray extension that makes it each to work with Vector data with XArray. It has an implementation of the exactextract algorithm that provides a fast and accurate statistcs by determining the fraction of each pixel that is covered by the polygon. We have a full example available in our Cloud Native Remote Sensing with Python course.
Google Earth Engine
The bottom line? The difference in the results is small when you are working with higher resolution rasters with small pixels but become significant when you are working with gridded rasters with large pixels. Understanding how your software deals with partial pixels will help you evaluate the high accuracy of your results.
Comments