Skip to content

Commit 223514d

Browse files
author
Klaus Zimmermann
committed
Port TransformCoordinate.c to Proj 6 API.
1 parent 09276c0 commit 223514d

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed
Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,39 @@
1-
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H 1
2-
31
#include <stdio.h>
4-
#include <proj_api.h>
2+
#include <proj.h>
53
#include "TransformCoordinate.h"
64

75
int TransformCoordinate(char * SrcProjStr, char * DstProjStr,
86
double * x, double * y, double * z,
97
unsigned int nPoint) {
10-
projPJ SrcProj, DstProj;
8+
PJ_CONTEXT *CTX;
9+
PJ *P;
10+
size_t stride = sizeof(double);
1111
int Err, i;
1212

13+
CTX = proj_context_create();
14+
P = proj_create_crs_to_crs(CTX, SrcProjStr, DstProjStr, NULL);
15+
1316
/* Constructing the projections */
14-
if (!(SrcProj = pj_init_plus(SrcProjStr))) {
15-
printf("FATAL ERROR: Can not make a projection out of <%s>\n", SrcProjStr);
17+
if (P==0) {
18+
printf("FATAL ERROR: Can not make a transform out of <%s> and <%s>\n",
19+
SrcProjStr, DstProjStr);
1620
return (1);
1721
}
18-
if (!(DstProj = pj_init_plus(DstProjStr))) {
19-
printf("FATAL ERROR: Can not make a projection out of <%s>\n", DstProjStr);
20-
return (2);
21-
}
22-
23-
/* Converting to radian if needed */
24-
if (pj_is_latlong(SrcProj)) {
25-
for (i = 0; i < nPoint; i++) {
26-
x[i] *= DEG_TO_RAD;
27-
y[i] *= DEG_TO_RAD;
28-
}
29-
}
3022

3123
/* Transforming the coordinates */
32-
if ((Err = pj_transform(SrcProj, DstProj, nPoint, 1, x, y, z)) != 0) {
33-
printf("FATAL ERROR: %s\n", pj_strerrno(Err));
24+
Err = proj_trans_generic(P, PJ_FWD,
25+
x, stride, nPoint,
26+
y, stride, nPoint,
27+
z, stride, nPoint,
28+
0, 0, 0);
29+
if (Err != 0) {
30+
printf("FATAL ERROR: Could convert only %i out of %u points\n",
31+
Err, nPoint);
3432
return (3);
3533
}
3634

37-
/* converting to degree if needed */
38-
if (pj_is_latlong(DstProj)) {
39-
for (i = 0; i < nPoint; i++) {
40-
x[i] *= RAD_TO_DEG;
41-
y[i] *= RAD_TO_DEG;
42-
}
43-
}
44-
4535
/* freeing the projection */
46-
pj_free(DstProj);
47-
pj_free(SrcProj);
36+
proj_destroy(P);
37+
proj_context_destroy(CTX);
4838
return (0);
4939
}

0 commit comments

Comments
 (0)