21 #include <grass/gis.h>
22 #include <grass/gprojects.h>
23 #include <grass/glocale.h>
27 #ifdef PROJ_VERSION_NUM
28 #undef PROJ_VERSION_NUM
30 #define PROJ_VERSION_NUM ((PROJ_VERSION_MAJOR)*1000000+(PROJ_VERSION_MINOR)*10000+(PROJ_VERSION_PATCH)*100)
34 #define MULTIPLY_LOOP(x,y,c,m) \
36 for (i = 0; i < c; ++i) {\
42 #define DIVIDE_LOOP(x,y,c,m) \
44 for (i = 0; i < c; ++i) {\
50 static double METERS_in = 1.0, METERS_out = 1.0;
53 #if PROJ_VERSION_MAJOR >= 6
54 int get_pj_area(
double *xmin,
double *xmax,
double *ymin,
double *ymax)
56 struct Cell_head window;
65 if (window.proj != PROJECTION_LL) {
70 const char *projstr =
NULL;
73 struct Key_Value *in_proj_info, *in_unit_info;
74 struct pj_info iproj, oproj, tproj;
79 G_warning(_(
"Can't get projection info of current location"));
85 G_warning(_(
"Can't get projection units of current location"));
90 if (
pj_get_kv(&iproj, in_proj_info, in_unit_info) < 0) {
91 G_fatal_error(_(
"Can't get projection key values of current location"));
102 source_crs = proj_get_source_crs(
NULL, iproj.pj);
104 projstr = proj_as_proj_string(
NULL, source_crs, PJ_PROJ_5,
NULL);
108 proj_destroy(iproj.pj);
109 iproj.pj = source_crs;
116 G_asprintf(&tproj.def,
"+proj=pipeline +step +inv %s",
118 tproj.pj = proj_create(PJ_DEFAULT_CTX, tproj.def);
119 if (tproj.pj ==
NULL) {
120 G_warning(_(
"proj_create() failed for '%s'"), tproj.def);
123 proj_destroy(tproj.pj);
127 projstr = proj_as_proj_string(
NULL, tproj.pj, PJ_PROJ_5,
NULL);
128 if (projstr ==
NULL) {
129 G_warning(_(
"proj_create() failed for '%s'"), tproj.def);
132 proj_destroy(tproj.pj);
138 estep = (window.west + window.east) / 21.;
139 nstep = (window.north + window.south) / 21.;
140 for (i = 0; i < 20; i++) {
141 x[i] = window.west + estep * (i + 1);
144 x[i + 20] = window.west + estep * (i + 1);
145 y[i + 20] = window.south;
147 x[i + 40] = window.west;
148 y[i + 40] = window.south + nstep * (i + 1);
150 x[i + 60] = window.east;
151 y[i + 60] = window.south + nstep * (i + 1);
154 y[80] = window.north;
156 y[81] = window.south;
158 y[82] = window.north;
160 y[83] = window.south;
161 x[84] = (window.west + window.east) / 2.;
162 y[84] = (window.north + window.south) / 2.;
166 proj_destroy(tproj.pj);
168 *xmin = *xmax =
x[84];
169 *ymin = *ymax = y[84];
170 for (i = 0; i < 84; i++) {
181 G_debug(1,
"get_pj_area(): xmin %g, xmax %g, ymin %g, ymax %g",
182 *xmin, *xmax, *ymin, *ymax);
187 char *get_pj_type_string(PJ *pj)
189 char *pj_type =
NULL;
191 switch (proj_get_type(pj)) {
192 case PJ_TYPE_UNKNOWN:
195 case PJ_TYPE_ELLIPSOID:
198 case PJ_TYPE_PRIME_MERIDIAN:
201 case PJ_TYPE_GEODETIC_REFERENCE_FRAME:
202 G_asprintf(&pj_type,
"geodetic reference frame");
204 case PJ_TYPE_DYNAMIC_GEODETIC_REFERENCE_FRAME:
205 G_asprintf(&pj_type,
"dynamic geodetic reference frame");
207 case PJ_TYPE_VERTICAL_REFERENCE_FRAME:
208 G_asprintf(&pj_type,
"vertical reference frame");
210 case PJ_TYPE_DYNAMIC_VERTICAL_REFERENCE_FRAME:
211 G_asprintf(&pj_type,
"dynamic vertical reference frame");
213 case PJ_TYPE_DATUM_ENSEMBLE:
220 case PJ_TYPE_GEODETIC_CRS:
223 case PJ_TYPE_GEOCENTRIC_CRS:
228 case PJ_TYPE_GEOGRAPHIC_CRS:
231 case PJ_TYPE_GEOGRAPHIC_2D_CRS:
234 case PJ_TYPE_GEOGRAPHIC_3D_CRS:
237 case PJ_TYPE_VERTICAL_CRS:
240 case PJ_TYPE_PROJECTED_CRS:
243 case PJ_TYPE_COMPOUND_CRS:
246 case PJ_TYPE_TEMPORAL_CRS:
249 case PJ_TYPE_ENGINEERING_CRS:
252 case PJ_TYPE_BOUND_CRS:
255 case PJ_TYPE_OTHER_CRS:
258 case PJ_TYPE_CONVERSION:
261 case PJ_TYPE_TRANSFORMATION:
264 case PJ_TYPE_CONCATENATED_OPERATION:
265 G_asprintf(&pj_type,
"concatenated operation");
267 case PJ_TYPE_OTHER_COORDINATE_OPERATION:
268 G_asprintf(&pj_type,
"other coordinate operation");
316 const struct pj_info *info_out,
317 struct pj_info *info_trans)
319 if (info_in->pj ==
NULL)
322 if (info_in->def ==
NULL)
323 G_fatal_error(_(
"Input coordinate system definition is NULL"));
326 #if PROJ_VERSION_MAJOR >= 6
331 info_trans->pj =
NULL;
332 info_trans->meters = 1.;
333 info_trans->zone = 0;
334 sprintf(info_trans->proj,
"pipeline");
337 if (info_trans->def) {
341 info_trans->pj = proj_create(PJ_DEFAULT_CTX, info_trans->def);
342 if (info_trans->pj ==
NULL) {
343 G_warning(_(
"proj_create() failed for '%s'"), info_trans->def);
347 projstr = proj_as_proj_string(
NULL, info_trans->pj, PJ_PROJ_5,
NULL);
348 if (projstr ==
NULL) {
349 G_warning(_(
"proj_create() failed for '%s'"), info_trans->def);
359 info_trans->def =
G_store(projstr);
361 if (strstr(info_trans->def,
"axisswap")) {
362 G_warning(_(
"The transformation pipeline contains an '%s' step. "
363 "Remove this step if easting and northing are swapped in the output."),
367 G_debug(1,
"proj_create() pipeline: %s", info_trans->def);
372 ((
struct pj_info *)info_in)->meters = 1;
373 ((
struct pj_info *)info_out)->meters = 1;
378 else if (info_out->pj ==
NULL) {
379 const char *projstr =
NULL;
393 if (proj_get_type(info_in->pj) == PJ_TYPE_BOUND_CRS) {
396 G_debug(1,
"transform to ll equivalent: found bound crs");
397 source_crs = proj_get_source_crs(
NULL, info_in->pj);
399 projstr = proj_as_proj_string(
NULL, source_crs, PJ_PROJ_5,
NULL);
402 proj_destroy(source_crs);
407 G_debug(1,
"ll equivalent definition: %s", indef);
412 G_asprintf(&(info_trans->def),
"+proj=pipeline +step +inv %s",
414 info_trans->pj = proj_create(PJ_DEFAULT_CTX, info_trans->def);
415 if (info_trans->pj ==
NULL) {
416 G_warning(_(
"proj_create() failed for '%s'"), info_trans->def);
421 projstr = proj_as_proj_string(
NULL, info_trans->pj, PJ_PROJ_5,
NULL);
422 if (projstr ==
NULL) {
423 G_warning(_(
"proj_create() failed for '%s'"), info_trans->def);
431 else if (info_in->def && info_out->pj && info_out->def) {
433 char *indefcrs =
NULL, *outdefcrs =
NULL;
434 char *insrid =
NULL, *outsrid =
NULL;
435 int use_insrid = 0, use_outsrid = 0;
436 PJ *source_crs, *target_crs;
437 PJ_AREA *pj_area =
NULL;
438 double xmin, xmax, ymin, ymax;
443 G_debug(1,
"source proj string: %s", info_in->def);
444 G_debug(1,
"source type: %s", get_pj_type_string(info_in->pj));
445 indefcrs = info_in->def;
446 source_crs = proj_get_source_crs(
NULL, info_in->pj);
450 projstr = proj_as_proj_string(
NULL, source_crs, PJ_PROJ_5,
NULL);
453 G_debug(1,
"Input CRS definition converted from '%s' to '%s'",
454 info_in->def, indefcrs);
456 proj_destroy(source_crs);
460 G_debug(1,
"target proj string: %s", info_out->def);
461 G_debug(1,
"target type: %s", get_pj_type_string(info_out->pj));
462 outdefcrs = info_out->def;
463 target_crs = proj_get_source_crs(
NULL, info_out->pj);
467 projstr = proj_as_proj_string(
NULL, target_crs, PJ_PROJ_5,
NULL);
470 G_debug(1,
"Output CRS definition converted from '%s' to '%s'",
471 info_out->def, outdefcrs);
473 proj_destroy(target_crs);
479 if (strncmp(info_in->srid,
"epsg", 4) == 0)
482 insrid =
G_store(info_in->srid);
485 if (info_out->srid) {
486 if (strncmp(info_out->srid,
"epsg", 4) == 0)
489 outsrid =
G_store(info_out->srid);
499 G_debug(1,
"Input CRS definition: %s", indef);
508 G_debug(1,
"Output CRS definition: %s", outdef);
511 source_crs = proj_create(
NULL, indef);
512 target_crs = proj_create(
NULL, outdef);
515 if (get_pj_area(&xmin, &xmax, &ymin, &ymax)) {
516 pj_area = proj_area_create();
517 proj_area_set_bbox(pj_area, xmin, ymin, xmax, ymax);
520 if (source_crs && target_crs) {
521 PJ_OPERATION_FACTORY_CONTEXT *operation_ctx;
522 PJ_OBJ_LIST *op_list;
524 operation_ctx = proj_create_operation_factory_context(
NULL,
NULL);
530 op_list = proj_create_operations(
NULL,
537 op_count = proj_list_get_count(op_list);
541 G_warning(_(
"Found %d possible transformations"), op_count);
542 for (i = 0; i < op_count; i++) {
544 const char *area_of_use, *projstr;
546 PJ_PROJ_INFO pj_info;
549 op = proj_list_get(
NULL, op_list, i);
550 op_norm = proj_normalize_for_visualization(PJ_DEFAULT_CTX, op);
553 G_warning(_(
"proj_normalize_for_visualization() failed for operation %d"),
561 projstr = proj_as_proj_string(
NULL, op,
563 pj_info = proj_pj_info(op);
564 proj_get_area_of_use(
NULL, op, &w, &s, &e, &n, &area_of_use);
569 pj_info.description);
573 if (pj_info.accuracy > 0) {
578 #if PROJ_VERSION_NUM >= 6020000
579 str = proj_get_remarks(op);
584 str = proj_get_scope(op);
607 proj_list_destroy(op_list);
608 proj_operation_factory_context_destroy(operation_ctx);
611 proj_destroy(source_crs);
613 proj_destroy(target_crs);
616 G_debug(1,
"trying %s to %s", indef, outdef);
618 info_trans->pj = proj_create_crs_to_crs(PJ_DEFAULT_CTX,
623 if (info_trans->pj) {
624 const char *projstr =
NULL;
626 projstr = proj_as_proj_string(
NULL, info_trans->pj,
628 if (projstr ==
NULL) {
629 G_debug(1,
"proj_create_crs_to_crs() failed with PROJ%d for input \"%s\", output \"%s\"",
630 PROJ_VERSION_MAJOR, indef, outdef);
635 G_debug(1,
"trying %s to %s", indef, outdef);
638 proj_destroy(info_trans->pj);
639 info_trans->pj =
NULL;
640 info_trans->pj = proj_create_crs_to_crs(PJ_DEFAULT_CTX,
650 ((
struct pj_info *)info_in)->meters = 1;
653 ((
struct pj_info *)info_out)->meters = 1;
658 if (info_trans->pj) {
662 G_debug(1,
"proj_create_crs_to_crs() succeeded with PROJ%d",
665 projstr = proj_as_proj_string(
NULL, info_trans->pj,
668 info_trans->def =
G_store(projstr);
676 pj_norm = proj_normalize_for_visualization(PJ_DEFAULT_CTX, info_trans->pj);
679 G_warning(_(
"proj_normalize_for_visualization() failed for '%s'"),
683 proj_destroy(info_trans->pj);
684 info_trans->pj = pj_norm;
685 projstr = proj_as_proj_string(
NULL, info_trans->pj,
687 info_trans->def =
G_store(projstr);
695 G_debug(1,
"proj_create_crs_to_crs() pipeline: %s", info_trans->def);
698 proj_destroy(info_trans->pj);
699 info_trans->pj =
NULL;
703 if (info_trans->pj ==
NULL) {
704 G_debug(1,
"proj_create_crs_to_crs() failed with PROJ%d for input \"%s\", output \"%s\"",
705 PROJ_VERSION_MAJOR, indef, outdef);
707 G_warning(
"GPJ_init_transform(): falling back to proj_create()");
718 G_asprintf(&(info_trans->def),
"+proj=pipeline +step +inv %s +step %s",
721 info_trans->pj = proj_create(PJ_DEFAULT_CTX, info_trans->def);
725 proj_area_destroy(pj_area);
734 if (info_trans->pj ==
NULL) {
735 G_warning(_(
"proj_create() failed for '%s'"), info_trans->def);
740 info_trans->pj =
NULL;
741 info_trans->meters = 1.;
742 info_trans->zone = 0;
743 sprintf(info_trans->proj,
"pipeline");
746 if (info_trans->def) {
748 info_trans->pj = proj_create(PJ_DEFAULT_CTX, info_trans->def);
749 if (info_trans->pj ==
NULL) {
750 G_warning(_(
"proj_create() failed for '%s'"), info_trans->def);
757 else if (info_out->pj ==
NULL) {
758 G_asprintf(&(info_trans->def),
"+proj=pipeline +step +inv %s",
760 info_trans->pj = proj_create(PJ_DEFAULT_CTX, info_trans->def);
761 if (info_trans->pj ==
NULL) {
762 G_warning(_(
"proj_create() failed for '%s'"), info_trans->def);
767 else if (info_in->def && info_out->pj && info_out->def) {
769 char *insrid =
NULL, *outsrid =
NULL;
773 if (strncmp(info_in->srid,
"EPSG", 4) == 0)
776 insrid =
G_store(info_in->srid);
779 if (info_out->pj && info_out->srid) {
780 if (strncmp(info_out->srid,
"EPSG", 4) == 0)
783 outsrid =
G_store(info_out->srid);
786 info_trans->pj =
NULL;
788 if (insrid && outsrid) {
792 G_asprintf(&(info_trans->def),
"+proj=pipeline +step +inv +init=%s +step +init=%s",
796 info_trans->pj = proj_create_crs_to_crs(PJ_DEFAULT_CTX,
802 if (info_trans->pj) {
803 G_debug(1,
"proj_create_crs_to_crs() succeeded with PROJ5");
829 G_asprintf(&(info_trans->def),
"+proj=pipeline +step +inv %s +step %s",
832 info_trans->pj = proj_create(PJ_DEFAULT_CTX, info_trans->def);
841 if (info_trans->pj ==
NULL) {
842 G_warning(_(
"proj_create() failed for '%s'"), info_trans->def);
849 if (info_out->pj ==
NULL) {
851 G_warning(_(
"Unable to create latlong equivalent for '%s'"),
890 const struct pj_info *info_out,
891 const struct pj_info *info_trans,
int dir,
892 double *
x,
double *y,
double *z)
898 int in_is_ll, out_is_ll, in_deg2rad, out_rad2deg;
901 if (info_in->pj ==
NULL)
904 if (info_trans->pj ==
NULL)
907 in_deg2rad = out_rad2deg = 1;
910 METERS_in = info_in->meters;
911 in_is_ll = !strncmp(info_in->proj,
"ll", 2);
912 #if PROJ_VERSION_MAJOR >= 6
916 if (in_is_ll && proj_angular_input(info_trans->pj, dir) == 0) {
921 METERS_out = info_out->meters;
922 out_is_ll = !strncmp(info_out->proj,
"ll", 2);
923 #if PROJ_VERSION_MAJOR >= 6
927 if (out_is_ll && proj_angular_output(info_trans->pj, dir) == 0) {
939 METERS_out = info_in->meters;
940 out_is_ll = !strncmp(info_in->proj,
"ll", 2);
941 #if PROJ_VERSION_MAJOR >= 6
945 if (out_is_ll && proj_angular_output(info_trans->pj, dir) == 0) {
950 METERS_in = info_out->meters;
951 in_is_ll = !strncmp(info_out->proj,
"ll", 2);
952 #if PROJ_VERSION_MAJOR >= 6
956 if (in_is_ll && proj_angular_input(info_trans->pj, dir) == 0) {
971 c.lpzt.lam = (*x) / RAD_TO_DEG;
972 c.lpzt.phi = (*y) / RAD_TO_DEG;
985 c.xyzt.x = *
x * METERS_in;
986 c.xyzt.y = *y * METERS_in;
994 c = proj_trans(info_trans->pj, dir, c);
995 ok = proj_errno(info_trans->pj);
998 G_warning(_(
"proj_trans() failed: %s"), proj_errno_string(ok));
1007 *
x = c.lp.lam * RAD_TO_DEG;
1008 *y = c.lp.phi * RAD_TO_DEG;
1019 *
x = c.xyzt.x / METERS_out;
1020 *y = c.xyzt.y / METERS_out;
1028 const struct pj_info *p_in, *p_out;
1030 if (info_out ==
NULL)
1033 if (dir == PJ_FWD) {
1042 METERS_in = p_in->meters;
1043 METERS_out = p_out->meters;
1048 if (strncmp(p_in->proj,
"ll", 2) == 0) {
1049 u = (*x) / RAD_TO_DEG;
1050 v = (*y) / RAD_TO_DEG;
1057 ok = pj_transform(p_in->pj, p_out->pj, 1, 0, &u, &v, &h);
1060 G_warning(_(
"pj_transform() failed: %s"), pj_strerrno(ok));
1064 if (strncmp(p_out->proj,
"ll", 2) == 0) {
1065 *
x = u * RAD_TO_DEG;
1066 *y = v * RAD_TO_DEG;
1069 *
x = u / METERS_out;
1070 *y = v / METERS_out;
1106 const struct pj_info *info_out,
1107 const struct pj_info *info_trans,
int dir,
1108 double *
x,
double *y,
double *z,
int n)
1116 int in_is_ll, out_is_ll, in_deg2rad, out_rad2deg;
1119 if (info_trans->pj ==
NULL)
1122 in_deg2rad = out_rad2deg = 1;
1123 if (dir == PJ_FWD) {
1125 METERS_in = info_in->meters;
1126 in_is_ll = !strncmp(info_in->proj,
"ll", 2);
1127 #if PROJ_VERSION_MAJOR >= 6
1131 if (in_is_ll && proj_angular_input(info_trans->pj, dir) == 0) {
1136 METERS_out = info_out->meters;
1137 out_is_ll = !strncmp(info_out->proj,
"ll", 2);
1138 #if PROJ_VERSION_MAJOR >= 6
1142 if (out_is_ll && proj_angular_output(info_trans->pj, dir) == 0) {
1154 METERS_out = info_in->meters;
1155 out_is_ll = !strncmp(info_in->proj,
"ll", 2);
1156 #if PROJ_VERSION_MAJOR >= 6
1160 if (out_is_ll && proj_angular_output(info_trans->pj, dir) == 0) {
1165 METERS_in = info_out->meters;
1166 in_is_ll = !strncmp(info_out->proj,
"ll", 2);
1167 #if PROJ_VERSION_MAJOR >= 6
1171 if (in_is_ll && proj_angular_input(info_trans->pj, dir) == 0) {
1183 z = G_malloc(
sizeof(
double) * n);
1185 for (i = 0; i < n; i++)
1200 for (i = 0; i < n; i++) {
1203 c.lpzt.lam = (*x) / RAD_TO_DEG;
1204 c.lpzt.phi = (*y) / RAD_TO_DEG;
1211 c = proj_trans(info_trans->pj, dir, c);
1212 if ((ok = proj_errno(info_trans->pj)) < 0)
1216 x[i] = c.lp.lam * RAD_TO_DEG;
1217 y[i] = c.lp.phi * RAD_TO_DEG;
1226 for (i = 0; i < n; i++) {
1229 c.lpzt.lam = (*x) / RAD_TO_DEG;
1230 c.lpzt.phi = (*y) / RAD_TO_DEG;
1237 c = proj_trans(info_trans->pj, dir, c);
1238 if ((ok = proj_errno(info_trans->pj)) < 0)
1242 x[i] = c.xy.x / METERS_out;
1243 y[i] = c.xy.y / METERS_out;
1250 for (i = 0; i < n; i++) {
1252 c.xyzt.x =
x[i] * METERS_in;
1253 c.xyzt.y = y[i] * METERS_in;
1255 c = proj_trans(info_trans->pj, dir, c);
1256 if ((ok = proj_errno(info_trans->pj)) < 0)
1260 x[i] = c.lp.lam * RAD_TO_DEG;
1261 y[i] = c.lp.phi * RAD_TO_DEG;
1270 for (i = 0; i < n; i++) {
1272 c.xyzt.x =
x[i] * METERS_in;
1273 c.xyzt.y = y[i] * METERS_in;
1275 c = proj_trans(info_trans->pj, dir, c);
1276 if ((ok = proj_errno(info_trans->pj)) < 0)
1279 x[i] = c.xy.x / METERS_out;
1280 y[i] = c.xy.y / METERS_out;
1288 G_warning(_(
"proj_trans() failed: %s"), proj_errno_string(ok));
1292 const struct pj_info *p_in, *p_out;
1294 if (dir == PJ_FWD) {
1303 METERS_in = p_in->meters;
1304 METERS_out = p_out->meters;
1307 z = G_malloc(
sizeof(
double) * n);
1309 for (i = 0; i < n; ++i)
1313 if (strncmp(p_in->proj,
"ll", 2) == 0) {
1314 if (strncmp(p_out->proj,
"ll", 2) == 0) {
1316 ok = pj_transform(info_in->pj, info_out->pj, n, 1,
x, y, z);
1321 ok = pj_transform(info_in->pj, info_out->pj, n, 1,
x, y, z);
1326 if (strncmp(p_out->proj,
"ll", 2) == 0) {
1328 ok = pj_transform(info_in->pj, info_out->pj, n, 1,
x, y, z);
1333 ok = pj_transform(info_in->pj, info_out->pj, n, 1,
x, y, z);
1341 G_warning(_(
"pj_transform() failed: %s"), pj_strerrno(ok));
1369 const struct pj_info *info_in,
const struct pj_info *info_out)
1373 struct pj_info info_trans;
1380 METERS_in = info_in->meters;
1381 METERS_out = info_out->meters;
1383 if (strncmp(info_in->proj,
"ll", 2) == 0) {
1385 c.lpzt.lam = (*x) / RAD_TO_DEG;
1386 c.lpzt.phi = (*y) / RAD_TO_DEG;
1389 c = proj_trans(info_trans.pj, PJ_FWD, c);
1390 ok = proj_errno(info_trans.pj);
1392 if (strncmp(info_out->proj,
"ll", 2) == 0) {
1394 *
x = c.lp.lam * RAD_TO_DEG;
1395 *y = c.lp.phi * RAD_TO_DEG;
1399 *
x = c.xy.x / METERS_out;
1400 *y = c.xy.y / METERS_out;
1405 c.xyzt.x = *
x * METERS_in;
1406 c.xyzt.y = *y * METERS_in;
1409 c = proj_trans(info_trans.pj, PJ_FWD, c);
1410 ok = proj_errno(info_trans.pj);
1412 if (strncmp(info_out->proj,
"ll", 2) == 0) {
1414 *
x = c.lp.lam * RAD_TO_DEG;
1415 *y = c.lp.phi * RAD_TO_DEG;
1419 *
x = c.xy.x / METERS_out;
1420 *y = c.xy.y / METERS_out;
1423 proj_destroy(info_trans.pj);
1426 G_warning(_(
"proj_trans() failed: %d"), ok);
1432 METERS_in = info_in->meters;
1433 METERS_out = info_out->meters;
1435 if (strncmp(info_in->proj,
"ll", 2) == 0) {
1436 if (strncmp(info_out->proj,
"ll", 2) == 0) {
1437 u = (*x) / RAD_TO_DEG;
1438 v = (*y) / RAD_TO_DEG;
1439 ok = pj_transform(info_in->pj, info_out->pj, 1, 0, &u, &v, &h);
1440 *
x = u * RAD_TO_DEG;
1441 *y = v * RAD_TO_DEG;
1444 u = (*x) / RAD_TO_DEG;
1445 v = (*y) / RAD_TO_DEG;
1446 ok = pj_transform(info_in->pj, info_out->pj, 1, 0, &u, &v, &h);
1447 *
x = u / METERS_out;
1448 *y = v / METERS_out;
1452 if (strncmp(info_out->proj,
"ll", 2) == 0) {
1455 ok = pj_transform(info_in->pj, info_out->pj, 1, 0, &u, &v, &h);
1456 *
x = u * RAD_TO_DEG;
1457 *y = v * RAD_TO_DEG;
1462 ok = pj_transform(info_in->pj, info_out->pj, 1, 0, &u, &v, &h);
1463 *
x = u / METERS_out;
1464 *y = v / METERS_out;
1468 G_warning(_(
"pj_transform() failed: %s"), pj_strerrno(ok));
1498 const struct pj_info *info_in,
const struct pj_info *info_out)
1504 struct pj_info info_trans;
1511 METERS_in = info_in->meters;
1512 METERS_out = info_out->meters;
1515 h = G_malloc(
sizeof *h *
count);
1517 for (i = 0; i <
count; ++i)
1522 if (strncmp(info_in->proj,
"ll", 2) == 0) {
1524 if (strncmp(info_out->proj,
"ll", 2) == 0) {
1525 for (i = 0; i <
count; i++) {
1527 c.lpzt.lam =
x[i] / RAD_TO_DEG;
1528 c.lpzt.phi = y[i] / RAD_TO_DEG;
1530 c = proj_trans(info_trans.pj, PJ_FWD, c);
1531 if ((ok = proj_errno(info_trans.pj)) < 0)
1534 x[i] = c.lp.lam * RAD_TO_DEG;
1535 y[i] = c.lp.phi * RAD_TO_DEG;
1539 for (i = 0; i <
count; i++) {
1541 c.lpzt.lam =
x[i] / RAD_TO_DEG;
1542 c.lpzt.phi = y[i] / RAD_TO_DEG;
1544 c = proj_trans(info_trans.pj, PJ_FWD, c);
1545 if ((ok = proj_errno(info_trans.pj)) < 0)
1548 x[i] = c.xy.x / METERS_out;
1549 y[i] = c.xy.y / METERS_out;
1555 if (strncmp(info_out->proj,
"ll", 2) == 0) {
1556 for (i = 0; i <
count; i++) {
1558 c.xyzt.x =
x[i] * METERS_in;
1559 c.xyzt.y = y[i] * METERS_in;
1561 c = proj_trans(info_trans.pj, PJ_FWD, c);
1562 if ((ok = proj_errno(info_trans.pj)) < 0)
1565 x[i] = c.lp.lam * RAD_TO_DEG;
1566 y[i] = c.lp.phi * RAD_TO_DEG;
1570 for (i = 0; i <
count; i++) {
1572 c.xyzt.x =
x[i] * METERS_in;
1573 c.xyzt.y = y[i] * METERS_in;
1575 c = proj_trans(info_trans.pj, PJ_FWD, c);
1576 if ((ok = proj_errno(info_trans.pj)) < 0)
1579 x[i] = c.xy.x / METERS_out;
1580 y[i] = c.xy.y / METERS_out;
1586 proj_destroy(info_trans.pj);
1589 G_warning(_(
"proj_trans() failed: %d"), ok);
1592 METERS_in = info_in->meters;
1593 METERS_out = info_out->meters;
1596 h = G_malloc(
sizeof *h *
count);
1598 for (i = 0; i <
count; ++i)
1602 if (strncmp(info_in->proj,
"ll", 2) == 0) {
1603 if (strncmp(info_out->proj,
"ll", 2) == 0) {
1605 ok = pj_transform(info_in->pj, info_out->pj,
count, 1,
x, y, h);
1610 ok = pj_transform(info_in->pj, info_out->pj,
count, 1,
x, y, h);
1615 if (strncmp(info_out->proj,
"ll", 2) == 0) {
1617 ok = pj_transform(info_in->pj, info_out->pj,
count, 1,
x, y, h);
1622 ok = pj_transform(info_in->pj, info_out->pj,
count, 1,
x, y, h);
1630 G_warning(_(
"pj_transform() failed: %s"), pj_strerrno(ok));