Skip to content

Commit

Permalink
Merge ca453c1 into 5d105cb
Browse files Browse the repository at this point in the history
  • Loading branch information
kbevers committed May 24, 2018
2 parents 5d105cb + ca453c1 commit 4785b5e
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 15 deletions.
10 changes: 8 additions & 2 deletions docs/source/operations/transformations/vgridshift.rst
Expand Up @@ -11,9 +11,11 @@ Change Vertical datum change by grid shift
+-----------------+--------------------------------------------------------------------+
| **Domain** | 3D |
+-----------------+--------------------------------------------------------------------+
| **Input type** | Geodetic coordinates (horizontal), meters (vertical). |
| **Input type** | Geodetic coordinates (horizontal), meters (vertical), |
| | decimalyear (temporal) |
+-----------------+--------------------------------------------------------------------+
| **Output type** | Geodetic coordinates (horizontal), meters (vertical). |
| **Output type** | Geodetic coordinates (horizontal), meters (vertical), |
| | decimalyear (temporal) |
+-----------------+--------------------------------------------------------------------+

The vertical grid shift is done by offsetting the vertical input coordinates by
Expand Down Expand Up @@ -50,3 +52,7 @@ Parameters
not available.

Grids are expected to be in GTX format.

.. option:: +t_final=<time>

.. option:: +t_epoch=<time>
59 changes: 50 additions & 9 deletions src/PJ_hgridshift.c
@@ -1,12 +1,20 @@
#define PJ_LIB__

#include <errno.h>
#include <string.h>
#include <stddef.h>
#include <time.h>

#include "proj_internal.h"
#include "projects.h"

PROJ_HEAD(hgridshift, "Horizontal grid shift");

struct pj_opaque_hgridshift {
double t_final;
double t_epoch;
};

static XYZ forward_3d(LPZ lpz, PJ *P) {
PJ_COORD point = {{0,0,0,0}};
point.lpz = lpz;
Expand Down Expand Up @@ -34,21 +42,36 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) {
return point.lpz;
}


