proposal/bugfix: Remove checks for gdal resampling algorithm values #388
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #387
This was pretty simple so I went ahead with it, but happy to consider alternatives too!
We were relying on a gdal bug to build a list of human-readable names for resampling algorithms. In gdal 3.8.5, this no longer works. We could implement a different way to get the names, but I propose that we remove the list entirely.
The lists in question (
_GDAL_WARP_ALGORITHMS
and_GDAL_WARP_ALGOS_FOR_HUMAN_EYES
) are used inwarp_raster
andbuild_overviews
. They're only used to check that the provided resampling algorithm is a valid option, and raise a helpful error message if not. I think we can do away with that because GDAL raises its own (slightly less helpful) error message if given an invalid algorithm name:gdal.WarpRaster
raises aTypeError: in method 'wrapper_GDALWarpDestName', argument 4 of type 'GDALWarpAppOptions *'
and prints outERROR 5: Unknown resampling method: <resampling method>.
Withgdal.UseExceptions()
, you get a nicerRuntimeError: Unknown resampling method: <resampling method>.
gdal.BuildOverviews
raises aRuntimeError: Building overviews failed or was interrupted for <raster path>.
and prints outERROR 1: GDALGetResampleFunction: Unsupported resampling method "<resampling_method>".
Withgdal.UseExceptions()
, you getRuntimeError: GDALGetResampleFunction: Unsupported resampling method "<resampling method>"
.These error messages aren't quite as nice as what
pygeoprocessing
had, but they're adequate to identify the issue. Since we pass the resample method argument directly to the underlying gdal function, I think it makes sense to let GDAL handle it.A couple of behavior changes:
gdal.WarpRaster
resample algorithm argument can be agdal.GRA_*
constant as well as a string name. By removing the pygeoprocessing check, we can acceptgdal.GRA_*
constants too.gdal.WarpRaster
andgdal.BuildOverviews
use the nearest neighbor algorithm if the resampling argument starts with 'near'. So 'near', 'nearest', 'nearest_neighbor', and 'near_foo' all work.