From c3fd68227b408a0172afb449651d3dae6b38612e Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Wed, 12 Jul 2017 11:52:14 +0200 Subject: Implemented proj_transform_coord() and proj_transform_obs() --- src/PJ_cart.c | 39 ++++++++++++++++++++++++++++++++++----- src/pj_obs_api.c | 52 +++++++++++++++++++++++++++++++++++++++++----------- src/proj.def | 55 +++++++++++++++++++++++++++++-------------------------- src/proj.h | 2 ++ 4 files changed, 106 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/PJ_cart.c b/src/PJ_cart.c index 9155dd03..c6d1dd74 100644 --- a/src/PJ_cart.c +++ b/src/PJ_cart.c @@ -235,6 +235,7 @@ int pj_cart_selftest (void) { PJ_CONTEXT *ctx; PJ *P; PJ_OBS a, b, obs[2]; + PJ_COORD coord[2]; int err; size_t n, sz; double dist, h, t; @@ -419,14 +420,42 @@ int pj_cart_selftest (void) { if (50 != obs[1].coo.lpz.z) return 27; /* NOTE: unchanged */ if (50==h) return 28; - /* Clean up */ - proj_destroy (P); + /* test proj_transform_obs() */ + + obs[0].coo = proj_coord (PJ_TORAD(12), PJ_TORAD(55), 45, 0); + obs[1].coo = proj_coord (PJ_TORAD(12), PJ_TORAD(56), 50, 0); + + if (proj_transform_obs(P, PJ_FWD, 2, obs)) + return 30; + if (a.coo.lpz.lam != obs[0].coo.lpz.lam) return 31; + if (a.coo.lpz.phi != obs[0].coo.lpz.phi) return 32; + if (a.coo.lpz.z != obs[0].coo.lpz.z) return 33; + if (b.coo.lpz.lam != obs[1].coo.lpz.lam) return 34; + if (b.coo.lpz.phi != obs[1].coo.lpz.phi) return 35; + if (b.coo.lpz.z != obs[1].coo.lpz.z) return 36; + + /* test proj_transform_coord() */ + + coord[0] = proj_coord (PJ_TORAD(12), PJ_TORAD(55), 45, 0); + coord[1] = proj_coord (PJ_TORAD(12), PJ_TORAD(56), 50, 0); + if (proj_transform_coord(P, PJ_FWD, 2, coord)) + return 40; + + if (a.coo.lpz.lam != coord[0].lpz.lam) return 41; + if (a.coo.lpz.phi != coord[0].lpz.phi) return 42; + if (a.coo.lpz.z != coord[0].lpz.z) return 43; + if (b.coo.lpz.lam != coord[1].lpz.lam) return 44; + if (b.coo.lpz.phi != coord[1].lpz.phi) return 45; + if (b.coo.lpz.z != coord[1].lpz.z) return 46; + + /* Clean up after transform* tests */ + proj_destroy (P); /* test proj_create_crs_to_crs() */ P = proj_create_crs_to_crs(0, "epsg:25832", "epsg:25833"); if (P==0) - return 30; + return 50; a.coo.xy.x = 700000.0; a.coo.xy.y = 6000000.0; @@ -435,14 +464,14 @@ int pj_cart_selftest (void) { a = proj_trans_obs(P, PJ_FWD, a); if (dist > 1e-7) - return 31; + return 51; proj_destroy(P); /* let's make sure that only entries in init-files results in a usable PJ */ P = proj_create_crs_to_crs(0, "proj=utm +zone=32 +datum=WGS84", "proj=utm +zone=33 +datum=WGS84"); if (P != 0) { proj_destroy(P); - return 32; + return 52; } return 0; diff --git a/src/pj_obs_api.c b/src/pj_obs_api.c index 1b353b46..81a6e337 100644 --- a/src/pj_obs_api.c +++ b/src/pj_obs_api.c @@ -216,7 +216,7 @@ size_t proj_transform ( In most cases, the stride will be identical for x, y,z, and t, since they will typically be either individual arrays (stride = sizeof(double)), or strided views into an array of application specific data structures (stride = sizeof (...)). - + But in order to support cases where x, y, z, and t come from heterogeneous sources, individual strides, sx, sy, sz, st, are used. @@ -244,7 +244,7 @@ size_t proj_transform ( if (0==ny) y = &null_broadcast; if (0==nz) z = &null_broadcast; if (0==nt) t = &null_broadcast; - + /* nothing to do? */ if (0==nx+ny+nz+nt) return 0; @@ -315,10 +315,46 @@ size_t proj_transform ( *z = coord.xyzt.z; if (nt==1) *t = coord.xyzt.t; - + return i; } +/*****************************************************************************/ +int proj_transform_obs (PJ *P, enum proj_direction direction, size_t n, PJ_OBS *obs) { +/****************************************************************************** + Batch transform an array of PJ_OBS. + + Returns 0 if all observations are transformed without error, otherwise + returns error number. +******************************************************************************/ + size_t i; + for (i=0; i