Skip to content

Identify UTM zones in WKT strings via regex - #244

Closed
trasch wants to merge 1 commit into
add-utm-zonesfrom
utm-wkt-identification
Closed

trasch wants to merge 1 commit into
add-utm-zonesfrom
utm-wkt-identification

Conversation

@trasch

@trasch trasch commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #241 (UTM zone projections): closes the one remaining gap, per the discussion after the 2467-suite run — Projection(wkt:) could not recognize UTM zone .prj files, since the fragment-set WKT matching can't extract the zone number.

The pitfall this explicitly handles

UTM .prj strings (ESRI style) contain PROJECTION["Transverse_Mercator"] — which the generic EPSG:3395 fragment matcher (PROJCS + Mercator) happily matches. A naïve "fall through to fragments" would therefore silently mislabel a UTM string as EPSG:3395. The implementation short-circuits on a UTM zone token: the string resolves to a UTM projection or is rejected outright — never guessed against unrelated fragments.

Implementation

  • File-private UtmWktIdentification namespace in Projection.swift, two Swift regex literals:
    • Zone token: (?i)(?:UTM|Universal[\s_]+Transverse[\s_]+Mercator)[\s_]*Zone[\s_]*(\d{1,2})[\s_]*([NS]) — ESRI underscore variants, spelled-out name, spaces/underscores, case-insensitive
    • Central_Meridian: (?i)Central[\s_]*Meridian["]?\s*,\s*(-?\d+(?:\.\d+)?) — when present, must agree with the zone's central meridian (±0.001°), else no match
  • Hemisphere mandatory; zones validated to 1 ... 60 (no guessing); SRID computed as 32_600 + zone / 32_700 + zone
  • Regex literals are built per call (non-Sendable as static stored properties under strict concurrency); the integer-capture inference (Int128) is normalized via explicit String conversion

Tests (+4 funcs, 8 assertions)

  • Realistic ESRI .prj: WGS_1984_UTM_Zone_19N + central_meridian,-69 → 32619 (and southern 20S/−63 → 32720)
  • Short-circuit pin: a UTM token contradicted by its central meridian → nil (not 3395)
  • Token variants: utm zone 5n, Universal Transverse Mercator Zone 33 N, date-line edges (1N → 32601, 60S → 32760)
  • CM cross-validation: agreement passes, contradiction rejects (zone 19N/−70, zone 7S/−140)
  • Invalid tokens: missing hemisphere, zones 0/61/100, UTM Zones → nil
  • Existing matcher tests unchanged and passing (no fragment conflicts — none of the registered patterns contain a UTM zone token)

Also clears 4 redundant-#require warnings in the Phase 4 MapTile tests that the test build surfaced.

Full suite: 2467 tests in 177 suites, zero warnings.

UTM zone `.prj` files could not be recognized: the fragment-set WKT
matching cannot extract the zone number, and a naive fallback would
mismatch - UTM `.prj` strings mention "Transverse_Mercator", which
the generic EPSG:3395 fragments would match.

- File-private UtmWktIdentification namespace with two Swift regex
  literals: a zone token (UTM / "Universal Transverse Mercator",
  spaces or underscores as separators, case-insensitive) capturing
  zone number and hemisphere, and a Central_Meridian parameter for
  cross-validation against the zone's expected central meridian.
- The hemisphere token is mandatory; zones are validated to 1...60;
  an unparseable or contradicted match yields nil.
- A string carrying a UTM zone token short-circuits the matcher:
  it is resolved to a UTM projection or rejected outright, never
  falling through to unrelated name fragments.
- Tests: realistic ESRI-style `.prj` strings (northern and southern
  variants), zone/hemisphere token variants, date-line edge zones,
  central meridian agreement and contradiction cases, and rejected
  invalid tokens (missing hemisphere, zones outside 1...60).
- Clears four redundant #require warnings in the MapTile tests
  (non-failable boundingBox getters).
@trasch

trasch commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #250, which consolidates the full projection-genericity chain into a single reviewable PR. All commits are unchanged in #250.

@trasch trasch closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant