Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDAL warp algorithm names missing with GDAL>=3.8.5 #387

Closed
emlys opened this issue Apr 9, 2024 · 0 comments · Fixed by #388
Closed

GDAL warp algorithm names missing with GDAL>=3.8.5 #387

emlys opened this issue Apr 9, 2024 · 0 comments · Fixed by #388
Labels
bug Something isn't working

Comments

@emlys
Copy link
Member

emlys commented Apr 9, 2024

GDAL 3.8.5 fixed a bug where the options list provided to gdal.WarpOptions was modified by the function call. pygeoprocessing was relying on this bug to get the warp algorithm name. We'll need to find another way to get _GDAL_WARP_ALGORITHMS.

_GDAL_WARP_ALGORITHMS = []
for _warp_algo in (_attrname for _attrname in dir(gdalconst)
if _attrname.startswith('GRA_')):
# In GDAL < 3.4, the options used were actually gdal.GRIORA_*
# instead of gdal.GRA_*, and gdal.WarpOptions would:
# * return an integer for any gdal.GRIORA options it didn't recognize
# * Return an abbreviated string (e.g. -rb instead of 'bilinear') for
# several warp algorithms
# This behavior was changed in GDAL 3.4, where the correct name is
# returned in all cases.
#
# In GDAL < 3.4, an error would be logged if GDAL couldn't recognize the
# option. Pushing a null error handler avoids this and cleans up the
# logging.
gdal.PushErrorHandler(lambda *args: None)
_options = []
# GDAL's python bindings only offer this one way of translating gdal.GRA_*
# options to their string names (but compatibility is limited in different
# GDAL versions, see notes above)
warp_opts = gdal.WarpOptions(
options=_options, # SIDE EFFECT: Adds flags to this list.
resampleAlg=getattr(gdalconst, _warp_algo), # use GRA_* name.
overviewLevel=None) # Don't add overview parameters.
gdal.PopErrorHandler()
# _options is populated during the WarpOptions call above.
for _item in _options:
is_int = False
try:
int(_item)
is_int = True
except ValueError:
pass
if _item == '-r':
continue
elif (_item.startswith('-r') and len(_item) > 2) or is_int:
# (GDAL < 3.4) Translate shorthand params to name.
# (GDAL < 3.4) Translate unrecognized (int) codes to name.
_item = re.sub('^gra_', '', _warp_algo.lower())
_GDAL_WARP_ALGORITHMS.append(_item)

@emlys emlys added the bug Something isn't working label Apr 9, 2024
emlys added a commit to emlys/pygeoprocessing that referenced this issue Apr 9, 2024
emlys added a commit to emlys/pygeoprocessing that referenced this issue Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant