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.
ProjectTurbo87/utm
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
| 71 | 71 | return x < 0 | |
| 72 | 72 | ||
| 73 | 73 | ||
| 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 | + | ||
| 74 | 79 | def to_latlon(easting, northing, zone_number, zone_letter=None, northern=None, strict=True): | |
| 75 | 80 | """This function convert an UTM coordinate into Latitude and Longitude | |
| 76 | 81 | ||
| ⋯ | |||
| 164 | 169 | d3 / 6 * (1 + 2 * p_tan2 + c) + | |
| 165 | 170 | d5 / 120 * (5 - 2 * c + 28 * p_tan2 - 3 * c2 + 8 * E_P2 + 24 * p_tan4)) / p_cos | |
| 166 | 171 | ||
| 172 | + | longitude = mod_angle(longitude + mathlib.radians(zone_number_to_central_longitude(zone_number))) | |
| 173 | + | ||
| 167 | 174 | return (mathlib.degrees(latitude), | |
| 168 | - | mathlib.degrees(longitude) + zone_number_to_central_longitude(zone_number)) | |
| 175 | + | mathlib.degrees(longitude)) | |
| 169 | 176 | ||
| 170 | 177 | ||
| 171 | 178 | def from_latlon(latitude, longitude, force_zone_number=None, force_zone_letter=None): | |
| ⋯ | |||
| 218 | 225 | n = R / mathlib.sqrt(1 - E * lat_sin**2) | |
| 219 | 226 | c = E_P2 * lat_cos**2 | |
| 220 | 227 | ||
| 221 | - | a = lat_cos * (lon_rad - central_lon_rad) | |
| 228 | + | a = lat_cos * mod_angle(lon_rad - central_lon_rad) | |
| 222 | 229 | a2 = a * a | |
| 223 | 230 | a3 = a2 * a | |
| 224 | 231 | a4 = a3 * a | |
The check that tells the two apart
fail→pass·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
- 2026-07-27from_latlon