static void update_parameters(PJ *P) { /*************************************************************************** Update transformation parameters. --------------------------------- The 14-parameter Helmert transformation is at it's core the same as the 7-parameter transformation, since the transformation parameters are projected forward or backwards in time via the rate of changes of the parameters. The transformation parameters are calculated for a specific epoch before the actual Helmert transformation is carried out. The transformation parameters are updated with the following equation [0]: . P(t) = P(EPOCH) + P * (t - EPOCH) . where EPOCH is the epoch indicated in the above table and P is the rate of that parameter. [0] http://itrf.ign.fr/doc_ITRF/Transfo-ITRF2008_ITRFs.txt *******************************************************************************/ struct pj_opaque_helmert *Q = (struct pj_opaque_helmert *) P->opaque; double dt = Q->t_obs - Q->t_epoch; Q->xyz.x = Q->xyz_0.x + Q->dxyz.x * dt; Q->xyz.y = Q->xyz_0.y + Q->dxyz.y * dt; Q->xyz.z = Q->xyz_0.z + Q->dxyz.z * dt; Q->opk.o = Q->opk_0.o + Q->dopk.o * dt; Q->opk.p = Q->opk_0.p + Q->dopk.p * dt; Q->opk.k = Q->opk_0.k + Q->dopk.k * dt; Q->scale = Q->scale_0 + Q->dscale * dt; Q->theta = Q->theta_0 + Q->dtheta * dt; /* debugging output */ if (proj_log_level(P->ctx, PJ_LOG_TELL) >= PJ_LOG_TRACE) { proj_log_trace(P, "Transformation parameters for observation " "t_obs=%g (t_epoch=%g):", Q->t_obs, Q->t_epoch); proj_log_trace(P, "x: %g", Q->xyz.x); proj_log_trace(P, "y: %g", Q->xyz.y); proj_log_trace(P, "z: %g", Q->xyz.z); proj_log_trace(P, "s: %g", Q->scale*1e-6); proj_log_trace(P, "rx: %g", Q->opk.o); proj_log_trace(P, "ry: %g", Q->opk.p); proj_log_trace(P, "rz: %g", Q->opk.k); proj_log_trace(P, "theta: %g", Q->theta); } }
double proj_vgrid_value(PJ *P, LP lp){ /*********************************************** Read grid value at position lp in grids loaded with proj_grid_init. Returns the grid value of the given coordinate. ************************************************/ struct CTABLE used_grid; double value; memset(&used_grid, 0, sizeof(struct CTABLE)); value = read_vgrid_value(P, lp, &(P->vgridlist_geoid_count), P->vgridlist_geoid, &used_grid); proj_log_trace(P, "proj_vgrid_value: (%f, %f) = %f", lp.lam*RAD_TO_DEG, lp.phi*RAD_TO_DEG, value); return value; }
static void build_rot_matrix(PJ *P) { /*************************************************************************** Build rotation matrix. ---------------------- Here we rename rotation indices from omega, phi, kappa (opk), to fi (i.e. phi), theta, psi (ftp), in order to reduce the mental agility needed to implement the expression for the rotation matrix derived over at https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions The relevant section is Euler angles ( z-’-x" intrinsic) -> Rotation matrix By default small angle approximations are used: The matrix elements are approximated by expanding the trigonometric functions to linear order (i.e. cos(x) = 1, sin(x) = x), and discarding products of second order. This was a useful hack when calculating by hand was the only option, but in general, today, should be avoided because: 1. It does not save much computation time, as the rotation matrix is built only once and probably used many times (except when transforming spatio-temporal coordinates). 2. The error induced may be too large for ultra high accuracy applications: the Earth is huge and the linear error is approximately the angular error multiplied by the Earth radius. However, in many cases the approximation is necessary, since it has been used historically: Rotation angles from older published datum shifts may actually be a least squares fit to the linearized rotation approximation, hence not being strictly valid for deriving the exact rotation matrix. In fact, most publicly available transformation parameters are based on the approximate Helmert transform, which is why we use that as the default setting, even though it is more correct to use the exact form of the equations. So in order to fit historically derived coordinates, the access to the approximate rotation matrix is necessary - at least in principle. Also, when using any published datum transformation information, one should always check which convention (exact or approximate rotation matrix) is expected, and whether the induced error for selecting the opposite convention is acceptable (which it often is). Sign conventions ---------------- Take care: Two different sign conventions exist for the rotation terms. Conceptually they relate to whether we rotate the coordinate system or the "position vector" (the vector going from the coordinate system origin to the point being transformed, i.e. the point coordinates interpreted as vector coordinates). Switching between the "position vector" and "coordinate system" conventions is simply a matter of switching the sign of the rotation angles, which algebraically also translates into a transposition of the rotation matrix. Hence, as geodetic constants should preferably be referred to exactly as published, the "convention" option provides the ability to switch between the conventions. ***************************************************************************/ struct pj_opaque_helmert *Q = (struct pj_opaque_helmert *) P->opaque; double f, t, p; /* phi/fi , theta, psi */ double cf, ct, cp; /* cos (fi, theta, psi) */ double sf, st, sp; /* sin (fi, theta, psi) */ /* rename (omega, phi, kappa) to (fi, theta, psi) */ f = Q->opk.o; t = Q->opk.p; p = Q->opk.k; /* Those equations are given assuming coordinate frame convention. */ /* For the position vector convention, we transpose the matrix just after. */ if (Q->exact) { cf = cos(f); sf = sin(f); ct = cos(t); st = sin(t); cp = cos(p); sp = sin(p); R00 = ct*cp; R01 = cf*sp + sf*st*cp; R02 = sf*sp - cf*st*cp; R10 = -ct*sp; R11 = cf*cp - sf*st*sp; R12 = sf*cp + cf*st*sp; R20 = st; R21 = -sf*ct; R22 = cf*ct; } else{ R00 = 1; R01 = p; R02 = -t; R10 = -p; R11 = 1; R12 = f; R20 = t; R21 = -f; R22 = 1; } /* For comparison: Description from Engsager/Poder implementation in set_dtm_1.c (trlib) DATUM SHIFT: TO = scale * ROTZ * ROTY * ROTX * FROM + TRANSLA ( cz sz 0) (cy 0 -sy) (1 0 0) ROTZ=(-sz cz 0), ROTY=(0 1 0), ROTX=(0 cx sx) ( 0 0 1) (sy 0 cy) (0 -sx cx) trp->r11 = cos_ry*cos_rz; trp->r12 = cos_rx*sin_rz + sin_rx*sin_ry*cos_rz; trp->r13 = sin_rx*sin_rz - cos_rx*sin_ry*cos_rz; trp->r21 = -cos_ry*sin_rz; trp->r22 = cos_rx*cos_rz - sin_rx*sin_ry*sin_rz; trp->r23 = sin_rx*cos_rz + cos_rx*sin_ry*sin_rz; trp->r31 = sin_ry; trp->r32 = -sin_rx*cos_ry; trp->r33 = cos_rx*cos_ry; trp->scale = 1.0 + scale; */ if (Q->is_position_vector) { double r; r = R01; R01 = R10; R10 = r; r = R02; R02 = R20; R20 = r; r = R12; R12 = R21; R21 = r; } /* some debugging output */ if (proj_log_level(P->ctx, PJ_LOG_TELL) >= PJ_LOG_TRACE) { proj_log_trace(P, "Rotation Matrix:"); proj_log_trace(P, " | % 6.6g % 6.6g % 6.6g |", R00, R01, R02); proj_log_trace(P, " | % 6.6g % 6.6g % 6.6g |", R10, R11, R12); proj_log_trace(P, " | % 6.6g % 6.6g % 6.6g |", R20, R21, R22); } }
int pj_apply_vgridshift( PJ *defn, const char *listname, PJ_GRIDINFO ***gridlist_p, int *gridlist_count_p, int inverse, long point_count, int point_offset, double *x, double *y, double *z ) { int i; static int debug_count = 0; PJ_GRIDINFO **tables; struct CTABLE ct; if( *gridlist_p == NULL ) { *gridlist_p = pj_gridlist_from_nadgrids( pj_get_ctx(defn), pj_param(defn->ctx,defn->params,listname).s, gridlist_count_p ); if( *gridlist_p == NULL || *gridlist_count_p == 0 ) return defn->ctx->last_errno; } if( *gridlist_count_p == 0 ) { pj_ctx_set_errno( defn->ctx, PJD_ERR_FAILED_TO_LOAD_GRID); return PJD_ERR_FAILED_TO_LOAD_GRID; } tables = *gridlist_p; defn->ctx->last_errno = 0; for( i = 0; i < point_count; i++ ) { double value; long io = i * point_offset; LP input; input.phi = y[io]; input.lam = x[io]; value = read_vgrid_value(defn, input, gridlist_count_p, tables, &ct); if( inverse ) z[io] -= value; else z[io] += value; if( value != HUGE_VAL ) { if( debug_count++ < 20 ) { proj_log_trace(defn, "pj_apply_gridshift(): used %s", ct.id); break; } } if( value == HUGE_VAL ) { int itable; char gridlist[3000]; proj_log_debug(defn, "pj_apply_vgridshift(): failed to find a grid shift table for\n" " location (%.7fdW,%.7fdN)", x[io] * RAD_TO_DEG, y[io] * RAD_TO_DEG ); gridlist[0] = '\0'; for( itable = 0; itable < *gridlist_count_p; itable++ ) { PJ_GRIDINFO *gi = tables[itable]; if( strlen(gridlist) + strlen(gi->gridname) > sizeof(gridlist)-100 ) { strcat( gridlist, "..." ); break; } if( itable == 0 ) sprintf( gridlist, " tried: %s", gi->gridname ); else sprintf( gridlist+strlen(gridlist), ",%s", gi->gridname ); } proj_log_debug(defn, "%s", gridlist); pj_ctx_set_errno( defn->ctx, PJD_ERR_GRID_AREA ); return PJD_ERR_GRID_AREA; } } return 0; }