|
1 | | -#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H 1 |
2 | | - |
3 | 1 | #include <stdio.h> |
4 | | -#include <proj_api.h> |
| 2 | +#include <proj.h> |
5 | 3 | #include "TransformCoordinate.h" |
6 | 4 |
|
7 | 5 | int TransformCoordinate(char * SrcProjStr, char * DstProjStr, |
8 | 6 | double * x, double * y, double * z, |
9 | 7 | unsigned int nPoint) { |
10 | | - projPJ SrcProj, DstProj; |
| 8 | + PJ_CONTEXT *CTX; |
| 9 | + PJ *P; |
| 10 | + size_t stride = sizeof(double); |
11 | 11 | int Err, i; |
12 | 12 |
|
| 13 | + CTX = proj_context_create(); |
| 14 | + P = proj_create_crs_to_crs(CTX, SrcProjStr, DstProjStr, NULL); |
| 15 | + |
13 | 16 | /* 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); |
16 | 20 | return (1); |
17 | 21 | } |
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 | | - } |
30 | 22 |
|
31 | 23 | /* 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); |
34 | 32 | return (3); |
35 | 33 | } |
36 | 34 |
|
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 | | - |
45 | 35 | /* freeing the projection */ |
46 | | - pj_free(DstProj); |
47 | | - pj_free(SrcProj); |
| 36 | + proj_destroy(P); |
| 37 | + proj_context_destroy(CTX); |
48 | 38 | return (0); |
49 | 39 | } |
0 commit comments