2008-08-06 02:13:06 +08:00
|
|
|
"""
|
2014-12-18 05:00:05 +08:00
|
|
|
This module houses the GDAL & SRS Exception objects, and the
|
2008-08-06 02:13:06 +08:00
|
|
|
check_err() routine which checks the status code returned by
|
2014-12-18 05:00:05 +08:00
|
|
|
GDAL/OGR methods.
|
2008-08-06 02:13:06 +08:00
|
|
|
"""
|
2013-11-03 01:18:46 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2015-02-06 02:25:34 +08:00
|
|
|
# #### GDAL & SRS Exceptions ####
|
2013-10-17 16:17:41 +08:00
|
|
|
class GDALException(Exception):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 01:18:46 +08:00
|
|
|
|
2013-10-17 16:17:41 +08:00
|
|
|
class SRSException(Exception):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 01:18:46 +08:00
|
|
|
|
2015-02-06 02:25:34 +08:00
|
|
|
# #### GDAL/OGR error checking codes and routine ####
|
2008-08-06 02:13:06 +08:00
|
|
|
|
|
|
|
# OGR Error Codes
|
2013-10-15 03:13:14 +08:00
|
|
|
OGRERR_DICT = {
|
2014-12-18 05:00:05 +08:00
|
|
|
1: (GDALException, 'Not enough data.'),
|
|
|
|
2: (GDALException, 'Not enough memory.'),
|
|
|
|
3: (GDALException, 'Unsupported geometry type.'),
|
|
|
|
4: (GDALException, 'Unsupported operation.'),
|
|
|
|
5: (GDALException, 'Corrupt data.'),
|
|
|
|
6: (GDALException, 'OGR failure.'),
|
2013-10-15 03:13:14 +08:00
|
|
|
7: (SRSException, 'Unsupported SRS.'),
|
2014-12-18 05:00:05 +08:00
|
|
|
8: (GDALException, 'Invalid handle.'),
|
2013-10-15 03:13:14 +08:00
|
|
|
}
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2014-12-02 01:34:50 +08:00
|
|
|
# CPL Error Codes
|
2018-09-26 14:48:47 +08:00
|
|
|
# https://www.gdal.org/cpl__error_8h.html
|
2014-12-02 01:34:50 +08:00
|
|
|
CPLERR_DICT = {
|
|
|
|
1: (GDALException, 'AppDefined'),
|
|
|
|
2: (GDALException, 'OutOfMemory'),
|
|
|
|
3: (GDALException, 'FileIO'),
|
|
|
|
4: (GDALException, 'OpenFailed'),
|
|
|
|
5: (GDALException, 'IllegalArg'),
|
|
|
|
6: (GDALException, 'NotSupported'),
|
|
|
|
7: (GDALException, 'AssertionFailed'),
|
|
|
|
8: (GDALException, 'NoWriteAccess'),
|
|
|
|
9: (GDALException, 'UserInterrupt'),
|
|
|
|
10: (GDALException, 'ObjectNull'),
|
|
|
|
}
|
2014-12-18 05:00:05 +08:00
|
|
|
|
|
|
|
ERR_NONE = 0
|
2014-12-02 01:34:50 +08:00
|
|
|
|
2013-11-03 01:18:46 +08:00
|
|
|
|
2014-12-02 01:34:50 +08:00
|
|
|
def check_err(code, cpl=False):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Check the given CPL/OGRERR and raise an exception where appropriate.
|
2014-12-02 01:34:50 +08:00
|
|
|
"""
|
|
|
|
err_dict = CPLERR_DICT if cpl else OGRERR_DICT
|
2013-10-11 04:42:30 +08:00
|
|
|
|
2014-12-18 05:00:05 +08:00
|
|
|
if code == ERR_NONE:
|
2008-08-06 02:13:06 +08:00
|
|
|
return
|
2014-12-02 01:34:50 +08:00
|
|
|
elif code in err_dict:
|
|
|
|
e, msg = err_dict[code]
|
2011-03-15 07:00:03 +08:00
|
|
|
raise e(msg)
|
2008-08-06 02:13:06 +08:00
|
|
|
else:
|
2014-12-02 01:34:50 +08:00
|
|
|
raise GDALException('Unknown error code: "%s"' % code)
|