diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-06-21 22:43:14 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-06-21 23:40:50 +0200 |
| commit | 4e36fd85b9bd9f80c83d7f262c5a8fb3ae44cde2 (patch) | |
| tree | c787ebfba75f36bc576934dde44a1964df94c3ae /src/pj_transform.c | |
| parent | 8ee389a6f44fb9ac0380ddbd3706b9354269d62f (diff) | |
| download | PROJ-4e36fd85b9bd9f80c83d7f262c5a8fb3ae44cde2.tar.gz PROJ-4e36fd85b9bd9f80c83d7f262c5a8fb3ae44cde2.zip | |
Add support for deg, rad and grad in unitconvert (fixes #1052), and document that it supports numeric factors (refs #1053)
Diffstat (limited to 'src/pj_transform.c')
| -rw-r--r-- | src/pj_transform.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/pj_transform.c b/src/pj_transform.c index e67cc525..b459e4a2 100644 --- a/src/pj_transform.c +++ b/src/pj_transform.c @@ -69,8 +69,8 @@ static int adjust_axis( projCtx ctx, const char *axis, int denormalize_flag, #define M_BF (defn->datum_params[6]) /* -** This table is intended to indicate for any given error code in -** the range 0 to -56, whether that error will occur for all locations (ie. +** This table is intended to indicate for any given error code +** whether that error will occur for all locations (ie. ** it is a problem with the coordinate system as a whole) in which case the ** value would be 0, or if the problem is with the point being transformed ** in which case the value is 1. @@ -98,6 +98,19 @@ static const int transient_error[60] = { /* 50 to 59 */ 1, 0, 1, 0, 1, 1, 1, 1, 0, 0 }; +/* -------------------------------------------------------------------- */ +/* Read transient_error[] in a safe way. */ +/* -------------------------------------------------------------------- */ +static int get_transient_error_value(int pos_index) +{ + const int array_size = + (int)(sizeof(transient_error) / sizeof(transient_error[0])); + if( pos_index < 0 || pos_index >= array_size ) { + return 0; + } + return transient_error[pos_index]; +} + /* -------------------------------------------------------------------- */ /* Transform unusual input coordinate axis orientation to */ @@ -211,7 +224,7 @@ static int geographic_to_projected (PJ *P, long n, int dist, double *x, double * && P->ctx->last_errno != ERANGE) && (P->ctx->last_errno > 0 || P->ctx->last_errno < -44 || n == 1 - || transient_error[-P->ctx->last_errno] == 0 ) ) + || get_transient_error_value(-P->ctx->last_errno) == 0 ) ) { return P->ctx->last_errno; } @@ -249,7 +262,7 @@ static int geographic_to_projected (PJ *P, long n, int dist, double *x, double * && P->ctx->last_errno != ERANGE) && (P->ctx->last_errno > 0 || P->ctx->last_errno < -44 || n == 1 - || transient_error[-P->ctx->last_errno] == 0 ) ) + || get_transient_error_value(-P->ctx->last_errno) == 0 ) ) { return P->ctx->last_errno; } @@ -319,7 +332,7 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double * && P->ctx->last_errno != ERANGE) && (P->ctx->last_errno > 0 || P->ctx->last_errno < -44 || n == 1 - || transient_error[-P->ctx->last_errno] == 0 ) ) + || get_transient_error_value(-P->ctx->last_errno) == 0 ) ) { return P->ctx->last_errno; } @@ -358,7 +371,7 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double * && P->ctx->last_errno != ERANGE) && (P->ctx->last_errno > 0 || P->ctx->last_errno < -44 || n == 1 - || transient_error[-P->ctx->last_errno] == 0 ) ) + || get_transient_error_value(-P->ctx->last_errno) == 0 ) ) { return P->ctx->last_errno; } @@ -850,7 +863,7 @@ int pj_datum_transform( PJ *src, PJ *dst, z_is_temp = TRUE; } -#define CHECK_RETURN(defn) {if( defn->ctx->last_errno != 0 && (defn->ctx->last_errno > 0 || transient_error[-defn->ctx->last_errno] == 0) ) { if( z_is_temp ) pj_dalloc(z); return defn->ctx->last_errno; }} +#define CHECK_RETURN(defn) {if( defn->ctx->last_errno != 0 && (defn->ctx->last_errno > 0 || get_transient_error_value(-defn->ctx->last_errno) == 0) ) { if( z_is_temp ) pj_dalloc(z); return defn->ctx->last_errno; }} /* -------------------------------------------------------------------- */ /* If this datum requires grid shifts, then apply it to geodetic */ |
