aboutsummaryrefslogtreecommitdiff
path: root/src/4D_api.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-08-22 22:52:48 +0200
committerEven Rouault <even.rouault@spatialys.com>2019-08-23 21:49:40 +0200
commit11869e2c4d29f0e607a0f78fb289d253fccd9a16 (patch)
tree5b8be1637f9272b8b3ddb4a6280b6207389fbf4f /src/4D_api.cpp
parentb7f829ce8f7c9fce2934b3981493a5d3338143b9 (diff)
downloadPROJ-11869e2c4d29f0e607a0f78fb289d253fccd9a16.tar.gz
PROJ-11869e2c4d29f0e607a0f78fb289d253fccd9a16.zip
Add proj_create_crs_to_crs_from_pj()
I've been frustrated a number of times with proj_create_crs_to_crs() not accepting a PJ* object for the source and target CRS. And thus constraining to go back to WKT2 in a artificial way.
Diffstat (limited to 'src/4D_api.cpp')
-rw-r--r--src/4D_api.cpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/4D_api.cpp b/src/4D_api.cpp
index 07ccfd91..3a9582e6 100644
--- a/src/4D_api.cpp
+++ b/src/4D_api.cpp
@@ -1045,10 +1045,27 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char
return nullptr;
}
+ auto ret = proj_create_crs_to_crs_from_pj(ctx, src, dst, area, nullptr);
+ proj_destroy(src);
+ proj_destroy(dst);
+ return ret;
+}
+
+/*****************************************************************************/
+PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, PJ *source_crs, PJ *target_crs, PJ_AREA *area, const char* const *) {
+/******************************************************************************
+ Create a transformation pipeline between two known coordinate reference
+ systems.
+
+ See docs/source/development/reference/functions.rst
+
+******************************************************************************/
+ if( !ctx ) {
+ ctx = pj_get_default_ctx();
+ }
+
auto operation_ctx = proj_create_operation_factory_context(ctx, nullptr);
if( !operation_ctx ) {
- proj_destroy(src);
- proj_destroy(dst);
return nullptr;
}
@@ -1067,12 +1084,10 @@ 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);
- auto op_list = proj_create_operations(ctx, src, dst, operation_ctx);
+ auto op_list = proj_create_operations(ctx, source_crs, target_crs, operation_ctx);
if( !op_list ) {
proj_operation_factory_context_destroy(operation_ctx);
- proj_destroy(src);
- proj_destroy(dst);
return nullptr;
}
@@ -1080,8 +1095,7 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char
if( op_count == 0 ) {
proj_list_destroy(op_list);
proj_operation_factory_context_destroy(operation_ctx);
- proj_destroy(src);
- proj_destroy(dst);
+
proj_context_log_debug(ctx, "No operation found matching criteria");
return nullptr;
}
@@ -1090,35 +1104,29 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char
assert(P);
if( P == nullptr || op_count == 1 || (area && area->bbox_set) ||
- proj_get_type(src) == PJ_TYPE_GEOCENTRIC_CRS ||
- proj_get_type(dst) == PJ_TYPE_GEOCENTRIC_CRS ) {
+ proj_get_type(source_crs) == PJ_TYPE_GEOCENTRIC_CRS ||
+ proj_get_type(target_crs) == PJ_TYPE_GEOCENTRIC_CRS ) {
proj_list_destroy(op_list);
proj_operation_factory_context_destroy(operation_ctx);
- proj_destroy(src);
- proj_destroy(dst);
return P;
}
- auto pjGeogToSrc = create_operation_to_base_geog_crs(ctx, src);
+ auto pjGeogToSrc = create_operation_to_base_geog_crs(ctx, source_crs);
if( !pjGeogToSrc )
{
proj_list_destroy(op_list);
proj_operation_factory_context_destroy(operation_ctx);
- proj_destroy(src);
- proj_destroy(dst);
proj_context_log_debug(ctx,
"Cannot create transformation from geographic CRS of source CRS to source CRS");
proj_destroy(P);
return nullptr;
}
- auto pjGeogToDst = create_operation_to_base_geog_crs(ctx, dst);
+ auto pjGeogToDst = create_operation_to_base_geog_crs(ctx, target_crs);
if( !pjGeogToDst )
{
proj_list_destroy(op_list);
proj_operation_factory_context_destroy(operation_ctx);
- proj_destroy(src);
- proj_destroy(dst);
proj_context_log_debug(ctx,
"Cannot create transformation from geographic CRS of target CRS to target CRS");
proj_destroy(P);
@@ -1177,8 +1185,6 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char
proj_list_destroy(op_list);
proj_operation_factory_context_destroy(operation_ctx);
- proj_destroy(src);
- proj_destroy(dst);
proj_destroy(pjGeogToSrc);
proj_destroy(pjGeogToDst);
@@ -1205,8 +1211,6 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char
{
proj_list_destroy(op_list);
proj_operation_factory_context_destroy(operation_ctx);
- proj_destroy(src);
- proj_destroy(dst);
proj_destroy(pjGeogToSrc);
proj_destroy(pjGeogToDst);
proj_destroy(P);