From 3e7984f3b26e408e69b960f8e0d03b6ac0576188 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 16 Mar 2022 12:24:22 +0100 Subject: Transformation: no longer do vertical trasnformation when doing compound CRS to 2D CRS / add --3d to cs2cs Previously, when computing transformation between a compound CRS and a geographic/projected 2D CRS, the behaviour was similar to implicitly promoting the 2D CRS to 3D CRS in the pipeline computation logic, hence a geoid model could be applied. But note that when doing a geographic 3D to geographic/projected 2D CRS transformation, we *did* not do this implicit promotion and if a Helmert transformation existed between the datums, it was done only in 2D. So this is a bit inconsistent and triggered the comment in https://github.com/OSGeo/PROJ/issues/2318#issuecomment-1068924513 With this commit, we no longer do any vertical transformation when doing compound CRS to the 2D CRS, but just take the transformation of the horizontal part of the compound CRS to the 2D CRS. Said otherwise, NAD83+NAVD88 to NAD83 will no longer lead to the application of the geoid model. Unless you explicitly ask for the promotion NAD83 to 3D. Also related, in https://github.com/OSGeo/PROJ/issues/1563 that went to 6.3.0, I changed cs2cs to automatically promote to 3D the CRS as soon as one of them was compound, for the sake of being consistent with the past behaviour. But it then becomes difficult to predict PROJ behaviour depending on which level of it you consider... This commit undoes that and adds an explicit --3d switch to cs2cs, similarly to projinfo, to ask for promotion. Other bug fix found in the process, when using legacy syntax, +init=epsg:4979, (WGS 84 3D), the resulting CRS was 2D and not 3D. --- test/unit/test_network.cpp | 2 +- test/unit/test_operationfactory.cpp | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'test/unit') diff --git a/test/unit/test_network.cpp b/test/unit/test_network.cpp index f8b70ae8..73265008 100644 --- a/test/unit/test_network.cpp +++ b/test/unit/test_network.cpp @@ -1146,7 +1146,7 @@ TEST(networking, curl_vgridshift) { // WGS84 to EGM2008 height. Using egm08_25.tif auto P = - proj_create_crs_to_crs(ctx, "EPSG:4326", "EPSG:4326+3855", nullptr); + proj_create_crs_to_crs(ctx, "EPSG:4979", "EPSG:4326+3855", nullptr); ASSERT_NE(P, nullptr); PJ_COORD c; diff --git a/test/unit/test_operationfactory.cpp b/test/unit/test_operationfactory.cpp index 0c3ecae4..bb69e347 100644 --- a/test/unit/test_operationfactory.cpp +++ b/test/unit/test_operationfactory.cpp @@ -5441,7 +5441,9 @@ TEST(operation, compoundCRS_to_geogCRS_2D_promote_to_3D_context) { auto src = nn_dynamic_pointer_cast(srcObj); ASSERT_TRUE(src != nullptr); auto nnSrc = NN_NO_CHECK(src); - auto dst = authFactory->createCoordinateReferenceSystem("4269"); // NAD83 + auto dst = + authFactory->createCoordinateReferenceSystem("4269")->promoteTo3D( + std::string(), authFactory->databaseContext()); // NAD83 auto listCompoundToGeog2D = CoordinateOperationFactory::create()->createOperations(nnSrc, dst, @@ -5454,18 +5456,11 @@ TEST(operation, compoundCRS_to_geogCRS_2D_promote_to_3D_context) { CoordinateOperationFactory::create()->createOperations(dst, nnSrc, ctxt); EXPECT_EQ(listGeog2DToCompound.size(), listCompoundToGeog2D.size()); - - auto listCompoundToGeog3D = - CoordinateOperationFactory::create()->createOperations( - nnSrc, - dst->promoteTo3D(std::string(), authFactory->databaseContext()), - ctxt); - EXPECT_EQ(listCompoundToGeog3D.size(), listCompoundToGeog2D.size()); } // --------------------------------------------------------------------------- -TEST(operation, compoundCRS_of_projCRS_to_geogCRS_2D_context) { +TEST(operation, compoundCRS_of_projCRS_to_geogCRS_3D_context) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); @@ -5480,7 +5475,9 @@ TEST(operation, compoundCRS_of_projCRS_to_geogCRS_2D_context) { auto src = nn_dynamic_pointer_cast(srcObj); ASSERT_TRUE(src != nullptr); auto nnSrc = NN_NO_CHECK(src); - auto dst = authFactory->createCoordinateReferenceSystem("4269"); // NAD83 + auto dst = + authFactory->createCoordinateReferenceSystem("4269")->promoteTo3D( + std::string(), authFactory->databaseContext()); // NAD83 auto list = CoordinateOperationFactory::create()->createOperations( nnSrc, dst, ctxt); @@ -5945,7 +5942,9 @@ TEST(operation, compoundCRS_of_vertCRS_with_geoid_model_to_geogCRS) { createFromUserInput(wkt, authFactory->databaseContext(), false); auto src = nn_dynamic_pointer_cast(srcObj); ASSERT_TRUE(src != nullptr); - auto dst = authFactory->createCoordinateReferenceSystem("4269"); // NAD83 + auto dst = + authFactory->createCoordinateReferenceSystem("4269")->promoteTo3D( + std::string(), authFactory->databaseContext()); // NAD83 auto list = CoordinateOperationFactory::create()->createOperations( NN_NO_CHECK(src), dst, ctxt); @@ -6153,7 +6152,7 @@ TEST(operation, compoundCRS_with_non_meter_horiz_and_vertical_to_geog) { AuthorityFactory::create(DatabaseContext::create(), "EPSG"); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); auto list = CoordinateOperationFactory::create()->createOperations( - NN_NO_CHECK(src), authFactory->createCoordinateReferenceSystem("4326"), + NN_NO_CHECK(src), authFactory->createCoordinateReferenceSystem("4979"), ctxt); ASSERT_EQ(list.size(), 1U); // Check that vertical unit conversion is done just once -- cgit v1.2.3