exactextract
exactextract copied to clipboard
Add functionality to convert nodata to a fixed value
Many population datasets use NODATA
pixels for areas outside the modeled domain, e.g. ocean pixels. For the purpose of exactextract
these should be considered equivalent to zero.
The following workaround is available in Python using GDAL:
from osgeo import gdal
gdal.BuildVRT('/vsimem/vrt1.vrt', "my_pop_data.tif", VRTNodata = 0)
pop_src = gdal.BuildVRT('', '/vsimem/vrt1.vrt', srcNodata = "none")
This is not clear in its intent and easy to get wrong. As an alternative, the exactextractr package uses default_weight
and default_value
arguments to convert NODATA into a constant value.
Similar functionality could be added to exactextract, either by:
- modifying
Raster
to have adefault_value
argument. This would require that allRasterSource
implementations in turn accept such a value, and pass it along when constructingRaster
objects. - modifying
RasterStats
to take appropriate arguments, so you could call e.g.weighted_mean(default_weight=0)
. This would be automatically exposed in both the Python bindings and the CLI and would avoid the need to modifyRasterSource
implementations.