|
1 from ctypes import c_char_p, c_int, c_void_p, POINTER |
|
2 from django.contrib.gis.gdal.libgdal import lgdal, std_call |
|
3 from django.contrib.gis.gdal.prototypes.generation import \ |
|
4 const_string_output, double_output, int_output, \ |
|
5 srs_output, string_output, void_output |
|
6 |
|
7 ## Shortcut generation for routines with known parameters. |
|
8 def srs_double(f): |
|
9 """ |
|
10 Creates a function prototype for the OSR routines that take |
|
11 the OSRSpatialReference object and |
|
12 """ |
|
13 return double_output(f, [c_void_p, POINTER(c_int)], errcheck=True) |
|
14 |
|
15 def units_func(f): |
|
16 """ |
|
17 Creates a ctypes function prototype for OSR units functions, e.g., |
|
18 OSRGetAngularUnits, OSRGetLinearUnits. |
|
19 """ |
|
20 return double_output(f, [c_void_p, POINTER(c_char_p)], strarg=True) |
|
21 |
|
22 # Creation & destruction. |
|
23 clone_srs = srs_output(std_call('OSRClone'), [c_void_p]) |
|
24 new_srs = srs_output(std_call('OSRNewSpatialReference'), [c_char_p]) |
|
25 release_srs = void_output(lgdal.OSRRelease, [c_void_p], errcheck=False) |
|
26 destroy_srs = void_output(std_call('OSRDestroySpatialReference'), [c_void_p], errcheck=False) |
|
27 srs_validate = void_output(lgdal.OSRValidate, [c_void_p]) |
|
28 |
|
29 # Getting the semi_major, semi_minor, and flattening functions. |
|
30 semi_major = srs_double(lgdal.OSRGetSemiMajor) |
|
31 semi_minor = srs_double(lgdal.OSRGetSemiMinor) |
|
32 invflattening = srs_double(lgdal.OSRGetInvFlattening) |
|
33 |
|
34 # WKT, PROJ, EPSG, XML importation routines. |
|
35 from_wkt = void_output(lgdal.OSRImportFromWkt, [c_void_p, POINTER(c_char_p)]) |
|
36 from_proj = void_output(lgdal.OSRImportFromProj4, [c_void_p, c_char_p]) |
|
37 from_epsg = void_output(std_call('OSRImportFromEPSG'), [c_void_p, c_int]) |
|
38 from_xml = void_output(lgdal.OSRImportFromXML, [c_void_p, c_char_p]) |
|
39 |
|
40 # Morphing to/from ESRI WKT. |
|
41 morph_to_esri = void_output(lgdal.OSRMorphToESRI, [c_void_p]) |
|
42 morph_from_esri = void_output(lgdal.OSRMorphFromESRI, [c_void_p]) |
|
43 |
|
44 # Identifying the EPSG |
|
45 identify_epsg = void_output(lgdal.OSRAutoIdentifyEPSG, [c_void_p]) |
|
46 |
|
47 # Getting the angular_units, linear_units functions |
|
48 linear_units = units_func(lgdal.OSRGetLinearUnits) |
|
49 angular_units = units_func(lgdal.OSRGetAngularUnits) |
|
50 |
|
51 # For exporting to WKT, PROJ.4, "Pretty" WKT, and XML. |
|
52 to_wkt = string_output(std_call('OSRExportToWkt'), [c_void_p, POINTER(c_char_p)]) |
|
53 to_proj = string_output(std_call('OSRExportToProj4'), [c_void_p, POINTER(c_char_p)]) |
|
54 to_pretty_wkt = string_output(std_call('OSRExportToPrettyWkt'), [c_void_p, POINTER(c_char_p), c_int], offset=-2) |
|
55 |
|
56 # Memory leak fixed in GDAL 1.5; still exists in 1.4. |
|
57 to_xml = string_output(lgdal.OSRExportToXML, [c_void_p, POINTER(c_char_p), c_char_p], offset=-2) |
|
58 |
|
59 # String attribute retrival routines. |
|
60 get_attr_value = const_string_output(std_call('OSRGetAttrValue'), [c_void_p, c_char_p, c_int]) |
|
61 get_auth_name = const_string_output(lgdal.OSRGetAuthorityName, [c_void_p, c_char_p]) |
|
62 get_auth_code = const_string_output(lgdal.OSRGetAuthorityCode, [c_void_p, c_char_p]) |
|
63 |
|
64 # SRS Properties |
|
65 isgeographic = int_output(lgdal.OSRIsGeographic, [c_void_p]) |
|
66 islocal = int_output(lgdal.OSRIsLocal, [c_void_p]) |
|
67 isprojected = int_output(lgdal.OSRIsProjected, [c_void_p]) |
|
68 |
|
69 # Coordinate transformation |
|
70 new_ct= srs_output(std_call('OCTNewCoordinateTransformation'), [c_void_p, c_void_p]) |
|
71 destroy_ct = void_output(std_call('OCTDestroyCoordinateTransformation'), [c_void_p], errcheck=False) |