Whole file

Turbo87/utm

The author described this change as Fix issue near anti-meridian when forcing zones. It counts as a record because the check below fails on the code as it stood at 875f0de45 and passes on eeed1f1cc, with nothing else changed between the two runs.

Fix saved2020-08-22
Sharing licenceMIT · LICENSE
Change size+9 2

What the code was meant to do, written into the code itself as a save note

Fix issue near anti-meridian when forcing zones

The change

7171 return x < 0
7272
7373
74+def mod_angle(value):
75+ """Returns angle in radians to be between -pi and pi"""
76+ return (value + mathlib.pi) % (2 * mathlib.pi) - mathlib.pi
77+
78+
7479 def to_latlon(easting, northing, zone_number, zone_letter=None, northern=None, strict=True):
7580 """This function convert an UTM coordinate into Latitude and Longitude
7681
164169 d3 / 6 * (1 + 2 * p_tan2 + c) +
165170 d5 / 120 * (5 - 2 * c + 28 * p_tan2 - 3 * c2 + 8 * E_P2 + 24 * p_tan4)) / p_cos
166171
172+ longitude = mod_angle(longitude + mathlib.radians(zone_number_to_central_longitude(zone_number)))
173+
167174 return (mathlib.degrees(latitude),
168- mathlib.degrees(longitude) + zone_number_to_central_longitude(zone_number))
175+ mathlib.degrees(longitude))
169176
170177
171178 def from_latlon(latitude, longitude, force_zone_number=None, force_zone_letter=None):
218225 n = R / mathlib.sqrt(1 - E * lat_sin**2)
219226 c = E_P2 * lat_cos**2
220227
221- a = lat_cos * (lon_rad - central_lon_rad)
228+ a = lat_cos * mod_angle(lon_rad - central_lon_rad)
222229 a2 = a * a
223230 a3 = a2 * a
224231 a4 = a3 * a

The check that tells the two apart

failpass·test/test_utm.py::TestForcingAntiMeridian::test_force_east

Check file test/test_utm.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it875f0de454bace3885ea2655ead3c7a2b1025eee
Broken version dated2020-08-22
Moduleutm.conversion
Units changedfrom_latlon, to_latlon
Fingerprint86f8c6ed83d28f95
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in Turbo87/utm