Skip to content

Commit

Permalink
Add an hardcoded +ellps=GRS80 when there is no datum/ellipsoid specif…
Browse files Browse the repository at this point in the history
…ication (refs OSGeo#201)
  • Loading branch information
rouault committed Dec 27, 2018
1 parent a562729 commit 6bb14fa
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/source/operations/options/ellps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

See :option:`proj -le` for a list of available ellipsoids.

*Defaults to "WGS84".*
*Defaults to "GRS80".*
5 changes: 3 additions & 2 deletions docs/source/usage/differences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).
39 changes: 39 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/******************************************************************************
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion test/gie/ellipsoid.gie
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/unit/gie_self_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 6bb14fa

Please sign in to comment.