Skip to content

Fix Oblique Mercator natural-origin offset to use the central-line azimuth - #130

Merged
pomadchin merged 1 commit into
locationtech:masterfrom
sergei-malyshko-navvis:fix/omerc-natural-origin-offset
Aug 3, 2026
Merged

Fix Oblique Mercator natural-origin offset to use the central-line azimuth#130
pomadchin merged 1 commit into
locationtech:masterfrom
sergei-malyshko-navvis:fix/omerc-natural-origin-offset

Conversation

@sergei-malyshko-navvis

Copy link
Copy Markdown
Contributor

Summary

Fixes the Oblique Mercator (+proj=omerc) natural-origin offset so that the projection centre maps to the false easting/northing when +gamma differs from +alpha — in particular for definitions with an explicit +gamma=0 and a non-zero azimuth (the ESRI "Local" / mine-grid convention).

Root cause

In ObliqueMercatorProjection.initialize(), the natural-origin (uc) offset is computed with cosrot = cos(Gamma) (the rectified bearing γ):

u_0 = no_uoff ? 0. :
    Math.abs(al * Math.atan(Math.sqrt(d * d - 1.) / cosrot) / bl);

Snyder's Hotine Oblique Mercator (and PROJ) define this offset from the central-line azimuth α:

u_c = (A / B) * atan( sqrt(D^2 - 1) / cos(alpha_c) )

project() computes the point's along-line coordinate from the natural azimuth (singam/cosgam), so the offset must be based on α, not γ. When γ = α the two coincide (the common case, and why this went unnoticed — e.g. the standard EPSG omerc grids store +gamma equal to +alpha). But when γ ≠ α — e.g. +gamma=0 with a non-zero azimuth — u_0 no longer cancels the centre's coordinate, and the centre is displaced along the central line.

Impact (before the fix)

For a grid like +proj=omerc +lat_0=-20 +lonc=140 +alpha=30 +gamma=0 +k=1 +x_0=200000 +y_0=300000 +ellps=GRS80, the centre (140, -20) should map to (200000, 300000). Before the fix it was off by ~2.5 km in the along-line direction (larger for larger azimuths). This is the ESRI PROJECTION["Local"] mine-grid convention (origin + scale + azimuth, no rectification), which is common for Australian survey grids.

Fix

Use cos(alpha) for the offset. This is a no-op when γ == α (verified by the full existing test suite) and matches PROJ output when γ ≠ α.

Test

Adds Proj4VariousTest#testObliqueMercatorExplicitGamma, covering +gamma=0 with a non-zero azimuth. It asserts the centre maps exactly to the false easting/northing and checks two further points; reference coordinates were computed with PROJ. With the fix the centre error is 0 and the points agree with PROJ to < 1e-4 m; before the fix the centre was ~2.5 km off.

Full core suite: 65 run, 0 failures, 0 errors, 2 skipped (pre-existing).

Related note (not addressed here)

The Gamma field defaults to 0.0 rather than NaN, so the gzi = Double.isNaN(Gamma) guard is always "provided" and the if (gzi == 0) Gamma = alpha; default (rectified bearing defaults to the azimuth when +gamma is omitted) never runs. That affects the rotation for the +gamma-omitted case and the unreachable two-point setup. I've kept this PR focused on the offset bug; happy to open a separate issue/PR for the Gamma default if useful.

…imuth

The natural-origin (uc) offset was computed from the rectified bearing
(Gamma) via cosrot, but Snyder's Hotine Oblique Mercator defines it with
the central-line azimuth (alpha):

    u_c = (A / B) * atan(sqrt(D^2 - 1) / cos(alpha_c))

When Gamma equals alpha the two agree, which is why this went unnoticed.
For definitions where the rectified bearing differs from the azimuth --
notably the ESRI "Local" / mine-grid convention of an explicit +gamma=0
with a non-zero azimuth -- the projection centre was displaced along the
central line (e.g. ~2.5 km), so the false easting/northing no longer
landed on the centre.

Use cos(alpha) for the offset. This is a no-op when Gamma == alpha and
matches PROJ output when Gamma != alpha.

Adds a regression test (Proj4VariousTest#testObliqueMercatorExplicitGamma)
covering +gamma=0 with a non-zero azimuth, with reference coordinates
computed by PROJ.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Sergei Malyshko <sergei.malyshko@navvis.com>
@pomadchin
pomadchin self-requested a review July 28, 2026 14:18
@pomadchin

Copy link
Copy Markdown
Member

Thanks for rising up a PR!

Also could I ask you to sign https://www.eclipse.org/legal/eca/? (ECA form link) that would help us to make the ECA bot happy.

@pomadchin

Copy link
Copy Markdown
Member

Thanks, that's a great catch!

@pomadchin pomadchin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥

@pomadchin
pomadchin merged commit e79dbaf into locationtech:master Aug 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants