aboutsummaryrefslogtreecommitdiff
path: root/src/PJ_vgridshift.c
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2017-10-23 11:38:56 +0200
committerKristian Evers <kristianevers@gmail.com>2017-10-29 14:02:13 +0100
commit3a2bd267a67d41a461946a6f7b0a99262f47d8a7 (patch)
tree156b3da57e883f0fa8f971ec70999e9fe6ec95ca /src/PJ_vgridshift.c
parent47dd489e1def98f583a3288e4e3f101ae741b4e2 (diff)
downloadPROJ-3a2bd267a67d41a461946a6f7b0a99262f47d8a7.tar.gz
PROJ-3a2bd267a67d41a461946a6f7b0a99262f47d8a7.zip
Refactor grid shift functions.
This refactoring of the grid shift functions allows for easier access to the actual grid values, as well as making it possible to perform horizontal grid shift on a single coordinate without using the pj_apply_gridshift* functions. The latter simplifies the execution path of the forward and inverse functions in PJ_hgridshift.c. This commit introduces proj_*grid_init, proj_*grid_value and proj_hgrid_apply. The init functions initialises horizontal and vertical grids respectivelive (wrappers for pj_gridlist_from_nadgrids with simpler parameters). The proj_*grid_value functions returns the specific grid value at coordinate lp. The proj_hgrid_apply function applies the grid offset to the input coordinate and outputs the adjusted coordinate.
Diffstat (limited to 'src/PJ_vgridshift.c')
-rw-r--r--src/PJ_vgridshift.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c
index ededd544..691f791b 100644
--- a/src/PJ_vgridshift.c
+++ b/src/PJ_vgridshift.c
@@ -9,14 +9,10 @@ static XYZ forward_3d(LPZ lpz, PJ *P) {
PJ_TRIPLET point;
point.lpz = lpz;
- if (P->gridlist != NULL) {
+ if (P->vgridlist_geoid != NULL) {
/* Only try the gridshift if at least one grid is loaded,
* otherwise just pass the coordinate through unchanged. */
- pj_apply_vgridshift( P, "sgrids",
- &(P->gridlist),
- &(P->gridlist_count),
- 1, 1, 0,
- &point.xyz.x, &point.xyz.y, &point.xyz.z );
+ point.xyz.z -= proj_vgrid_value(P, point.lp);
}
return point.xyz;
@@ -27,14 +23,10 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) {
PJ_TRIPLET point;
point.xyz = xyz;
- if (P->gridlist != NULL) {
+ if (P->vgridlist_geoid != NULL) {
/* Only try the gridshift if at least one grid is loaded,
* otherwise just pass the coordinate through unchanged. */
- pj_apply_vgridshift( P, "sgrids",
- &(P->gridlist),
- &(P->gridlist_count),
- 0, 1, 0,
- &point.xyz.x, &point.xyz.y, &point.xyz.z );
+ point.xyz.z += proj_vgrid_value(P, point.lp);
}
return point.lpz;
@@ -61,14 +53,13 @@ PJ *PROJECTION(vgridshift) {
return pj_default_destructor(P, PJD_ERR_NO_ARGS);
}
- /* Build gridlist. P->gridlist can be empty if +grids only ask for optional grids. */
- P->gridlist = pj_gridlist_from_nadgrids( P->ctx, pj_param(P->ctx, P->params, "sgrids").s,
- &(P->gridlist_count) );
+ /* Build gridlist. P->vgridlist_geoid can be empty if +grids only ask for optional grids. */
+ proj_vgrid_init(P, "grids");
/* Was gridlist compiled properly? */
- if ( pj_ctx_get_errno(P->ctx) ) {
+ if ( proj_errno(P) ) {
proj_log_error(P, "vgridshift: could not find required grid(s).");
- return pj_default_destructor(P, -38);
+ return pj_default_destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
}
P->fwdobs = forward_obs;