diff --git a/config/FreeBSD b/config/FreeBSD index ad4ecf2d8c..5c66a94c6e 100644 --- a/config/FreeBSD +++ b/config/FreeBSD @@ -10,7 +10,7 @@ */ #define HdfDefines -DFreeBSD -#define StdDefines -DSYSV -D_XOPEN_SOURCE -DByteSwapped -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H +#define StdDefines -DSYSV -D_XOPEN_SOURCE -DByteSwapped #define ByteSwapped #define Cstatic #define Cdynamic diff --git a/ni/src/lib/nfp/TransformCoordinate.c b/ni/src/lib/nfp/TransformCoordinate.c index 89d816423e..c0877eeec1 100644 --- a/ni/src/lib/nfp/TransformCoordinate.c +++ b/ni/src/lib/nfp/TransformCoordinate.c @@ -1,50 +1,39 @@ -#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H 1 - #include -#include +#include #include "TransformCoordinate.h" int TransformCoordinate(char * SrcProjStr, char * DstProjStr, - double * x, double * y, double * z, - unsigned int nPoint) { - projPJ SrcProj, DstProj; - int Err, i; - - /* Constructing the projections */ - if (!(SrcProj = pj_init_plus(SrcProjStr))) { - printf("FATAL ERROR: Can not make a projection out of <%s>\n", SrcProjStr); - return (1); - } - if (!(DstProj = pj_init_plus(DstProjStr))) { - printf("FATAL ERROR: Can not make a projection out of <%s>\n", DstProjStr); - return (2); - } - - /* Converting to radian if needed */ - if (pj_is_latlong(SrcProj)) { - for (i = 0; i < nPoint; i++) { - x[i] *= DEG_TO_RAD; - y[i] *= DEG_TO_RAD; - } - } - - /* Transforming the coordinates */ - if ((Err = pj_transform(SrcProj, DstProj, nPoint, 1, x, y, z)) != 0) { - printf("FATAL ERROR: %s\n", pj_strerrno(Err)); - return (3); - } - - /* converting to degree if needed */ - if (pj_is_latlong(DstProj)) { - for (i = 0; i < nPoint; i++) { - x[i] *= RAD_TO_DEG; - y[i] *= RAD_TO_DEG; - } - } - - /* freeing the projection */ - pj_free(DstProj); - pj_free(SrcProj); - return (0); + double * x, double * y, double * z, + unsigned int nPoint) { + PJ_CONTEXT *CTX; + PJ *P; + size_t stride = sizeof(double); + int Err, i; + + CTX = proj_context_create(); + P = proj_create_crs_to_crs(CTX, SrcProjStr, DstProjStr, NULL); + + /* Constructing the projections */ + if (P==0) { + printf("FATAL ERROR: Can not make a transform out of <%s> and <%s>\n", + SrcProjStr, DstProjStr); + return (1); + } + + /* Transforming the coordinates */ + Err = proj_trans_generic(P, PJ_FWD, + x, stride, nPoint, + y, stride, nPoint, + z, stride, nPoint, + 0, 0, 0); + if (Err != 0) { + printf("FATAL ERROR: Could convert only %i out of %u points\n", + Err, nPoint); + return (3); + } + + /* freeing the projection */ + proj_destroy(P); + proj_context_destroy(CTX); + return (0); } -