diff options
| author | Even Rouault <even.rouault@mines-paris.org> | 2018-12-31 11:37:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-31 11:37:51 +0100 |
| commit | 32f3ef47e55c38b0eabb6d781fee3944d3239414 (patch) | |
| tree | ba2850500ee732559bada055dbab281ceff49a22 /src/4D_api.cpp | |
| parent | 5c41d3a1078895ed096b416db15c91108bccad87 (diff) | |
| parent | 0e0e0e475414ddeb75e0e140d8a3381a431036d9 (diff) | |
| download | PROJ-32f3ef47e55c38b0eabb6d781fee3944d3239414.tar.gz PROJ-32f3ef47e55c38b0eabb6d781fee3944d3239414.zip | |
Merge pull request #1208 from rouault/merge_PJ_and_PJ_OBJ
Unify PJ_OBJ and PJ structures
Diffstat (limited to 'src/4D_api.cpp')
| -rw-r--r-- | src/4D_api.cpp | 81 |
1 files changed, 52 insertions, 29 deletions
diff --git a/src/4D_api.cpp b/src/4D_api.cpp index 71144a75..d8288af8 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -39,9 +39,12 @@ #include "proj.h" #include "proj_internal.h" #include "proj_math.h" -#include "projects.h" +#include "proj_internal.h" #include "geodesic.h" +#include "proj/common.hpp" +#include "proj/coordinateoperation.hpp" + /* Initialize PJ_COORD struct */ PJ_COORD proj_coord (double x, double y, double z, double t) { @@ -83,6 +86,9 @@ int proj_angular_output (PJ *P, enum PJ_DIRECTION dir) { /* Geodesic distance (in meter) + fwd and rev azimuth between two points on the ellipsoid */ PJ_COORD proj_geod (const PJ *P, PJ_COORD a, PJ_COORD b) { PJ_COORD c; + if( !P->geod ) { + return proj_coord_error(); + } /* Note: the geodesic code takes arguments in degrees */ geod_inverse (P->geod, PJ_TODEG(a.lpz.phi), PJ_TODEG(a.lpz.lam), @@ -98,6 +104,9 @@ PJ_COORD proj_geod (const PJ *P, PJ_COORD a, PJ_COORD b) { double proj_lp_dist (const PJ *P, PJ_COORD a, PJ_COORD b) { double s12, azi1, azi2; /* Note: the geodesic code takes arguments in degrees */ + if( !P->geod ) { + return HUGE_VAL; + } geod_inverse (P->geod, PJ_TODEG(a.lpz.phi), PJ_TODEG(a.lpz.lam), PJ_TODEG(b.lpz.phi), PJ_TODEG(b.lpz.lam), @@ -734,7 +743,7 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char - a PROJ string, like "+proj=longlat +datum=WGS84". When using that syntax, the axis order and unit for geographic CRS will be longitude, latitude, and the unit degrees. - - more generally any string accepted by proj_obj_create_from_user_input() + - more generally any string accepted by proj_create_from_user_input() An "area of use" can be specified in area. When it is supplied, the more accurate transformation between two given systems can be chosen. @@ -744,12 +753,6 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char PJ *P = proj_create_crs_to_crs(0, "EPSG:25832", "EPSG:25833", NULL); ******************************************************************************/ - PJ *P; - PJ_OBJ* src; - PJ_OBJ* dst; - PJ_OPERATION_FACTORY_CONTEXT* operation_ctx; - PJ_OBJ_LIST* op_list; - PJ_OBJ* op; const char* proj_string; const char* const optionsProj4Mode[] = { "USE_PROJ4_INIT_RULES=YES", nullptr }; @@ -760,23 +763,23 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char const char* const* optionsImportCRS = proj_context_get_use_proj4_init_rules(ctx, FALSE) ? optionsProj4Mode : nullptr; - src = proj_obj_create_from_user_input(ctx, source_crs, optionsImportCRS); + auto src = proj_create_from_user_input(ctx, source_crs, optionsImportCRS); if( !src ) { proj_context_log_debug(ctx, "Cannot instanciate source_crs"); return nullptr; } - dst = proj_obj_create_from_user_input(ctx, target_crs, optionsImportCRS); + auto dst = proj_create_from_user_input(ctx, target_crs, optionsImportCRS); if( !dst ) { proj_context_log_debug(ctx, "Cannot instanciate target_crs"); - proj_obj_destroy(src); + proj_destroy(src); return nullptr; } - operation_ctx = proj_create_operation_factory_context(ctx, nullptr); + auto operation_ctx = proj_create_operation_factory_context(ctx, nullptr); if( !operation_ctx ) { - proj_obj_destroy(src); - proj_obj_destroy(dst); + proj_destroy(src); + proj_destroy(dst); return nullptr; } @@ -793,35 +796,36 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char proj_operation_factory_context_set_grid_availability_use( ctx, operation_ctx, PROJ_GRID_AVAILABILITY_DISCARD_OPERATION_IF_MISSING_GRID); - op_list = proj_obj_create_operations(ctx, src, dst, operation_ctx); + auto op_list = proj_create_operations(ctx, src, dst, operation_ctx); proj_operation_factory_context_destroy(operation_ctx); - proj_obj_destroy(src); - proj_obj_destroy(dst); + proj_destroy(src); + proj_destroy(dst); if( !op_list ) { return nullptr; } - if( proj_obj_list_get_count(op_list) == 0 ) { - proj_obj_list_destroy(op_list); + if( proj_list_get_count(op_list) == 0 ) { + proj_list_destroy(op_list); proj_context_log_debug(ctx, "No operation found matching criteria"); return nullptr; } - op = proj_obj_list_get(ctx, op_list, 0); - proj_obj_list_destroy(op_list); + auto op = proj_list_get(ctx, op_list, 0); + proj_list_destroy(op_list); if( !op ) { return nullptr; } - proj_string = proj_obj_as_proj_string(ctx, op, PJ_PROJ_5, nullptr); + proj_string = proj_as_proj_string(ctx, op, PJ_PROJ_5, nullptr); if( !proj_string) { - proj_obj_destroy(op); + proj_destroy(op); proj_context_log_debug(ctx, "Cannot export operation as a PROJ string"); return nullptr; } + PJ* P; if( proj_string[0] == '\0' ) { /* Null transform ? */ P = proj_create(ctx, "proj=affine"); @@ -829,7 +833,7 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char P = proj_create(ctx, proj_string); } - proj_obj_destroy(op); + proj_destroy(op); return P; } @@ -1069,9 +1073,6 @@ PJ_PROJ_INFO proj_pj_info(PJ *P) { memset(&pjinfo, 0, sizeof(PJ_PROJ_INFO)); - /* Expected accuracy of the transformation. Hardcoded for now, will be improved */ - /* later. Most likely to be used when a transformation is set up with */ - /* proj_create_crs_to_crs in a future version that leverages the EPSG database. */ pjinfo.accuracy = -1.0; if (nullptr==P) @@ -1081,8 +1082,30 @@ PJ_PROJ_INFO proj_pj_info(PJ *P) { if (pj_param(P->ctx, P->params, "tproj").i) pjinfo.id = pj_param(P->ctx, P->params, "sproj").s; - /* projection description */ - pjinfo.description = P->descr; + /* coordinate operation description */ + if( P->iso_obj ) { + pjinfo.description = P->iso_obj->nameStr().c_str(); + } else { + pjinfo.description = P->descr; + } + + // accuracy + if( P->iso_obj ) { + auto conv = dynamic_cast<const NS_PROJ::operation::Conversion*>(P->iso_obj.get()); + if( conv ) { + pjinfo.accuracy = 0.0; + } else { + auto op = dynamic_cast<const NS_PROJ::operation::CoordinateOperation*>(P->iso_obj.get()); + if( op ) { + const auto& accuracies = op->coordinateOperationAccuracies(); + if( !accuracies.empty() ) { + try { + pjinfo.accuracy = std::stod(accuracies[0]->value()); + } catch ( const std::exception& ) {} + } + } + } + } /* projection definition */ if (P->def_full) |
