diff options
| author | Kristian Evers <kristianevers@gmail.com> | 2018-01-08 11:54:54 +0100 |
|---|---|---|
| committer | Kristian Evers <kristianevers@gmail.com> | 2018-01-08 19:58:06 +0100 |
| commit | 47953f0a93cd90d0d52b74f2b2705516f018b2f1 (patch) | |
| tree | 5f4f70608db82da6d6fc793562fe161243159510 /src | |
| parent | 07bb446ec474cf62094070a8ea848b37c911a075 (diff) | |
| download | PROJ-47953f0a93cd90d0d52b74f2b2705516f018b2f1.tar.gz PROJ-47953f0a93cd90d0d52b74f2b2705516f018b2f1.zip | |
Allow usage of classic +axis parameter in axisswap.
Instead of +order the classic PROJ.4 parameter +axis can used instead.
This is mostly an inititive to simplify backwars compatibility in the
4D API. P->axis is initialized in pj_init() it can be assumed that it
is set up correctly.
+order and +axis are mutually exclusive.
Diffstat (limited to 'src')
| -rw-r--r-- | src/PJ_axisswap.c | 97 |
1 files changed, 63 insertions, 34 deletions
diff --git a/src/PJ_axisswap.c b/src/PJ_axisswap.c index 62a9fba3..bb22f41e 100644 --- a/src/PJ_axisswap.c +++ b/src/PJ_axisswap.c @@ -159,53 +159,70 @@ static PJ_COORD reverse_4d(PJ_COORD coo, PJ *P) { PJ *CONVERSION(axisswap,0) { /***********************************************************************/ struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); - char *order, *s; - unsigned int i, j, n; + char *s; + unsigned int i, j, n = 0; if (0==Q) return pj_default_destructor (P, ENOMEM); P->opaque = (void *) Q; - /* read axis order */ - if (pj_param (P->ctx, P->params, "torder").i) { - order = pj_param(P->ctx, P->params, "sorder").s; - } else { - return pj_default_destructor(P, PJD_ERR_MISSING_ARGS); - } - - /* Preparation and finalization steps are skipped, since the raison */ - /* d'etre of axisswap is to bring input coordinates in line with the */ - /* the internally expected order (ENU), such that handling of offsets */ - /* etc. can be done correctly in a later step of a pipeline */ - P->skip_fwd_prepare = 1; - P->skip_fwd_finalize = 1; - P->skip_inv_prepare = 1; - P->skip_inv_finalize = 1; + /* +order and +axis are mutually exclusive */ + if ( !pj_param_exists(P->params, "order") == !pj_param_exists(P->params, "axis") ) + return pj_default_destructor(P, PJD_ERR_AXIS); /* fill axis list with indices from 4-7 to simplify duplicate search further down */ - for (i=0; i<4; i++) + for (i=0; i<4; i++) { Q->axis[i] = i+4; + Q->sign[i] = 1; + } + + /* if the "order" parameter is used */ + if ( pj_param_exists(P->params, "order") ) { + /* read axis order */ + char *order = pj_param(P->ctx, P->params, "sorder").s; + + /* check that all characters are valid */ + for (i=0; i<strlen(order); i++) + if (strchr("1234-,", order[i]) == 0) { + proj_log_error(P, "axisswap: unknown axis '%c'", order[i]); + return pj_default_destructor(P, PJD_ERR_AXIS); + } - /* check that all characters are valid */ - for (i=0; i<strlen(order); i++) - if (strchr("1234-,", order[i]) == 0) { - proj_log_error(P, "axisswap: unknown axis '%c'", order[i]); - return pj_default_destructor(P, PJD_ERR_AXIS); + /* read axes numbers and signs */ + for ( s = order, n = 0; *s != '\0' && n < 4; ) { + Q->axis[n] = abs(atoi(s))-1; + Q->sign[n++] = sign(atoi(s)); + while ( *s != '\0' && *s != ',' ) + s++; + if ( *s == ',' ) + s++; } + } - /* read axes numbers and signs */ - for ( s = order, n = 0; *s != '\0' && n < 4; ) { - Q->axis[n] = abs(atoi(s))-1; - if (Q->axis[n] >= 4) { - proj_log_error(P, "swapaxis: invalid axis '%s'", s); - return pj_default_destructor(P, PJD_ERR_AXIS); + /* if the "axis" parameter is used */ + if ( pj_param_exists(P->params, "axis") ) { + /* parse the classic PROJ.4 enu axis specification */ + for (i=0; i < 3; i++) { + switch(P->axis[i]) { + case 'w': + Q->sign[i] = -1; + case 'e': + Q->axis[i] = 0; + break; + case 's': + Q->sign[i] = -1; + case 'n': + Q->axis[i] = 1; + break; + case 'd': + Q->sign[i] = -1; + case 'u': + Q->axis[i] = 2; + break; + } } - Q->sign[n++] = sign(atoi(s)); - while ( *s != '\0' && *s != ',' ) - s++; - if ( *s == ',' ) - s++; + n = 3; } /* check for duplicate axes */ @@ -219,6 +236,7 @@ PJ *CONVERSION(axisswap,0) { } } + /* only map fwd/inv functions that are possible with the given axis setup */ if (n == 4) { P->fwd4d = forward_4d; @@ -233,6 +251,7 @@ PJ *CONVERSION(axisswap,0) { P->inv = reverse_2d; } + if (P->fwd4d == NULL && P->fwd3d == NULL && P->fwd == NULL) { proj_log_error(P, "swapaxis: bad axis order"); return pj_default_destructor(P, PJD_ERR_AXIS); @@ -246,5 +265,15 @@ PJ *CONVERSION(axisswap,0) { P->right = PJ_IO_UNITS_PROJECTED; } + + /* Preparation and finalization steps are skipped, since the raison */ + /* d'etre of axisswap is to bring input coordinates in line with the */ + /* the internally expected order (ENU), such that handling of offsets */ + /* etc. can be done correctly in a later step of a pipeline */ + P->skip_fwd_prepare = 1; + P->skip_fwd_finalize = 1; + P->skip_inv_prepare = 1; + P->skip_inv_finalize = 1; + return P; } |
