diff options
| author | Thomas Knudsen <busstoptaktik@users.noreply.github.com> | 2018-02-12 11:53:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-12 11:53:27 +0100 |
| commit | a557b49e85ebfbfe0af076bc529002ca60e4a045 (patch) | |
| tree | 3f56b95bd9fcce2a4f4c0725b7cda1bcb4bba1cf /src | |
| parent | 4bbb3df6c7ca56f477ef53113258d13f8a71bbce (diff) | |
| parent | 5480a1ffaa38e16dd592beeaa42deb7e2cf4eadb (diff) | |
| download | PROJ-a557b49e85ebfbfe0af076bc529002ca60e4a045.tar.gz PROJ-a557b49e85ebfbfe0af076bc529002ca60e4a045.zip | |
Merge pull request #793 from busstoptaktik/pj_init_cleanup
A few repairs in and around pj_init.c
Diffstat (limited to 'src')
| -rw-r--r-- | src/gie.c | 13 | ||||
| -rw-r--r-- | src/pj_init.c | 37 | ||||
| -rw-r--r-- | src/projects.h | 37 |
3 files changed, 62 insertions, 25 deletions
@@ -1836,12 +1836,12 @@ static int pj_cart_selftest (void) { /* linear in and out */ P = proj_create(PJ_DEFAULT_CTX, - " +proj=helmert +ellps=GRS80" + " +proj=helmert" " +x=0.0127 +y=0.0065 +z=-0.0209 +s=0.00195" " +rx=-0.00039 +ry=0.00080 +rz=-0.00114" " +dx=-0.0029 +dy=-0.0002 +dz=-0.0006 +ds=0.00001" " +drx=-0.00011 +dry=-0.00019 +drz=0.00007" - " +t_epoch=1988.0 +transpose" + " +t_epoch=1988.0 +transpose +no_defs" ); if (0==P) return 0; if (proj_angular_input (P, PJ_FWD)) return 116; @@ -1853,8 +1853,12 @@ static int pj_cart_selftest (void) { if (proj_angular_input (P, PJ_INV)) return 121; if (proj_angular_output (P, PJ_FWD)) return 122; if (proj_angular_output (P, PJ_INV)) return 123; - proj_destroy(P); + /* We specified "no_defs" but didn't give any ellipsoid info */ + /* pj_init_ctx should defualt to WGS84 */ + if (P->a != 6378137.0) return 124; + if (P->f != 1.0/298.257223563) return 125; + proj_destroy(P); return 0; } @@ -1862,9 +1866,6 @@ static int pj_cart_selftest (void) { - - - static int test_time(const char* args, double tol, double t_in, double t_exp) { PJ_COORD in, out; PJ *P = proj_create(PJ_DEFAULT_CTX, args); diff --git a/src/pj_init.c b/src/pj_init.c index f54a2a92..bf098686 100644 --- a/src/pj_init.c +++ b/src/pj_init.c @@ -470,22 +470,20 @@ pj_init(int argc, char **argv) { } -typedef PJ *(constructor)(PJ *); - -static constructor *pj_constructor (const char *name) { +static PJ_CONSTRUCTOR pj_locate_constructor (const char *name) { int i; char *s; for (i = 0; (s = pj_list[i].id) && strcmp(name, s) ; ++i) ; if (0==s) return 0; - return (constructor *) pj_list[i].proj; + return (PJ_CONSTRUCTOR) pj_list[i].proj; } PJ * pj_init_ctx(projCtx ctx, int argc, char **argv) { char *s, *name; - constructor *proj; + PJ_CONSTRUCTOR proj; paralist *curr, *init, *start; int i; int err; @@ -511,7 +509,7 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) { n_inits++; } - /* can't have nested pipeline directly */ + /* can't have nested pipelines directly */ if (n_pipelines > 1) { pj_ctx_set_errno (ctx, PJD_ERR_MALFORMED_PIPELINE); return 0; @@ -559,7 +557,7 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) { return pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED); name += 5; - proj = pj_constructor (name); + proj = pj_locate_constructor (name); if (0==proj) return pj_dealloc_params (ctx, start, PJD_ERR_UNKNOWN_PROJECTION_ID); @@ -594,16 +592,23 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) { return pj_default_destructor (PIN, proj_errno(PIN)); err = pj_ellipsoid (PIN); - if (PIN->need_ellps && 0 != err) { - pj_log (ctx, PJ_LOG_DEBUG_MINOR, "pj_init_ctx: Must specify ellipsoid or sphere"); - return pj_default_destructor (PIN, proj_errno(PIN)); - } - if (0==err) { - PIN->a_orig = PIN->a; - PIN->es_orig = PIN->es; - if (pj_calc_ellipsoid_params (PIN, PIN->a, PIN->es)) - return pj_default_destructor (PIN, PJD_ERR_ECCENTRICITY_IS_ONE); + + if (err) { + /* Didn't get an ellps, but doesn't need one: Get a free WGS84 */ + if (PIN->need_ellps) { + pj_log (ctx, PJ_LOG_DEBUG_MINOR, "pj_init_ctx: Must specify ellipsoid or sphere"); + return pj_default_destructor (PIN, proj_errno(PIN)); + } + else { + PIN->f = 1.0/298.257223563; + PIN->a_orig = PIN->a = 6378137.0; + PIN->es_orig = PIN->es = PIN->f*(2-PIN->f); + } } + PIN->a_orig = PIN->a; + PIN->es_orig = PIN->es; + if (pj_calc_ellipsoid_params (PIN, PIN->a, PIN->es)) + return pj_default_destructor (PIN, PJD_ERR_ECCENTRICITY_IS_ONE); /* Now that we have ellipse information check for WGS84 datum */ if( PIN->datum_type == PJD_3PARAM diff --git a/src/projects.h b/src/projects.h index bfbe08cb..25ff82a4 100644 --- a/src/projects.h +++ b/src/projects.h @@ -218,6 +218,37 @@ struct PJ_AREA { struct projCtx_t; typedef struct projCtx_t projCtx_t; +/***************************************************************************** + + Some function types that are especially useful when working with PJs + +****************************************************************************** + +PJ_CONSTRUCTOR: + + A function taking a pointer-to-PJ as arg, and returning a pointer-to-PJ. + Historically called twice: First with a 0 argument, to allocate memory, + second with the first return value as argument, for actual setup. + +PJ_DESTRUCTOR: + + A function taking a pointer-to-PJ and an integer as args, then first + handling the deallocation of the PJ, afterwards handing the integer over + to the error reporting subsystem, and finally returning a null pointer in + support of the "return free (P)" (aka "get the hell out of here") idiom. + +PJ_OPERATOR: + + A function taking a PJ_COORD and a pointer-to-PJ as args, applying the + PJ to the PJ_COORD, and returning the resulting PJ_COORD. + +*****************************************************************************/ +typedef PJ *(* PJ_CONSTRUCTOR) (PJ *); +typedef void *(* PJ_DESTRUCTOR) (PJ *, int); +typedef PJ_COORD (* PJ_OPERATOR) (PJ_COORD, PJ *); +/****************************************************************************/ + + /* base projection data structure */ struct PJconsts { @@ -267,10 +298,10 @@ struct PJconsts { LP (*inv)(XY, PJ *); XYZ (*fwd3d)(LPZ, PJ *); LPZ (*inv3d)(XYZ, PJ *); - PJ_COORD (*fwd4d)(PJ_COORD, PJ *); - PJ_COORD (*inv4d)(PJ_COORD, PJ *); + PJ_OPERATOR fwd4d; + PJ_OPERATOR inv4d; - void *(*destructor)(PJ *, int); + PJ_DESTRUCTOR destructor; /************************************************************************************* |
