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

Fixed mishandling of conversion to utm when forcing a zone letter #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 3 additions & 16 deletions utm/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,21 @@ def negative(x):

def to_latlon(easting, northing, zone_number, zone_letter=None, northern=None, strict=True):
"""This function convert an UTM coordinate into Latitude and Longitude

Parameters
----------
easting: int
Easting value of UTM coordinate

northing: int
Northing value of UTM coordinate

zone number: int
Zone Number is represented with global map numbers of an UTM Zone
Numbers Map. More information see utmzones [1]_

zone_letter: str
Zone Letter can be represented as string values. Where UTM Zone
Designators can be accessed in [1]_

northern: bool
You can set True or False to set this parameter. Default is None


.. _[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')
Expand Down Expand Up @@ -170,20 +162,16 @@ def to_latlon(easting, northing, zone_number, zone_letter=None, northern=None, s

def from_latlon(latitude, longitude, force_zone_number=None, force_zone_letter=None):
"""This function convert Latitude and Longitude to UTM coordinate

Parameters
----------
latitude: float
Latitude between 80 deg S and 84 deg N, e.g. (-80.0 to 84.0)

longitude: float
Longitude between 180 deg W and 180 deg E, e.g. (-180.0 to 180.0).

force_zone number: int
Zone Number is represented with global map numbers of an UTM Zone
Numbers Map. You may force conversion including one UTM Zone Number.
More information see utmzones [1]_

.. _[1]: http://www.jaworski.ca/utmzones.htm
"""
if not in_bounds(latitude, -80.0, 84.0):
Expand Down Expand Up @@ -237,15 +225,14 @@ def from_latlon(latitude, longitude, force_zone_number=None, force_zone_letter=N
northing = K0 * (m + n * lat_tan * (a2 / 2 +
a4 / 24 * (5 - lat_tan2 + 9 * c + 4 * c**2) +
a6 / 720 * (61 - 58 * lat_tan2 + lat_tan4 + 600 * c - 330 * E_P2)))

if mixed_signs(latitude):
raise ValueError("latitudes must all have the same sign")
elif negative(latitude):
elif zone_letter <= "M":
northing += 10000000

return easting, northing, zone_number, zone_letter


def latitude_to_zone_letter(latitude):
# If the input is a numpy array, just use the first element
# User responsibility to make sure that all points are in one zone
Expand Down