本文整理汇总了Python中osgeo.gdal.PushErrorHandler方法的典型用法代码示例。如果您正苦于以下问题:Python gdal.PushErrorHandler方法的具体用法?Python gdal.PushErrorHandler怎么用?Python gdal.PushErrorHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osgeo.gdal
的用法示例。
在下文中一共展示了gdal.PushErrorHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from osgeo import gdal [as 别名]
# 或者: from osgeo.gdal import PushErrorHandler [as 别名]
def __call__(self, *args, **kwargs):
errs, res = None, None
def error_handler(err_level, err_no, err_msg):
nonlocal errs
if err_level >= gdal.CE_Failure:
errs = err_no, err_msg
gdal.PushErrorHandler(error_handler)
try:
res = self._fn(*args, **kwargs)
except Exception as e:
if errs is None:
# This is not a gdal error, this might be a swig error or something else
raise
else:
# This is a gdal error, and `gdal.GetUseExceptions()` is True
# Read problems from the `errs` variable, the details stored in this exception
# are not reliable.
pass
finally:
gdal.PopErrorHandler()
if errs:
return False, errs
if self._none_is_error and res is None:
return False, (0, str(gdal.GetLastErrorMsg()).strip('\n'))
if self._nonzero_int_is_error and isinstance(res, int) and res != 0:
return False, (res, conv.str_of_cple(res))
return True, res