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

Rebase and tweaks to "Fix forcing zones around equator and add force_northern in from_latlon" #124

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 15 additions & 2 deletions test/test_utm.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,23 @@ def test_force_numpy(zone):
# Point above and below equator
lats = np.array([-0.1, 0.1])

result = UTM.from_latlon(lats, np.array([0, 0]), 31, zone)
with pytest.raises(ValueError,
match="latitudes must all have the same sign"):
UTM.from_latlon(lats, np.array([0, 0]), 31, zone)


@pytest.mark.skipif(not use_numpy, reason="numpy not installed")
@pytest.mark.parametrize("force_northern", (True, False))
def test_force_numpy_force_northern_true(force_northern):
# Point above and below equator
lats = np.array([-0.1, 0.1])

result = UTM.from_latlon(
lats, np.array([0, 0]), force_northern=force_northern)
for expected_lat, easting, northing in zip(lats, *result[:2]):
assert_equal_lat(
(easting, northing, result[2], result[3]), expected_lat)
(easting, northing, result[2], result[3]), expected_lat,
northern=force_northern)


def test_force_both():
Expand Down
9 changes: 7 additions & 2 deletions utm/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def check_valid_zone(zone_number, zone_letter):
raise OutOfRangeError('zone letter out of range (must be between C and X)')


def mixed_signs(x):
return use_numpy and mathlib.min(x) < 0 and mathlib.max(x) >= 0


def mod_angle(value):
"""Returns angle in radians to be between -pi and pi"""
return (value + mathlib.pi) % (2 * mathlib.pi) - mathlib.pi
Expand Down Expand Up @@ -107,7 +111,6 @@ def to_latlon(easting, northing, zone_number, zone_letter=None, northern=None, s
"""
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')

Expand Down Expand Up @@ -278,7 +281,9 @@ def from_latlon(latitude, longitude, force_zone_number=None, force_zone_letter=N
a4 / 24 * (5 - lat_tan2 + 9 * c + 4 * c**2) +
a6 / 720 * (61 - 58 * lat_tan2 + lat_tan4 + 600 * c - 330 * E_P2)))

if not northern:
if force_northern is None and mixed_signs(latitude):
heathhenley marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError("latitudes must all have the same sign")
elif not northern:
northing += 10000000

return easting, northing, zone_number, zone_letter
Expand Down