# For most use cases in this module, numpy is indistinguishable # from math, except it also works on numpy arrays except ImportError: import math as mathlib use_numpy = False
return lower <= mathlib.min(x) and mathlib.max(x) < upper return lower <= x < upper return lower <= x <= upper
if not 1 <= zone_number <= 60: raise OutOfRangeError('zone number out of range (must be between 1 and 60)')
if zone_letter: zone_letter = zone_letter.upper()
if not 'C' <= zone_letter <= 'X' or zone_letter in ['I', 'O']: raise OutOfRangeError('zone letter out of range (must be between C and X)')
return x < 0
"""Returns angle in radians to be between -pi and pi"""
"""This function converts UTM coordinates to Latitude and Longitude
Parameters ---------- easting: int or NumPy array Easting value of UTM coordinates
northing: int or NumPy array Northing value of UTM coordinates
zone_number: int Zone number is represented with global map numbers of a UTM zone numbers map. For more information see utmzones [1]_
zone_letter: str Zone letter can be represented as string values. UTM zone designators can be seen in [1]_
northern: bool You can set True or False to set this parameter. Default is None
strict: bool Raise an OutOfRangeError if outside of bounds
Returns ------- latitude: float or NumPy array Latitude between 80 deg S and 84 deg N, e.g. (-80.0 to 84.0)
longitude: float or NumPy array Longitude between 180 deg W and 180 deg E, e.g. (-180.0 to 180.0).
.. _[1]: http://www.jaworski.ca/utmzones.htm
""" if not zone_letter and northern is None: raise ValueError('either zone_letter or northern needs to be set')
elif zone_letter and northern is not None: raise ValueError('set either zone_letter or northern, but not both')
if strict: if not in_bounds(easting, 100000, 1000000, upper_strict=True): raise OutOfRangeError('easting out of range (must be between 100,000 m and 999,999 m)') if not in_bounds(northing, 0, 10000000): raise OutOfRangeError('northing out of range (must be between 0 m and 10,000,000 m)')
check_valid_zone(zone_number, zone_letter)
if zone_letter: zone_letter = zone_letter.upper() northern = (zone_letter >= 'N')
x = easting - 500000 y = northing
if not northern: y -= 10000000
m = y / K0 mu = m / (R * M1)
p_rad = (mu + P2 * mathlib.sin(2 * mu) + P3 * mathlib.sin(4 * mu) + P4 * mathlib.sin(6 * mu) + P5 * mathlib.sin(8 * mu))
p_sin = mathlib.sin(p_rad) p_sin2 = p_sin * p_sin
p_cos = mathlib.cos(p_rad)
p_tan = p_sin / p_cos p_tan2 = p_tan * p_tan p_tan4 = p_tan2 * p_tan2
ep_sin = 1 - E * p_sin2 ep_sin_sqrt = mathlib.sqrt(1 - E * p_sin2)
n = R / ep_sin_sqrt r = (1 - E) / ep_sin
c = E_P2 * p_cos**2 c2 = c * c
d = x / (n * K0) d2 = d * d d3 = d2 * d d4 = d3 * d d5 = d4 * d d6 = d5 * d
latitude = (p_rad - (p_tan / r) * (d2 / 2 - d4 / 24 * (5 + 3 * p_tan2 + 10 * c - 4 * c2 - 9 * E_P2)) + d6 / 720 * (61 + 90 * p_tan2 + 298 * c + 45 * p_tan4 - 252 * E_P2 - 3 * c2))
longitude = (d - d3 / 6 * (1 + 2 * p_tan2 + c) + d5 / 120 * (5 - 2 * c + 28 * p_tan2 - 3 * c2 + 8 * E_P2 + 24 * p_tan4)) / p_cos
longitude = mod_angle(longitude + mathlib.radians(zone_number_to_central_longitude(zone_number)))
return (mathlib.degrees(latitude), mathlib.degrees(longitude))
"""This function converts Latitude and Longitude to UTM coordinate
Parameters ---------- latitude: float or NumPy array Latitude between 80 deg S and 84 deg N, e.g. (-80.0 to 84.0)
longitude: float or NumPy array Longitude between 180 deg W and 180 deg E, e.g. (-180.0 to 180.0).
force_zone_number: int Zone number is represented by global map numbers of an UTM zone numbers map. You may force conversion to be included within one UTM zone number. For more information see utmzones [1]_
force_zone_letter: str You may force conversion to be included within one UTM zone letter. For more information see utmzones [1]_
Returns ------- easting: float or NumPy array Easting value of UTM coordinates
northing: float or NumPy array Northing value of UTM coordinates
zone_number: int Zone number is represented by global map numbers of a UTM zone numbers map. More information see utmzones [1]_
zone_letter: str Zone letter is represented by a string value. UTM zone designators can be accessed in [1]_
.. _[1]: http://www.jaworski.ca/utmzones.htm """ raise OutOfRangeError('latitude out of range (must be between 80 deg S and 84 deg N)') raise OutOfRangeError('longitude out of range (must be between 180 deg W and 180 deg E)') check_valid_zone(force_zone_number, force_zone_letter)
else: zone_number = force_zone_number
else: zone_letter = force_zone_letter
M2 * mathlib.sin(2 * lat_rad) + M3 * mathlib.sin(4 * lat_rad) - M4 * mathlib.sin(6 * lat_rad))
a3 / 6 * (1 - lat_tan2 + c) + a5 / 120 * (5 - 18 * lat_tan2 + lat_tan4 + 72 * c - 58 * E_P2)) + 500000
a4 / 24 * (5 - lat_tan2 + 9 * c + 4 * c**2) + a6 / 720 * (61 - 58 * lat_tan2 + lat_tan4 + 600 * c - 330 * E_P2)))
raise ValueError("latitudes must all have the same sign") northing += 10000000
# If the input is a numpy array, just use the first element # User responsibility to make sure that all points are in one zone latitude = latitude.flat[0]
else: return None
# If the input is a numpy array, just use the first element # User responsibility to make sure that all points are in one zone latitude = latitude.flat[0] longitude = longitude.flat[0]
return 32
if longitude < 9: return 31 elif longitude < 21: return 33 elif longitude < 33: return 35 elif longitude < 42: return 37
|