Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createOperations(): fix projected CRS with non-metre horiz&vertical unit and towgs84 to gencentric CRS (fixes #3229) #3231

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/iso19111/operation/conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4083,11 +4083,6 @@ void Conversion::_exportToPROJString(
const auto &components = compound->componentReferenceSystems();
if (!components.empty()) {
horiz = components.front().get();
const auto boundCRS =
dynamic_cast<const crs::BoundCRS *>(horiz);
if (boundCRS) {
horiz = boundCRS->baseCRS().get();
}
}
}

Expand All @@ -4110,6 +4105,13 @@ void Conversion::_exportToPROJString(
}

auto projCRS = dynamic_cast<const crs::ProjectedCRS *>(horiz);
if (projCRS == nullptr) {
auto boundCRS = dynamic_cast<const crs::BoundCRS *>(horiz);
if (boundCRS) {
projCRS = dynamic_cast<const crs::ProjectedCRS *>(
boundCRS->baseCRS().get());
}
}
if (projCRS) {
formatter->pushOmitZUnitConversion();
projCRS->addUnitConvertAndAxisSwap(formatter, bAxisSpecFound);
Expand Down
22 changes: 22 additions & 0 deletions test/unit/test_operationfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2783,6 +2783,28 @@ TEST(operation, boundCRS_of_projCRS_towgs84_to_boundCRS_of_projCRS_nadgrids) {

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

TEST(operation, boundCRS_of_projCRS_towgs84_non_metre_unit_to_geocentric) {
auto objSrc = PROJStringParser().createFromPROJString(
"+proj=merc +ellps=GRS80 +towgs84=0,0,0 +units=ft +vunits=ft "
"+type=crs");
auto src = nn_dynamic_pointer_cast<CRS>(objSrc);
ASSERT_TRUE(src != nullptr);
auto objDst = PROJStringParser().createFromPROJString(
"+proj=geocent +datum=WGS84 +type=crs");
auto dst = nn_dynamic_pointer_cast<CRS>(objDst);
ASSERT_TRUE(dst != nullptr);
auto op = CoordinateOperationFactory::create()->createOperation(
NN_CHECK_ASSERT(src), NN_CHECK_ASSERT(dst));
ASSERT_TRUE(op != nullptr);
EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
"+proj=pipeline "
"+step +proj=unitconvert +xy_in=ft +z_in=ft +xy_out=m +z_out=m "
"+step +inv +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=GRS80 "
"+step +proj=cart +ellps=WGS84");
}

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

static CRSNNPtr buildCRSFromProjStrThroughWKT(const std::string &projStr) {
auto crsFromProj = nn_dynamic_pointer_cast<CRS>(
PROJStringParser().createFromPROJString(projStr));
Expand Down