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

[Backport 6.2] createOperations(): fix conversion from/to PROJ.4 CRS strings with non-ISO-cosher options and towgs84/nadgrids #1606

Merged
merged 1 commit into from
Sep 12, 2019
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
19 changes: 13 additions & 6 deletions src/iso19111/coordinateoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12048,14 +12048,23 @@ CoordinateOperationFactory::Private::createOperations(
std::vector<CoordinateOperationNNPtr> res;
const bool allowEmptyIntersection = true;

const auto &sourceProj4Ext = sourceCRS->getExtensionProj4();
const auto &targetProj4Ext = targetCRS->getExtensionProj4();
auto boundSrc = dynamic_cast<const crs::BoundCRS *>(sourceCRS.get());
auto boundDst = dynamic_cast<const crs::BoundCRS *>(targetCRS.get());

const auto &sourceProj4Ext = boundSrc
? boundSrc->baseCRS()->getExtensionProj4()
: sourceCRS->getExtensionProj4();
const auto &targetProj4Ext = boundDst
? boundDst->baseCRS()->getExtensionProj4()
: targetCRS->getExtensionProj4();
if (!sourceProj4Ext.empty() || !targetProj4Ext.empty()) {

auto sourceProjExportable =
dynamic_cast<io::IPROJStringExportable *>(sourceCRS.get());
dynamic_cast<const io::IPROJStringExportable *>(
boundSrc ? boundSrc : sourceCRS.get());
auto targetProjExportable =
dynamic_cast<io::IPROJStringExportable *>(targetCRS.get());
dynamic_cast<const io::IPROJStringExportable *>(
boundDst ? boundDst : targetCRS.get());
if (!sourceProjExportable) {
throw InvalidOperation("Source CRS is not PROJ exportable");
}
Expand Down Expand Up @@ -12284,7 +12293,6 @@ CoordinateOperationFactory::Private::createOperations(
return applyInverse(createOperations(targetCRS, sourceCRS, context));
}

auto boundSrc = dynamic_cast<const crs::BoundCRS *>(sourceCRS.get());
auto geogDst = dynamic_cast<const crs::GeographicCRS *>(targetCRS.get());
if (boundSrc && geogDst) {
const auto &hubSrc = boundSrc->hubCRS();
Expand Down Expand Up @@ -12474,7 +12482,6 @@ CoordinateOperationFactory::Private::createOperations(
}

// reverse of previous case
auto boundDst = dynamic_cast<const crs::BoundCRS *>(targetCRS.get());
auto geogSrc = dynamic_cast<const crs::GeographicCRS *>(sourceCRS.get());
if (geogSrc && boundDst) {
return applyInverse(createOperations(targetCRS, sourceCRS, context));
Expand Down
24 changes: 24 additions & 0 deletions test/unit/test_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7187,6 +7187,30 @@ TEST(operation,

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

TEST(
operation,
createOperation_fallback_to_proj4_strings_regular_to_projliteral_with_towgs84) {
auto objSrc =
createFromUserInput("EPSG:4326", DatabaseContext::create(), false);
auto src = nn_dynamic_pointer_cast<CRS>(objSrc);
ASSERT_TRUE(src != nullptr);

auto objDst = PROJStringParser().createFromPROJString(
"+proj=utm +zone=31 +ellps=GRS80 +towgs84=1,2,3 +over +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=axisswap +order=2,1 "
"+step +proj=unitconvert +xy_in=deg +xy_out=rad "
"+step +proj=utm +zone=31 +ellps=GRS80 +towgs84=1,2,3 +over");
}

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

TEST(operation, createOperation_on_crs_with_bound_crs_and_wktext) {
auto objSrc = PROJStringParser().createFromPROJString(
"+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 "
Expand Down