2008-08-06 02:13:06 +08:00
|
|
|
"""
|
|
|
|
This module houses the OGR & SRS Exception objects, and the
|
|
|
|
check_err() routine which checks the status code returned by
|
|
|
|
OGR methods.
|
|
|
|
"""
|
2013-11-03 01:18:46 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2008-08-06 02:13:06 +08:00
|
|
|
#### OGR & 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 OGRException(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
|
|
|
|
2008-08-06 02:13:06 +08:00
|
|
|
class OGRIndexError(OGRException, KeyError):
|
|
|
|
"""
|
|
|
|
This exception is raised when an invalid index is encountered, and has
|
|
|
|
the 'silent_variable_feature' attribute set to true. This ensures that
|
|
|
|
django's templates proceed to use the next lookup type gracefully when
|
|
|
|
an Exception is raised. Fixes ticket #4740.
|
|
|
|
"""
|
|
|
|
silent_variable_failure = True
|
|
|
|
|
|
|
|
#### OGR error checking codes and routine ####
|
|
|
|
|
|
|
|
# OGR Error Codes
|
2013-10-15 03:13:14 +08:00
|
|
|
OGRERR_DICT = {
|
|
|
|
1: (OGRException, 'Not enough data.'),
|
|
|
|
2: (OGRException, 'Not enough memory.'),
|
|
|
|
3: (OGRException, 'Unsupported geometry type.'),
|
|
|
|
4: (OGRException, 'Unsupported operation.'),
|
|
|
|
5: (OGRException, 'Corrupt data.'),
|
|
|
|
6: (OGRException, 'OGR failure.'),
|
|
|
|
7: (SRSException, 'Unsupported SRS.'),
|
|
|
|
8: (OGRException, 'Invalid handle.'),
|
|
|
|
}
|
2008-08-06 02:13:06 +08:00
|
|
|
OGRERR_NONE = 0
|
|
|
|
|
2014-12-02 01:34:50 +08:00
|
|
|
# CPL Error Codes
|
|
|
|
# http://www.gdal.org/cpl__error_8h.html
|
|
|
|
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'),
|
|
|
|
}
|
|
|
|
CPLERR_NONE = 0
|
|
|
|
|
2013-11-03 01:18:46 +08:00
|
|
|
|
2014-12-02 01:34:50 +08:00
|
|
|
def check_err(code, cpl=False):
|
|
|
|
"""
|
|
|
|
Checks the given CPL/OGRERR, and raises an exception where appropriate.
|
|
|
|
"""
|
|
|
|
err_none = CPLERR_NONE if cpl else OGRERR_NONE
|
|
|
|
err_dict = CPLERR_DICT if cpl else OGRERR_DICT
|
2013-10-11 04:42:30 +08:00
|
|
|
|
2014-12-02 01:34:50 +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)
|