| 1 |
""" |
| 2 |
This module houses the GDAL & SRS Exception objects, and the |
| 3 |
check_err() routine which checks the status code returned by |
| 4 |
GDAL/OGR methods. |
| 5 |
""" |
| 6 |
|
| 7 |
|
| 8 |
# #### GDAL & SRS Exceptions #### |
| 9 |
class GDALException(Exception): |
| 10 |
pass |
| 11 |
|
| 12 |
|
| 13 |
class SRSException(Exception): |
| 14 |
pass |
| 15 |
|
| 16 |
|
| 17 |
# #### GDAL/OGR error checking codes and routine #### |
| 18 |
|
| 19 |
# OGR Error Codes |
| 20 |
OGRERR_DICT = { |
| 21 |
1: (GDALException, "Not enough data."), |
| 22 |
2: (GDALException, "Not enough memory."), |
| 23 |
3: (GDALException, "Unsupported geometry type."), |
| 24 |
4: (GDALException, "Unsupported operation."), |
| 25 |
5: (GDALException, "Corrupt data."), |
| 26 |
6: (GDALException, "OGR failure."), |
| 27 |
7: (SRSException, "Unsupported SRS."), |
| 28 |
8: (GDALException, "Invalid handle."), |
| 29 |
} |
| 30 |
|
| 31 |
# CPL Error Codes |
| 32 |
# https://gdal.org/api/cpl.html#cpl-error-h |
| 33 |
CPLERR_DICT = { |
| 34 |
1: (GDALException, "AppDefined"), |
| 35 |
2: (GDALException, "OutOfMemory"), |
| 36 |
3: (GDALException, "FileIO"), |
| 37 |
4: (GDALException, "OpenFailed"), |
| 38 |
5: (GDALException, "IllegalArg"), |
| 39 |
6: (GDALException, "NotSupported"), |
| 40 |
7: (GDALException, "AssertionFailed"), |
| 41 |
8: (GDALException, "NoWriteAccess"), |
| 42 |
9: (GDALException, "UserInterrupt"), |
| 43 |
10: (GDALException, "ObjectNull"), |
| 44 |
} |
| 45 |
|
| 46 |
ERR_NONE = 0 |
| 47 |
|
| 48 |
|
| 49 |
def check_err(code, cpl=False): |
| 50 |
""" |
| 51 |
Check the given CPL/OGRERR and raise an exception where appropriate. |
| 52 |
""" |
| 53 |
err_dict = CPLERR_DICT if cpl else OGRERR_DICT |
| 54 |
|
| 55 |
if code == ERR_NONE: |
| 56 |
return |
| 57 |
elif code in err_dict: |
| 58 |
e, msg = err_dict[code] |
| 59 |
raise e(msg) |
| 60 |
else: |
| 61 |
raise GDALException('Unknown error code: "%s"' % code) |