Skip to content

Commit

Permalink
createOperations(): fix incorrect height transformation between 3D pr…
Browse files Browse the repository at this point in the history
…omoted RGF93 and CH1903+ (fixes OSGeo#2541)
  • Loading branch information
rouault committed Mar 5, 2021
1 parent f278b5b commit 3086152
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/iso19111/operation/coordinateoperationfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2665,12 +2665,40 @@ void CoordinateOperationFactory::Private::createOperationsWithDatumPivot(
}
}
if (sourceAndTargetAre3D) {
opSecondCloned->getPrivate()->use3DHelmert_ = true;
auto invCO = dynamic_cast<InverseCoordinateOperation *>(
opSecondCloned.get());
if (invCO) {
auto invCOForward = invCO->forwardOperation().get();
invCOForward->getPrivate()->use3DHelmert_ = true;

// Force Helmert operations to use the 3D domain, even if the
// ones we found in EPSG are advertized for the 2D domain.
auto concat =
dynamic_cast<ConcatenatedOperation *>(opSecondCloned.get());
if (concat) {
std::vector<CoordinateOperationNNPtr> newSteps;
for (const auto &step : concat->operations()) {
auto newStep = step->shallowClone();
newStep->getPrivate()->use3DHelmert_ = true;
auto invCO = dynamic_cast<InverseCoordinateOperation *>(
newStep.get());
if (invCO) {
auto invCOForward = invCO->forwardOperation().get();
invCOForward->getPrivate()->use3DHelmert_ = true;
}
setCRSs(newStep.get(),
newStep->sourceCRS()->promoteTo3D(std::string(),
dbContext),
newStep->targetCRS()->promoteTo3D(std::string(),
dbContext));
newSteps.emplace_back(newStep);
}
opSecondCloned =
ConcatenatedOperation::createComputeMetadata(
newSteps, disallowEmptyIntersection);
} else {
opSecondCloned->getPrivate()->use3DHelmert_ = true;
auto invCO = dynamic_cast<InverseCoordinateOperation *>(
opSecondCloned.get());
if (invCO) {
auto invCOForward = invCO->forwardOperation().get();
invCOForward->getPrivate()->use3DHelmert_ = true;
}
}
}
if (isNullFirst) {
Expand Down
41 changes: 41 additions & 0 deletions test/unit/test_operationfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,47 @@ TEST(operation, geocentricCRS_to_geogCRS_different_datum_context) {

// ---------------------------------------------------------------------------

TEST(operation, geogCRS_3D_to_geogCRS_3D_different_datum_context) {
// Test for https://github.com/OSGeo/PROJ/issues/2541
auto dbContext = DatabaseContext::create();
auto authFactory = AuthorityFactory::create(dbContext, "EPSG");
auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0);
ctxt->setSpatialCriterion(
CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION);
auto list = CoordinateOperationFactory::create()->createOperations(
// RGF93 (3D)
authFactory->createCoordinateReferenceSystem("4965"),
// CH1903+ promoted to 3D
authFactory->createCoordinateReferenceSystem("4150")->promoteTo3D(
std::string(), dbContext),
ctxt);
ASSERT_GE(list.size(), 1U);
EXPECT_EQ(list[0]->nameStr(),
"RGF93 to ETRS89 (1) + Inverse of CH1903+ to ETRS89 (1)");
// Check that there is no +push +v_3
EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()),
"+proj=pipeline "
"+step +proj=axisswap +order=2,1 "
"+step +proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m "
"+step +proj=cart +ellps=GRS80 "
"+step +proj=helmert +x=-674.374 +y=-15.056 +z=-405.346 "
"+step +inv +proj=cart +ellps=bessel "
"+step +proj=unitconvert +xy_in=rad +z_in=m +xy_out=deg +z_out=m "
"+step +proj=axisswap +order=2,1");
EXPECT_EQ(list[0]->inverse()->exportToPROJString(
PROJStringFormatter::create().get()),
"+proj=pipeline "
"+step +proj=axisswap +order=2,1 "
"+step +proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m "
"+step +proj=cart +ellps=bessel "
"+step +proj=helmert +x=674.374 +y=15.056 +z=405.346 "
"+step +inv +proj=cart +ellps=GRS80 "
"+step +proj=unitconvert +xy_in=rad +z_in=m +xy_out=deg +z_out=m "
"+step +proj=axisswap +order=2,1");
}

// ---------------------------------------------------------------------------

TEST(operation, esri_projectedCRS_to_geogCRS_with_ITRF_intermediate_context) {
auto dbContext = DatabaseContext::create();
auto authFactoryEPSG = AuthorityFactory::create(dbContext, "EPSG");
Expand Down

0 comments on commit 3086152

Please sign in to comment.