Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how libmgrs.so is imported if installing with Python 3.5. #10

Merged
merged 2 commits into from
Apr 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions mgrs/core.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import atexit, os, re, sys
import ctypes
from ctypes.util import find_library

import ctypes
import sysconfig
import math

class RTreeError(Exception):
"RTree exception, indicates a RTree-related error."
pass

if os.name == 'nt':
lib_name = 'libmgrs.dll'
try:
Expand All @@ -25,7 +24,11 @@ def free(m):
raise
elif os.name == 'posix':
platform = os.uname()[0]
lib_name = 'libmgrs.so'
soabi = sysconfig.get_config_var('SOABI')
if soabi:
lib_name = 'libmgrs.{}.so'.format(soabi)
else:
lib_name = 'libmgrs.so'
local_library_path = os.path.abspath(os.path.dirname(__file__) + "/..")
free = ctypes.CDLL(find_library('c')).free
rt = ctypes.CDLL(os.path.join(local_library_path, lib_name))
Expand All @@ -50,7 +53,7 @@ def get_errors(value):
if key & value:
output += errors[key] + " & "
return output[:-2]

def TO_RADIANS(degrees):
return (float(degrees) * math.pi/180.0)

Expand All @@ -72,33 +75,33 @@ def check_error(result, func, cargs):
# char *MGRS);
# /*
# * The function Convert_Geodetic_To_MGRS converts geodetic (latitude and
# * longitude) coordinates to an MGRS coordinate string, according to the
# * current ellipsoid parameters. If any errors occur, the error code(s)
# * longitude) coordinates to an MGRS coordinate string, according to the
# * current ellipsoid parameters. If any errors occur, the error code(s)
# * are returned by the function, otherwise MGRS_NO_ERROR is returned.
# *
# * Latitude : Latitude in radians (input)
# * Longitude : Longitude in radians (input)
# * Precision : Precision level of MGRS string (input)
# * MGRS : MGRS coordinate string (output)
# *
# *
# */

rt.Convert_Geodetic_To_MGRS.argtypes = [ctypes.c_double, ctypes.c_double, ctypes.c_long, ctypes.c_char_p]
rt.Convert_Geodetic_To_MGRS.argtypes = [ctypes.c_double, ctypes.c_double, ctypes.c_long, ctypes.c_char_p]
rt.Convert_Geodetic_To_MGRS.restype = ctypes.c_long
rt.Convert_Geodetic_To_MGRS.errcheck = check_error

#
#
# /*
# * This function converts an MGRS coordinate string to Geodetic (latitude
# * and longitude in radians) coordinates. If any errors occur, the error
# * code(s) are returned by the function, otherwise MGRS_NO_ERROR is returned.
# * and longitude in radians) coordinates. If any errors occur, the error
# * code(s) are returned by the function, otherwise MGRS_NO_ERROR is returned.
# *
# * MGRS : MGRS coordinate string (input)
# * Latitude : Latitude in radians (output)
# * Longitude : Longitude in radians (output)
# *
# *
# */
#
#

rt.Convert_MGRS_To_Geodetic.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double)]
rt.Convert_MGRS_To_Geodetic.restype = ctypes.c_long
Expand All @@ -107,8 +110,8 @@ def check_error(result, func, cargs):

# /*
# * The function Convert_UTM_To_MGRS converts UTM (zone, easting, and
# * northing) coordinates to an MGRS coordinate string, according to the
# * current ellipsoid parameters. If any errors occur, the error code(s)
# * northing) coordinates to an MGRS coordinate string, according to the
# * current ellipsoid parameters. If any errors occur, the error code(s)
# * are returned by the function, otherwise MGRS_NO_ERROR is returned.
# *
# * Zone : UTM zone (input)
Expand All @@ -125,9 +128,9 @@ def check_error(result, func, cargs):

# /*
# * The function Convert_MGRS_To_UTM converts an MGRS coordinate string
# * to UTM projection (zone, hemisphere, easting and northing) coordinates
# * according to the current ellipsoid parameters. If any errors occur,
# * the error code(s) are returned by the function, otherwise UTM_NO_ERROR
# * to UTM projection (zone, hemisphere, easting and northing) coordinates
# * according to the current ellipsoid parameters. If any errors occur,
# * the error code(s) are returned by the function, otherwise UTM_NO_ERROR
# * is returned.
# *
# * MGRS : MGRS coordinate string (input)
Expand All @@ -139,4 +142,4 @@ def check_error(result, func, cargs):

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)]
rt.Convert_MGRS_To_UTM.restype = ctypes.c_long
rt.Convert_MGRS_To_UTM.errcheck = check_error
rt.Convert_MGRS_To_UTM.errcheck = check_error