From 6bb14fa874562eb4879a3b80b51b22cd2add058e Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 27 Dec 2018 16:22:09 +0100 Subject: [PATCH] Add an hardcoded +ellps=GRS80 when there is no datum/ellipsoid specification (refs #201) --- docs/source/operations/options/ellps.rst | 2 +- docs/source/usage/differences.rst | 5 +-- src/init.cpp | 39 ++++++++++++++++++++++++ test/gie/ellipsoid.gie | 3 +- test/unit/gie_self_tests.cpp | 4 +-- 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/docs/source/operations/options/ellps.rst b/docs/source/operations/options/ellps.rst index af98d377a9..b754f74187 100644 --- a/docs/source/operations/options/ellps.rst +++ b/docs/source/operations/options/ellps.rst @@ -2,4 +2,4 @@ See :option:`proj -le` for a list of available ellipsoids. - *Defaults to "WGS84".* + *Defaults to "GRS80".* diff --git a/docs/source/usage/differences.rst b/docs/source/usage/differences.rst index 1f7769d312..5694e4d074 100644 --- a/docs/source/usage/differences.rst +++ b/docs/source/usage/differences.rst @@ -66,5 +66,6 @@ Removal of proj_def.dat ----------------------- Before PROJ 6, the proj_def.dat was used to provide general and per-projection -parameters, when +no_defs was not specified. It has now been removed. In -particular, the +ellps=WGS84 is no longer a default. +parameters, when +no_defs was not specified. It has now been removed. In case, +no ellipsoid or datum specification is provided in the PROJ string, the +default ellipsoid is GRS80 (was WGS84 in previous PROJ versions). diff --git a/src/init.cpp b/src/init.cpp index 72ed69fe0c..4274f5b460 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -330,6 +330,43 @@ Expand key from buffer or (if not in buffer) from init file return init_items; } + + +static void append_default_ellipsoid_to_paralist (paralist *start) { + if (nullptr==start) + return; + + /* Set defaults, unless inhibited (either explicitly through a "no_defs" token */ + /* or implicitly, because we are initializing a pipeline) */ + if (pj_param_exists (start, "no_defs")) + return; + auto proj = pj_param_exists (start, "proj"); + if (nullptr==proj) + return; + if (strlen (proj->param) < 6) + return; + if (0==strcmp ("pipeline", proj->param + 5)) + return; + + /* Don't default ellipse if datum, ellps or any ellipsoid information is set */ + if (pj_param_exists (start, "datum")) return; + if (pj_param_exists (start, "ellps")) return; + if (pj_param_exists (start, "a")) return; + if (pj_param_exists (start, "b")) return; + if (pj_param_exists (start, "rf")) return; + if (pj_param_exists (start, "f")) return; + if (pj_param_exists (start, "e")) return; + if (pj_param_exists (start, "es")) return; + + /* Locate end of start-list */ + paralist *last = nullptr; + for (last = start; last->next; last = last->next); + + /* If we're here, it's OK to append the current default item */ + last->next = pj_mkparam("ellps=GRS80"); +} + + /*****************************************************************************/ static paralist *pj_expand_init_internal(PJ_CONTEXT *ctx, paralist *init, int allow_init_epsg) { /****************************************************************************** @@ -594,6 +631,8 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i return nullptr; } + append_default_ellipsoid_to_paralist (start); + /* Allocate projection structure */ PIN = proj(nullptr); if (nullptr==PIN) { diff --git a/test/gie/ellipsoid.gie b/test/gie/ellipsoid.gie index 88419346f6..929eb79972 100644 --- a/test/gie/ellipsoid.gie +++ b/test/gie/ellipsoid.gie @@ -58,7 +58,8 @@ operation proj=merc +a=-1 expect failure errno major_axis_not_given operation proj=merc -expect failure errno major_axis_not_given +accept 0 0 +expect 0 0 operation proj=merc +es=-1 expect failure errno major_axis_not_given diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 4e788358f4..9ff7a2789f 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -500,9 +500,9 @@ TEST(gie, io_predicates) { ASSERT_FALSE(proj_angular_output(P, PJ_FWD)); ASSERT_FALSE(proj_angular_output(P, PJ_INV)); - /* pj_init_ctx should default to WGS84 */ + /* pj_init_ctx should default to GRS80 */ ASSERT_EQ(P->a, 6378137.0); - ASSERT_EQ(P->f, 1.0 / 298.257223563); + ASSERT_EQ(P->f, 1.0 / 298.257222101); proj_destroy(P); /* Test that pj_fwd* and pj_inv* returns NaNs when receiving NaN input */