diff options
| -rw-r--r-- | src/iso19111/c_api.cpp | 21 | ||||
| -rw-r--r-- | src/proj.h | 5 | ||||
| -rw-r--r-- | test/unit/test_c_api.cpp | 57 |
3 files changed, 83 insertions, 0 deletions
diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index 5a3f0374..6b726f34 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -7518,6 +7518,27 @@ void PROJ_DLL proj_operation_factory_context_set_discard_superseded( // --------------------------------------------------------------------------- +/** \brief Set whether ballpark transformations are allowed. + * + * @param ctx PROJ context, or NULL for default context + * @param factory_ctx Operation factory context. must not be NULL + * @param allow set to TRUE to allow ballpark transformations. + * @since 7.1 + */ +void PROJ_DLL proj_operation_factory_context_set_allow_ballpark_transformations( + PJ_CONTEXT *ctx, PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, int allow) { + SANITIZE_CTX(ctx); + assert(factory_ctx); + try { + factory_ctx->operationContext->setAllowBallparkTransformations(allow != + 0); + } catch (const std::exception &e) { + proj_log_error(ctx, __FUNCTION__, e.what()); + } +} + +// --------------------------------------------------------------------------- + //! @cond Doxygen_Suppress /** \brief Opaque object representing a set of operation results. */ struct PJ_OPERATION_LIST : PJ_OBJ_LIST { @@ -1202,6 +1202,11 @@ void PROJ_DLL proj_operation_factory_context_set_discard_superseded( PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, int discard); +void PROJ_DLL proj_operation_factory_context_set_allow_ballpark_transformations( + PJ_CONTEXT *ctx, + PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, + int allow); + /* ------------------------------------------------------------------------- */ diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index da95e523..9e477ef3 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -1600,6 +1600,63 @@ TEST_F(CApi, proj_create_operations_with_pivot) { // --------------------------------------------------------------------------- +TEST_F(CApi, proj_create_operations_allow_ballpark_transformations) { + auto ctxt = proj_create_operation_factory_context(m_ctxt, nullptr); + ASSERT_NE(ctxt, nullptr); + ContextKeeper keeper_ctxt(ctxt); + + auto source_crs = proj_create_from_database( + m_ctxt, "EPSG", "4267", PJ_CATEGORY_CRS, false, nullptr); // NAD27 + ASSERT_NE(source_crs, nullptr); + ObjectKeeper keeper_source_crs(source_crs); + + auto target_crs = proj_create_from_database( + m_ctxt, "EPSG", "4258", PJ_CATEGORY_CRS, false, nullptr); // ETRS89 + ASSERT_NE(target_crs, nullptr); + ObjectKeeper keeper_target_crs(target_crs); + + proj_operation_factory_context_set_spatial_criterion( + m_ctxt, ctxt, PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION); + + proj_operation_factory_context_set_grid_availability_use( + m_ctxt, ctxt, PROJ_GRID_AVAILABILITY_IGNORED); + + // Default: allowed implictly + { + auto res = proj_create_operations(m_ctxt, source_crs, target_crs, ctxt); + ASSERT_NE(res, nullptr); + ObjListKeeper keeper_res(res); + + EXPECT_EQ(proj_list_get_count(res), 1); + } + + // Allow explictly + { + proj_operation_factory_context_set_allow_ballpark_transformations( + m_ctxt, ctxt, true); + + auto res = proj_create_operations(m_ctxt, source_crs, target_crs, ctxt); + ASSERT_NE(res, nullptr); + ObjListKeeper keeper_res(res); + + EXPECT_EQ(proj_list_get_count(res), 1); + } + + // Disallow + { + proj_operation_factory_context_set_allow_ballpark_transformations( + m_ctxt, ctxt, false); + + auto res = proj_create_operations(m_ctxt, source_crs, target_crs, ctxt); + ASSERT_NE(res, nullptr); + ObjListKeeper keeper_res(res); + + EXPECT_EQ(proj_list_get_count(res), 0); + } +} + +// --------------------------------------------------------------------------- + TEST_F(CApi, proj_context_set_database_path_null) { EXPECT_TRUE( |
