From 85e7d8e7b20e0fb25409bd2874878b5337e69c41 Mon Sep 17 00:00:00 2001 From: Javier Jimenez Shaw Date: Wed, 19 Feb 2025 00:18:39 +0100 Subject: [PATCH] Spilhaus: better use lon_0 and lat_0 --- .../operations/projections/spilhaus.rst | 4 +-- src/projections/spilhaus.cpp | 19 +++++++----- test/gie/spilhaus.gie | 30 +++++++++++++++++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/docs/source/operations/projections/spilhaus.rst b/docs/source/operations/projections/spilhaus.rst index 80a4ab6e55..4589e0f1d3 100644 --- a/docs/source/operations/projections/spilhaus.rst +++ b/docs/source/operations/projections/spilhaus.rst @@ -35,7 +35,7 @@ Parameters .. note:: All parameters are optional. -.. option:: +lon_c= +.. option:: +lon_0= Longitude of projection centre. @@ -49,7 +49,7 @@ Parameters See :ref:`Projection Units ` for more information. -.. option:: +lat_c= +.. option:: +lat_0= Latitude of projection centre. diff --git a/src/projections/spilhaus.cpp b/src/projections/spilhaus.cpp index 4383d5c70b..01b8680095 100644 --- a/src/projections/spilhaus.cpp +++ b/src/projections/spilhaus.cpp @@ -135,25 +135,30 @@ PJ *PJ_PROJECTION(spilhaus) { ? pj_param(P->ctx, P->params, ("r" + name).c_str()).f : def * DEG_TO_RAD; }; + // Values from https://github.com/OSGeo/PROJ/issues/1851 - const double lat_center = param_rad("lat_c", -49.56371678); - const double lon_center = param_rad("lon_c", 66.94970198); + if (!pj_param(P->ctx, P->params, "tlon_0").i) { + P->lam0 = 66.94970198 * DEG_TO_RAD; + } + if (!pj_param(P->ctx, P->params, "tlat_0").i) { + P->phi0 = -49.56371678 * DEG_TO_RAD; + } const double azimuth = param_rad("azi", 40.17823482); const double rotation = param_rad("rot", 45); Q->cosrot = cos(rotation); Q->sinrot = sin(rotation); - const double conformal_lat_center = pj_conformal_lat(lat_center, P->e); + const double conformal_lat_center = pj_conformal_lat(P->phi0, P->e); Q->sinalpha = -cos(conformal_lat_center) * cos(azimuth); Q->cosalpha = sqrt(1 - Q->sinalpha * Q->sinalpha); - Q->lambda_0 = lon_center + atan2(tan(azimuth), -sin(conformal_lat_center)); + Q->lambda_0 = atan2(tan(azimuth), -sin(conformal_lat_center)); Q->beta = M_PI + atan2(-sin(azimuth), -tan(conformal_lat_center)); - Q->conformal_distortion = - cos(lat_center) / sqrt(1 - P->es * sin(lat_center) * sin(lat_center)) / - cos(conformal_lat_center); + Q->conformal_distortion = cos(P->phi0) / + sqrt(1 - P->es * sin(P->phi0) * sin(P->phi0)) / + cos(conformal_lat_center); P->fwd = spilhaus_forward; P->inv = spilhaus_inverse; diff --git a/test/gie/spilhaus.gie b/test/gie/spilhaus.gie index 2c78c6a6c7..5c2c439429 100644 --- a/test/gie/spilhaus.gie +++ b/test/gie/spilhaus.gie @@ -367,11 +367,12 @@ expect -15390625 -15546875 ------------------------------------------------------------ # Stable for default parameters ------------------------------------------------------------ -operation +proj=spilhaus +rot=45 +k_0=1 +lat_c=-49.56371678 +lon_c=66.94970198 +azi=40.17823482 +operation +proj=spilhaus +rot=45 +k_0=1 +lat_0=-49.56371678 +lon_0=66.94970198 +azi=40.17823482 tolerance 1 mm ------------------------------------------------------------ accept 130.4 -16.2 expect 3733410.0118 -9320.8573 +roundtrip 1 ------------------------------------------------------------ # Sentitive to input parameters @@ -381,36 +382,42 @@ tolerance 1 mm ------------------------------------------------------------ accept 130.4 -16.2 expect 3733410.0118 -9320.8573 +roundtrip 1 ------------------------------------------------------------ -operation +proj=spilhaus +lon_c=10.1 +operation +proj=spilhaus +lon_0=10.1 tolerance 1 mm ------------------------------------------------------------ accept 130.4 -16.2 expect 4343770.7991 -3701935.6242 +roundtrip 1 ------------------------------------------------------------ -operation +proj=spilhaus +lat_c=30.1 +operation +proj=spilhaus +lat_0=30.1 tolerance 1 mm ------------------------------------------------------------ accept 130.4 -16.2 expect 3637341.2895 -2571368.8666 +roundtrip 1 ------------------------------------------------------------ operation +proj=spilhaus +azi=9.1 tolerance 1 mm ------------------------------------------------------------ accept 130.4 -16.2 expect 3061806.4542 -1678791.7428 +roundtrip 1 ------------------------------------------------------------ operation +proj=spilhaus +rot=40.1 tolerance 1 mm ------------------------------------------------------------ accept 130.4 -16.2 expect 3720561.6630 309609.603620 +roundtrip 1 ------------------------------------------------------------ operation +proj=spilhaus +k_0=0.9 tolerance 1 mm ------------------------------------------------------------ accept 130.4 -16.2 expect 3360069.0106 -8388.7716 +roundtrip 1 ------------------------------------------------------------ # Sphere @@ -422,4 +429,21 @@ accept 130.4 -16.2 expect 3737644.5177 -7049.7883 roundtrip 1 +------------------------------------------------------------ +# vs Adams WS2 +------------------------------------------------------------ +operation +proj=adams_ws2 +R=6378137 +tolerance 1 mm +------------------------------------------------------------ +accept 130.4 -16.2 +expect 8199312.0391 -1392652.9172 +roundtrip 1 +------------------------------------------------------------ +operation +proj=spilhaus +R=6378137 +lon_0=0 +lat_0=0 +azi=0 +rot=0 +tolerance 1 mm +------------------------------------------------------------ +accept 130.4 -16.2 +expect 8199312.0391 -1392652.9172 +roundtrip 1 +