|
1 """ |
|
2 This module houses the OGR & SRS Exception objects, and the |
|
3 check_err() routine which checks the status code returned by |
|
4 OGR methods. |
|
5 """ |
|
6 #### OGR & SRS Exceptions #### |
|
7 class GDALException(Exception): pass |
|
8 class OGRException(Exception): pass |
|
9 class SRSException(Exception): pass |
|
10 class OGRIndexError(OGRException, KeyError): |
|
11 """ |
|
12 This exception is raised when an invalid index is encountered, and has |
|
13 the 'silent_variable_feature' attribute set to true. This ensures that |
|
14 django's templates proceed to use the next lookup type gracefully when |
|
15 an Exception is raised. Fixes ticket #4740. |
|
16 """ |
|
17 silent_variable_failure = True |
|
18 |
|
19 #### OGR error checking codes and routine #### |
|
20 |
|
21 # OGR Error Codes |
|
22 OGRERR_DICT = { 1 : (OGRException, 'Not enough data.'), |
|
23 2 : (OGRException, 'Not enough memory.'), |
|
24 3 : (OGRException, 'Unsupported geometry type.'), |
|
25 4 : (OGRException, 'Unsupported operation.'), |
|
26 5 : (OGRException, 'Corrupt data.'), |
|
27 6 : (OGRException, 'OGR failure.'), |
|
28 7 : (SRSException, 'Unsupported SRS.'), |
|
29 8 : (OGRException, 'Invalid handle.'), |
|
30 } |
|
31 OGRERR_NONE = 0 |
|
32 |
|
33 def check_err(code): |
|
34 "Checks the given OGRERR, and raises an exception where appropriate." |
|
35 |
|
36 if code == OGRERR_NONE: |
|
37 return |
|
38 elif code in OGRERR_DICT: |
|
39 e, msg = OGRERR_DICT[code] |
|
40 raise e, msg |
|
41 else: |
|
42 raise OGRException('Unknown error code: "%s"' % code) |