From aeb024f2df5fb1c4d83959b6b9edcb62e8385226 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 17 Sep 2020 18:34:06 +0200 Subject: Adjust createBoundCRSToWGS84IfPossible() and operation filtering (for POSGAR 2007 to WGS84 issues) (fixes #2356) - We make createBoundCRSToWGS84IfPossible() more restrictive. If there are more than one Helmert transformation from the CRS to WGS 84 covering the area of use of the CRS, we do not create a BoundCRS / +towgs84 - In createOperations() filtering, we are less aggressive in discarding operations that have the same area of use but worse accuracy. We do it only if they involve more transformation steps. We now get: ``` $ projinfo EPSG:5340 -o PROJ PROJ.4 string: +proj=longlat +ellps=GRS80 +no_defs +type=crs $ projinfo -s EPSG:5340 -t EPSG:4326 --spatial-test intersects --summary Candidate operations found: 2 EPSG:9264, POSGAR 2007 to WGS 84 (2), 0.5 m, Argentina EPSG:5351, POSGAR 2007 to WGS 84 (1), 1.0 m, Argentina ``` --- test/unit/test_crs.cpp | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'test/unit/test_crs.cpp') diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index caee0646..0e340560 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -5422,40 +5422,18 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { { // Pulkovo 42 Romania auto crs_3844 = factory->createCoordinateReferenceSystem("3844"); - auto bound = crs_3844->createBoundCRSToWGS84IfPossible( - dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); - EXPECT_NE(bound, crs_3844); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + EXPECT_EQ(crs_3844->createBoundCRSToWGS84IfPossible( dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER), - bound); - auto boundCRS = nn_dynamic_pointer_cast(bound); - ASSERT_TRUE(boundCRS != nullptr); - EXPECT_EQ( - boundCRS->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=sterea +lat_0=46 +lon_0=25 +k=0.99975 +x_0=500000 " - "+y_0=500000 +ellps=krass " - "+towgs84=2.329,-147.042,-92.08,-0.309,0.325,0.497,5.69 " - "+units=m +no_defs +type=crs"); + crs_3844); } { // Pulkovo 42 Poland auto crs_2171 = factory->createCoordinateReferenceSystem("2171"); - auto bound = crs_2171->createBoundCRSToWGS84IfPossible( - dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); - EXPECT_NE(bound, crs_2171); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + EXPECT_EQ(crs_2171->createBoundCRSToWGS84IfPossible( dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER), - bound); - auto boundCRS = nn_dynamic_pointer_cast(bound); - ASSERT_TRUE(boundCRS != nullptr); - EXPECT_EQ( - boundCRS->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=sterea +lat_0=50.625 +lon_0=21.0833333333333 " - "+k=0.9998 +x_0=4637000 +y_0=5647000 +ellps=krass " - "+towgs84=33.4,-146.6,-76.3,-0.359,-0.053,0.844,-0.84 " - "+units=m +no_defs +type=crs"); + crs_2171); } { // NTF (Paris) @@ -5547,6 +5525,15 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { ::testing::UnitTest::GetInstance()->elapsed_time(); EXPECT_LE(time_after - time_before, 500); } + { + // POSGAR 2007: it has 2 helmert shifts to WGS84 (#2356). Don't take + // an arbitrary one + auto crs_5340 = factory->createCoordinateReferenceSystem("5340"); + EXPECT_EQ(crs_5340->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), + crs_5340); + } } // --------------------------------------------------------------------------- -- cgit v1.2.3