static PJ_COORD forward_4d (PJ_COORD obs, PJ *P) {
obs.xyz = forward_3d (obs.lpz, P);
return obs;
static PJ_COORD forward_4d(PJ_COORD obs, PJ *P) {
struct pj_opaque_hgridshift *Q = (struct pj_opaque_hgridshift *) P->opaque;
PJ_COORD point = obs;
if (Q->t_final != 0.0 && Q->t_epoch != 0.0) {
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.xyz = forward_3d (obs.lpz, P);
} else {
point.xyz = forward_3d (obs.lpz, P);
}
return point;
}


static PJ_COORD reverse_4d (PJ_COORD obs, PJ *P) {
obs.lpz = reverse_3d (obs.xyz, P);
return obs;
static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
struct pj_opaque_hgridshift *Q = (struct pj_opaque_hgridshift *) P->opaque;
PJ_COORD point = obs;
if (Q->t_final != 0.0 && Q->t_epoch != 0.0) {
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.lpz = reverse_3d (obs.xyz, P);
} else {
point.lpz = reverse_3d (obs.xyz, P);
}
return point;
}



PJ *TRANSFORMATION(hgridshift,0) {
struct pj_opaque_hgridshift *Q = pj_calloc (1, sizeof (struct pj_opaque_hgridshift));
if (0==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = (void *) Q;

P->fwd4d = forward_4d;
P->inv4d = reverse_4d;
Expand All @@ -65,6 +88,24 @@ PJ *TRANSFORMATION(hgridshift,0) {
return pj_default_destructor (P, PJD_ERR_NO_ARGS);
}

if (pj_param(P->ctx, P->params, "tt_final").i) {
Q->t_final = pj_param (P->ctx, P->params, "dt_final").f;
if (Q->t_final == 0) {
/* a number wasn't passed to +t_final, let's see if it was "now" */
/* and set the time accordingly. */
if (!strcmp("now", pj_param(P->ctx, P->params, "st_final").s)) {
time_t now;
struct tm *date;
time(&now);
date = localtime(&now);
Q->t_final = 1900.0 + date->tm_year + date->tm_yday/365.0;
}
}
}

if (pj_param(P->ctx, P->params, "tt_epoch").i)
Q->t_epoch = pj_param (P->ctx, P->params, "dt_epoch").f;


proj_hgrid_init(P, "grids");
/* Was gridlist compiled properly? */
Expand Down
50 changes: 46 additions & 4 deletions src/PJ_vgridshift.c
@@ -1,12 +1,19 @@
#define PJ_LIB__

#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <time.h>

#include "proj_internal.h"
#include "projects.h"

PROJ_HEAD(vgridshift, "Vertical grid shift");

struct pj_opaque_vgridshift {
double t_final;
double t_epoch;
};

static XYZ forward_3d(LPZ lpz, PJ *P) {
PJ_COORD point = {{0,0,0,0}};
Expand Down Expand Up @@ -37,25 +44,60 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) {


static PJ_COORD forward_4d(PJ_COORD obs, PJ *P) {
PJ_COORD point = {{0,0,0,0}};
point.xyz = forward_3d (obs.lpz, P);
struct pj_opaque_vgridshift *Q = (struct pj_opaque_vgridshift *) P->opaque;
PJ_COORD point = obs;
if (Q->t_final != 0.0 && Q->t_epoch != 0.0) {
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.xyz = forward_3d (obs.lpz, P);
} else {
point.xyz = forward_3d (obs.lpz, P);
}
return point;
}

static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
PJ_COORD point;
point.lpz = reverse_3d (obs.xyz, P);
struct pj_opaque_vgridshift *Q = (struct pj_opaque_vgridshift *) P->opaque;
PJ_COORD point = obs;
if (Q->t_final != 0.0 && Q->t_epoch != 0.0) {
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.lpz = reverse_3d (obs.xyz, P);
} else {
point.lpz = reverse_3d (obs.xyz, P);
}
return point;
}


PJ *TRANSFORMATION(vgridshift,0) {
struct pj_opaque_vgridshift *Q = pj_calloc (1, sizeof (struct pj_opaque_vgridshift));
if (0==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = (void *) Q;

if (!pj_param(P->ctx, P->params, "tgrids").i) {
proj_log_error(P, "vgridshift: +grids parameter missing.");
return pj_default_destructor(P, PJD_ERR_NO_ARGS);
}

if (pj_param(P->ctx, P->params, "tt_final").i) {
Q->t_final = pj_param (P->ctx, P->params, "dt_final").f;
if (Q->t_final == 0) {
/* a number wasn't passed to +t_final, let's see if it was "now" */
/* and set the time accordingly. */
if (!strcmp("now", pj_param(P->ctx, P->params, "st_final").s)) {
time_t now;
struct tm *date;
time(&now);
date = localtime(&now);
Q->t_final = 1900.0 + date->tm_year + date->tm_yday/365.0;
}
}
}

if (pj_param(P->ctx, P->params, "tt_epoch").i)
Q->t_epoch = pj_param (P->ctx, P->params, "dt_epoch").f;


/* Build gridlist. P->vgridlist_geoid can be empty if +grids only ask for optional grids. */
proj_vgrid_init(P, "grids");

Expand Down
73 changes: 73 additions & 0 deletions test/gie/deformation.gie
Expand Up @@ -62,4 +62,77 @@ expect failure pjd_err_failed_to_load_grid

operation proj=deformation xy_grids=alaska z_grids=nonexisting ellps=GRS80
expect failure pjd_err_missing_args

-------------------------------------------------------------------------------
operation +proj=vgridshift +grids=egm96_15.gtx +t_epoch=2010.0 +t_final=2018.0
-------------------------------------------------------------------------------
tolerance 0.1 mm
ignore pjd_err_failed_to_load_grid

accept 12 56 0.0 2000.0
expect 12 56 -36.5966 2000.0

accept 12 56 0.0 2011.0
expect 12 56 0.0 2011.0

accept 12 56 0.0 2019.0
expect 12 56 0.0 2019.0

accept 12 56 0.0
expect 12 56 -36.5966


-------------------------------------------------------------------------------
operation +proj=vgridshift +grids=egm96_15.gtx +t_epoch=2010.0 +t_final=now
-------------------------------------------------------------------------------
tolerance 0.1 mm
ignore pjd_err_failed_to_load_grid

accept 12 56 0.0 2000.0
expect 12 56 -36.5966 2000.0

accept 12 56 0.0 2011.0
expect 12 56 0.0 2011.0

accept 12 56 0.0 3011.0
expect 12 56 0.0 3011.0


-------------------------------------------------------------------------------
operation +proj=hgridshift +grids=alaska +t_epoch=2010.0 +t_final=2018.0
-------------------------------------------------------------------------------
tolerance 0.1 mm
ignore pjd_err_failed_to_load_grid

accept -147.0 64.0 0.0 2000.0
expect -147.0023233121 63.9995792119 0.0 2000.0
roundtrip 100

accept -147.0 64.0 0.0 2011.0
expect -147.0 64.0 0.0 2011.0
roundtrip 100

accept -147.0 64.0 0.0 2011.0
expect -147.0 64.0 0.0 2020.0
roundtrip 100

-------------------------------------------------------------------------------
operation +proj=hgridshift +grids=alaska +t_epoch=2010.0 +t_final=now
-------------------------------------------------------------------------------
tolerance 0.1 mm
ignore pjd_err_failed_to_load_grid

accept -147.0 64.0 0.0 2000.0
expect -147.0023233121 63.9995792119 0.0 2000.0
roundtrip 100

accept -147.0 64.0 0.0 2011.0
expect -147.0 64.0 0.0 2011.0
roundtrip 100

accept -147.0 64.0 0.0 3011.0
expect -147.0 64.0 0.0 3011.0
roundtrip 100


</gie>

0 comments on commit 4785b5e

Please sign in to comment.