geemap
geemap copied to clipboard
Inconsistent use of gdal
Here https://github.com/gee-community/geemap/blob/9c990baa21d62337ead2c6a6fbd58e0a74038a6f/geemap/common.py#L10794
from osgeo import gdal
import rasterio
# ... and suppress errors
gdal.PushErrorHandler("CPLQuietErrorHandler")
Whereas here https://github.com/gee-community/geemap/blob/9c990baa21d62337ead2c6a6fbd58e0a74038a6f/geemap/common.py#L15128
try:
from osgeo import gdal, osr
except ImportError:
raise ImportError("GDAL is not installed. Install it with pip install GDAL")
# [SNIP]
gdal.UseExceptions()
- One of the importss is wrapped in a try, but the others are not. I suggest dropping the try/except wrapping.
- The
UseExceptions
is great as that will become the default behavior of GDAL in the future. I suggest always doing that right after the imports each time there is afrom osgeo import
- The
gdal.PushErrorHandler
calls are missing the matchinggdal.PopErrorHandler()
. You are welcome to use this context manager if it makes things easier. https://github.com/schwehr/gdal-autotest2/blob/577974592837fdfc18fd90b338cb657f1f2332bd/python/gcore/gcore_util.py#L50
@contextlib.contextmanager
def ErrorHandler(error_name):
handler = gdal.PushErrorHandler(error_name)
try:
yield handler
finally:
gdal.PopErrorHandler()
#1867 wasn't quite right. I will try to make a PR this week that does what I think was intended. Sorry that my explanation above wasn't clear.