diff options
| author | Matt Littlemore <matthew520@live.com.au> | 2019-07-19 17:15:25 +0800 |
|---|---|---|
| committer | Kristian Evers <kristianevers@gmail.com> | 2019-07-19 11:15:25 +0200 |
| commit | 0fc4242ee5ae808fb998482e82da07c2b3b0b33e (patch) | |
| tree | e18a8139fe030f991f8de6a05ac33dcbe2a57f25 | |
| parent | f65c61a8fd268a7ff2536194881290ded61892a6 (diff) | |
| download | PROJ-0fc4242ee5ae808fb998482e82da07c2b3b0b33e.tar.gz PROJ-0fc4242ee5ae808fb998482e82da07c2b3b0b33e.zip | |
Add set discard superseded method to api (#1534)
Closes #1519
| -rw-r--r-- | scripts/reference_exported_symbols.txt | 1 | ||||
| -rw-r--r-- | src/iso19111/c_api.cpp | 22 | ||||
| -rw-r--r-- | src/iso19111/coordinateoperation.cpp | 3 | ||||
| -rw-r--r-- | src/proj.h | 5 | ||||
| -rw-r--r-- | test/unit/test_c_api.cpp | 66 |
5 files changed, 96 insertions, 1 deletions
diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt index f3d13bd7..bdfdd475 100644 --- a/scripts/reference_exported_symbols.txt +++ b/scripts/reference_exported_symbols.txt @@ -948,6 +948,7 @@ proj_operation_factory_context_set_allow_use_intermediate_crs proj_operation_factory_context_set_area_of_interest proj_operation_factory_context_set_crs_extent_use proj_operation_factory_context_set_desired_accuracy +proj_operation_factory_context_set_discard_superseded proj_operation_factory_context_set_grid_availability_use proj_operation_factory_context_set_spatial_criterion proj_operation_factory_context_set_use_proj_alternative_grid_names diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index 7a77ccfb..a125261a 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -6578,6 +6578,28 @@ void proj_operation_factory_context_set_allowed_intermediate_crs( // --------------------------------------------------------------------------- +/** \brief Set whether transformations that are superseded (but not deprecated) + * should be discarded. + * + * @param ctx PROJ context, or NULL for default context + * @param factory_ctx Operation factory context. must not be NULL + * @param discard superseded crs or not + */ +void PROJ_DLL proj_operation_factory_context_set_discard_superseded( + PJ_CONTEXT *ctx, PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, + int discard) { + SANITIZE_CTX(ctx); + assert(factory_ctx); + try { + factory_ctx->operationContext->setDiscardSuperseded(discard != 0); + } catch (const std::exception &e) { + proj_log_error(ctx, __FUNCTION__, e.what()); + } +} + + +// --------------------------------------------------------------------------- + /** \brief Find a list of CoordinateOperation from source_crs to target_crs. * * The operations are sorted with the most relevant ones first: by diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp index 7f3a2137..822f5822 100644 --- a/src/iso19111/coordinateoperation.cpp +++ b/src/iso19111/coordinateoperation.cpp @@ -10238,7 +10238,8 @@ struct FilterResults { // results // ... removeSyntheticNullTransforms(); - removeUninterestingOps(); + if (context->getDiscardSuperseded()) + removeUninterestingOps(); removeDuplicateOps(); removeSyntheticNullTransforms(); return *this; @@ -941,6 +941,11 @@ void PROJ_DLL proj_operation_factory_context_set_allowed_intermediate_crs( PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, const char* const *list_of_auth_name_codes); +void PROJ_DLL proj_operation_factory_context_set_discard_superseded( + PJ_CONTEXT *ctx, + PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, + int discard); + /* ------------------------------------------------------------------------- */ diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index bfbae1a5..e2d013b1 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -1352,6 +1352,72 @@ TEST_F(CApi, proj_create_operations) { // --------------------------------------------------------------------------- +TEST_F(CApi, proj_create_operations_discard_superseded) { + 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", "4203", PJ_CATEGORY_CRS, false, nullptr); // AGD84 + ASSERT_NE(source_crs, nullptr); + ObjectKeeper keeper_source_crs(source_crs); + + auto target_crs = proj_create_from_database( + m_ctxt, "EPSG", "4326", PJ_CATEGORY_CRS, false, nullptr); // WGS84 + 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); + + proj_operation_factory_context_set_discard_superseded( + 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), 2); + } + +// --------------------------------------------------------------------------- + +TEST_F(CApi, proj_create_operations_dont_discard_superseded) { + 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", "4203", PJ_CATEGORY_CRS, false, nullptr); // AGD84 + ASSERT_NE(source_crs, nullptr); + ObjectKeeper keeper_source_crs(source_crs); + + auto target_crs = proj_create_from_database( + m_ctxt, "EPSG", "4326", PJ_CATEGORY_CRS, false, nullptr); // WGS84 + 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); + + proj_operation_factory_context_set_discard_superseded( + 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), 5); + } + +// --------------------------------------------------------------------------- + TEST_F(CApi, proj_create_operations_with_pivot) { auto source_crs = proj_create_from_database( |
