1
1
import atexit , os , re , sys
2
2
import ctypes
3
3
from ctypes .util import find_library
4
-
5
- import ctypes
4
+ import sysconfig
6
5
import math
7
6
8
7
class RTreeError (Exception ):
9
8
"RTree exception, indicates a RTree-related error."
10
9
pass
11
-
10
+
12
11
if os .name == 'nt' :
13
12
try :
14
13
local_dlls = sys .path
@@ -29,7 +28,11 @@ def free(m):
29
28
raise
30
29
elif os .name == 'posix' :
31
30
platform = os .uname ()[0 ]
32
- lib_name = 'libmgrs.so'
31
+ soabi = sysconfig .get_config_var ('SOABI' )
32
+ if soabi :
33
+ lib_name = 'libmgrs.{}.so' .format (soabi )
34
+ else :
35
+ lib_name = 'libmgrs.so'
33
36
local_library_path = os .path .abspath (os .path .dirname (__file__ ) + "/.." )
34
37
free = ctypes .CDLL (find_library ('c' )).free
35
38
rt = ctypes .CDLL (os .path .join (local_library_path , lib_name ))
@@ -54,7 +57,7 @@ def get_errors(value):
54
57
if key & value :
55
58
output += errors [key ] + " & "
56
59
return output [:- 2 ]
57
-
60
+
58
61
def TO_RADIANS (degrees ):
59
62
return (float (degrees ) * math .pi / 180.0 )
60
63
@@ -76,33 +79,33 @@ def check_error(result, func, cargs):
76
79
# char *MGRS);
77
80
# /*
78
81
# * The function Convert_Geodetic_To_MGRS converts geodetic (latitude and
79
- # * longitude) coordinates to an MGRS coordinate string, according to the
80
- # * current ellipsoid parameters. If any errors occur, the error code(s)
82
+ # * longitude) coordinates to an MGRS coordinate string, according to the
83
+ # * current ellipsoid parameters. If any errors occur, the error code(s)
81
84
# * are returned by the function, otherwise MGRS_NO_ERROR is returned.
82
85
# *
83
86
# * Latitude : Latitude in radians (input)
84
87
# * Longitude : Longitude in radians (input)
85
88
# * Precision : Precision level of MGRS string (input)
86
89
# * MGRS : MGRS coordinate string (output)
87
- # *
90
+ # *
88
91
# */
89
92
90
- rt .Convert_Geodetic_To_MGRS .argtypes = [ctypes .c_double , ctypes .c_double , ctypes .c_long , ctypes .c_char_p ]
93
+ rt .Convert_Geodetic_To_MGRS .argtypes = [ctypes .c_double , ctypes .c_double , ctypes .c_long , ctypes .c_char_p ]
91
94
rt .Convert_Geodetic_To_MGRS .restype = ctypes .c_long
92
95
rt .Convert_Geodetic_To_MGRS .errcheck = check_error
93
96
94
- #
97
+ #
95
98
# /*
96
99
# * This function converts an MGRS coordinate string to Geodetic (latitude
97
- # * and longitude in radians) coordinates. If any errors occur, the error
98
- # * code(s) are returned by the function, otherwise MGRS_NO_ERROR is returned.
100
+ # * and longitude in radians) coordinates. If any errors occur, the error
101
+ # * code(s) are returned by the function, otherwise MGRS_NO_ERROR is returned.
99
102
# *
100
103
# * MGRS : MGRS coordinate string (input)
101
104
# * Latitude : Latitude in radians (output)
102
105
# * Longitude : Longitude in radians (output)
103
- # *
106
+ # *
104
107
# */
105
- #
108
+ #
106
109
107
110
rt .Convert_MGRS_To_Geodetic .argtypes = [ctypes .c_char_p , ctypes .POINTER (ctypes .c_double ), ctypes .POINTER (ctypes .c_double )]
108
111
rt .Convert_MGRS_To_Geodetic .restype = ctypes .c_long
@@ -111,8 +114,8 @@ def check_error(result, func, cargs):
111
114
112
115
# /*
113
116
# * The function Convert_UTM_To_MGRS converts UTM (zone, easting, and
114
- # * northing) coordinates to an MGRS coordinate string, according to the
115
- # * current ellipsoid parameters. If any errors occur, the error code(s)
117
+ # * northing) coordinates to an MGRS coordinate string, according to the
118
+ # * current ellipsoid parameters. If any errors occur, the error code(s)
116
119
# * are returned by the function, otherwise MGRS_NO_ERROR is returned.
117
120
# *
118
121
# * Zone : UTM zone (input)
@@ -129,9 +132,9 @@ def check_error(result, func, cargs):
129
132
130
133
# /*
131
134
# * The function Convert_MGRS_To_UTM converts an MGRS coordinate string
132
- # * to UTM projection (zone, hemisphere, easting and northing) coordinates
133
- # * according to the current ellipsoid parameters. If any errors occur,
134
- # * the error code(s) are returned by the function, otherwise UTM_NO_ERROR
135
+ # * to UTM projection (zone, hemisphere, easting and northing) coordinates
136
+ # * according to the current ellipsoid parameters. If any errors occur,
137
+ # * the error code(s) are returned by the function, otherwise UTM_NO_ERROR
135
138
# * is returned.
136
139
# *
137
140
# * MGRS : MGRS coordinate string (input)
@@ -143,4 +146,4 @@ def check_error(result, func, cargs):
143
146
144
147
rt .Convert_MGRS_To_UTM .argtype = [ctypes .c_char_p , ctypes .POINTER (ctypes .c_long ), ctypes .POINTER (ctypes .c_char ), ctypes .POINTER (ctypes .c_double ), ctypes .POINTER (ctypes .c_double )]
145
148
rt .Convert_MGRS_To_UTM .restype = ctypes .c_long
146
- rt .Convert_MGRS_To_UTM .errcheck = check_error
149
+ rt .Convert_MGRS_To_UTM .errcheck = check_error
0 commit comments