Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/FreeBSD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
79 changes: 34 additions & 45 deletions ni/src/lib/nfp/TransformCoordinate.c
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H 1

#include <stdio.h>
#include <proj_api.h>
#include <proj.h>
#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);
}