Debian Codegraph @

django/contrib/gis/gdal/prototypes/srs.py

raw
1 from ctypes import POINTER, c_char_p, c_int, c_void_p
2
3 from django.contrib.gis.gdal.libgdal import lgdal, std_call
4 from django.contrib.gis.gdal.prototypes.generation import (
5 const_string_output,
6 double_output,
7 int_output,
8 srs_output,
9 string_output,
10 void_output,
11 )
12
13
14 # Shortcut generation for routines with known parameters.
15 def srs_double(f):
16 """
17 Create a function prototype for the OSR routines that take
18 the OSRSpatialReference object and return a double value.
19 """
20 return double_output(f, [c_void_p, POINTER(c_int)], errcheck=True)
21
22
23 def units_func(f):
24 """
25 Create a ctypes function prototype for OSR units functions, e.g.,
26 OSRGetAngularUnits, OSRGetLinearUnits.
27 """
28 return double_output(f, [c_void_p, POINTER(c_char_p)], strarg=True)
29
30
31 # Creation & destruction.
32 clone_srs = srs_output(std_call("OSRClone"), [c_void_p])
33 new_srs = srs_output(std_call("OSRNewSpatialReference"), [c_char_p])
34 release_srs = void_output(lgdal.OSRRelease, [c_void_p], errcheck=False)
35 destroy_srs = void_output(
36 std_call("OSRDestroySpatialReference"), [c_void_p], errcheck=False
37 )
38 srs_validate = void_output(lgdal.OSRValidate, [c_void_p])
39 set_axis_strategy = void_output(
40 lgdal.OSRSetAxisMappingStrategy, [c_void_p, c_int], errcheck=False
41 )
42
43 # Getting the semi_major, semi_minor, and flattening functions.
44 semi_major = srs_double(lgdal.OSRGetSemiMajor)
45 semi_minor = srs_double(lgdal.OSRGetSemiMinor)
46 invflattening = srs_double(lgdal.OSRGetInvFlattening)
47
48 # WKT, PROJ, EPSG, XML importation routines.
49 from_wkt = void_output(lgdal.OSRImportFromWkt, [c_void_p, POINTER(c_char_p)])
50 from_proj = void_output(lgdal.OSRImportFromProj4, [c_void_p, c_char_p])
51 from_epsg = void_output(std_call("OSRImportFromEPSG"), [c_void_p, c_int])
52 from_xml = void_output(lgdal.OSRImportFromXML, [c_void_p, c_char_p])
53 from_user_input = void_output(std_call("OSRSetFromUserInput"), [c_void_p, c_char_p])
54
55 # Morphing to/from ESRI WKT.
56 morph_to_esri = void_output(lgdal.OSRMorphToESRI, [c_void_p])
57 morph_from_esri = void_output(lgdal.OSRMorphFromESRI, [c_void_p])
58
59 # Identifying the EPSG
60 identify_epsg = void_output(lgdal.OSRAutoIdentifyEPSG, [c_void_p])
61
62 # Getting the angular_units, linear_units functions
63 linear_units = units_func(lgdal.OSRGetLinearUnits)
64 angular_units = units_func(lgdal.OSRGetAngularUnits)
65
66 # For exporting to WKT, PROJ, "Pretty" WKT, and XML.
67 to_wkt = string_output(
68 std_call("OSRExportToWkt"), [c_void_p, POINTER(c_char_p)], decoding="utf-8"
69 )
70 to_proj = string_output(
71 std_call("OSRExportToProj4"), [c_void_p, POINTER(c_char_p)], decoding="ascii"
72 )
73 to_pretty_wkt = string_output(
74 std_call("OSRExportToPrettyWkt"),
75 [c_void_p, POINTER(c_char_p), c_int],
76 offset=-2,
77 decoding="utf-8",
78 )
79
80 to_xml = string_output(
81 lgdal.OSRExportToXML,
82 [c_void_p, POINTER(c_char_p), c_char_p],
83 offset=-2,
84 decoding="utf-8",
85 )
86
87 # String attribute retrieval routines.
88 get_attr_value = const_string_output(
89 std_call("OSRGetAttrValue"), [c_void_p, c_char_p, c_int], decoding="utf-8"
90 )
91 get_auth_name = const_string_output(
92 lgdal.OSRGetAuthorityName, [c_void_p, c_char_p], decoding="ascii"
93 )
94 get_auth_code = const_string_output(
95 lgdal.OSRGetAuthorityCode, [c_void_p, c_char_p], decoding="ascii"
96 )
97
98 # SRS Properties
99 isgeographic = int_output(lgdal.OSRIsGeographic, [c_void_p])
100 islocal = int_output(lgdal.OSRIsLocal, [c_void_p])
101 isprojected = int_output(lgdal.OSRIsProjected, [c_void_p])
102
103 # Coordinate transformation
104 new_ct = srs_output(std_call("OCTNewCoordinateTransformation"), [c_void_p, c_void_p])
105 destroy_ct = void_output(
106 std_call("OCTDestroyCoordinateTransformation"), [c_void_p], errcheck=False
107 )