From f0d6b64fee8b796ec038929187b7b725f62a5ba8 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 12 Mar 2020 23:10:20 +0100 Subject: Add proj_get_suggested_operation() Return the index of the operation that would be the most appropriate to transform the specified coordinates. This operation may use resources that are not locally available, depending on the search criteria used by proj_create_operations(). This could be done by using proj_create_operations() with a punctual bounding box, but this function is faster when one needs to evaluate on many points with the same (source_crs, target_crs) tuple. --- test/unit/test_c_api.cpp | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'test/unit/test_c_api.cpp') diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index 0f1b906e..f274af57 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -1348,12 +1348,36 @@ TEST_F(CApi, proj_create_operations) { EXPECT_EQ(proj_list_get(m_ctxt, res, -1), nullptr); EXPECT_EQ(proj_list_get(m_ctxt, res, proj_list_get_count(res)), nullptr); - auto op = proj_list_get(m_ctxt, res, 0); - ASSERT_NE(op, nullptr); - ObjectKeeper keeper_op(op); - EXPECT_FALSE(proj_coordoperation_has_ballpark_transformation(m_ctxt, op)); + { + auto op = proj_list_get(m_ctxt, res, 0); + ASSERT_NE(op, nullptr); + ObjectKeeper keeper_op(op); + EXPECT_FALSE( + proj_coordoperation_has_ballpark_transformation(m_ctxt, op)); + EXPECT_EQ(proj_get_name(op), std::string("NAD27 to NAD83 (3)")); + } + + { + PJ_COORD coord; + coord.xy.x = 40; + coord.xy.y = -100; + int idx = proj_get_suggested_operation(m_ctxt, res, PJ_FWD, coord); + ASSERT_GE(idx, 0); + ASSERT_LT(idx, proj_list_get_count(res)); + auto op = proj_list_get(m_ctxt, res, idx); + ASSERT_NE(op, nullptr); + ObjectKeeper keeper_op(op); + // Transformation for USA + EXPECT_EQ(proj_get_name(op), std::string("NAD27 to NAD83 (1)")); + } - EXPECT_EQ(proj_get_name(op), std::string("NAD27 to NAD83 (3)")); + { + PJ_COORD coord; + coord.xy.x = 40; + coord.xy.y = 10; + int idx = proj_get_suggested_operation(m_ctxt, res, PJ_FWD, coord); + EXPECT_GE(idx, -1); + } } // --------------------------------------------------------------------------- -- cgit v1.2.3