Skip to content

fix: from_latlon mis-reads a lowercase forced zone letter as northern#157

Open
chuenchen309 wants to merge 1 commit into
Turbo87:masterfrom
chuenchen309:fix/from-latlon-lowercase-zone-letter
Open

fix: from_latlon mis-reads a lowercase forced zone letter as northern#157
chuenchen309 wants to merge 1 commit into
Turbo87:masterfrom
chuenchen309:fix/from-latlon-lowercase-zone-letter

Conversation

@chuenchen309

Copy link
Copy Markdown

from_latlon(..., force_zone_letter=...) derives the hemisphere straight from the forced letter without normalizing case:

northern = (zone_letter >= 'N')

Every lowercase ASCII letter is >= 'N', so a lowercase southern-band letter (c–m) is mis-classified as northern and the 10,000,000 m false-northing offset is dropped — a 10,000 km error. Uppercase letters, and lowercase northern letters (n–x), happen to work.

>>> import utm
>>> utm.from_latlon(-30, 10, force_zone_letter='M')[1]
6680793.78
>>> utm.from_latlon(-30, 10, force_zone_letter='m')[1]
-3319206.22          # 10,000,000 m off; utm.to_latlon() then rejects it

Lowercase letters are a supported input elsewhere: to_latlon and check_valid_zone_letter both .upper() the letter first, and the test suite already forces lowercase 'u'. from_latlon was the lone case-sensitive spot.

Fix is northern = (zone_letter.upper() >= 'N'). This is the minimal change and leaves the returned letter's case untouched; if you'd rather normalize the forced letter to uppercase like to_latlon does, happy to switch to that.

Added test_force_south_lowercase_letter (mirrors test_force_south with a lowercase letter): red before, green after; full suite 165 passed.


Disclosure: this PR was authored by an AI coding agent (Claude Code) running on this account — it found the case-sensitivity mismatch, reproduced it, wrote the fix and the test, and wrote this description. The account holder reviews every change and is accountable for it, and the verification above is re-runnable from the diff. Happy to close it if it isn't the kind of contribution you want.

from_latlon() read the hemisphere straight off force_zone_letter without
uppercasing it, so a lowercase southern-band letter (c-m) compared >= 'N'
as true and was mis-read as northern, dropping the 10,000,000 m
false-northing offset (a 10,000 km error). Every other zone-letter path
(to_latlon, check_valid_zone_letter) already normalizes case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant