From 09276c02a8e33feb43031df0efd02bf33bc5eb89 Mon Sep 17 00:00:00 2001 From: Klaus Zimmermann Date: Mon, 27 Sep 2021 16:02:28 +0200 Subject: [PATCH 1/3] Fix formatting --- ni/src/lib/nfp/TransformCoordinate.c | 77 ++++++++++++++-------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/ni/src/lib/nfp/TransformCoordinate.c b/ni/src/lib/nfp/TransformCoordinate.c index 89d816423..7142b2798 100644 --- a/ni/src/lib/nfp/TransformCoordinate.c +++ b/ni/src/lib/nfp/TransformCoordinate.c @@ -5,46 +5,45 @@ #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; - } + 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; - } + } + + /* 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); + /* freeing the projection */ + pj_free(DstProj); + pj_free(SrcProj); + return (0); } - From 223514db8aed6191d1e8798baba74a83c6588976 Mon Sep 17 00:00:00 2001 From: Klaus Zimmermann Date: Mon, 27 Sep 2021 16:46:21 +0200 Subject: [PATCH 2/3] Port TransformCoordinate.c to Proj 6 API. --- ni/src/lib/nfp/TransformCoordinate.c | 50 +++++++++++----------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/ni/src/lib/nfp/TransformCoordinate.c b/ni/src/lib/nfp/TransformCoordinate.c index 7142b2798..c0877eeec 100644 --- a/ni/src/lib/nfp/TransformCoordinate.c +++ b/ni/src/lib/nfp/TransformCoordinate.c @@ -1,49 +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; + 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 (!(SrcProj = pj_init_plus(SrcProjStr))) { - printf("FATAL ERROR: Can not make a projection out of <%s>\n", SrcProjStr); + if (P==0) { + printf("FATAL ERROR: Can not make a transform out of <%s> and <%s>\n", + SrcProjStr, DstProjStr); 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)); + 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); } - /* 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); + proj_destroy(P); + proj_context_destroy(CTX); return (0); } From 9c7cbed8ed26513d706cf40ad9b4d17cd74323d3 Mon Sep 17 00:00:00 2001 From: Klaus Zimmermann Date: Mon, 27 Sep 2021 16:47:55 +0200 Subject: [PATCH 3/3] Remove remnants of old "ACCEPT_USE_OF_DEPRECATED_PROJ_API_H" --- config/FreeBSD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/FreeBSD b/config/FreeBSD index ad4ecf2d8..5c66a94c6 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