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

BoundCRS::identify(): avoid incompatible transformation for WKT1 / TOWGS84 export (fixes OSGeo/gdal#3958) #2747

Merged
merged 1 commit into from
Jun 10, 2021
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
10 changes: 9 additions & 1 deletion src/iso19111/crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include "proj/internal/internal.hpp"
#include "proj/internal/io_internal.hpp"

#include "operation/oputils.hpp"

#include "proj_constants.h"
#include "proj_json_streaming_writer.hpp"

Expand Down Expand Up @@ -5519,7 +5521,13 @@ BoundCRS::_identify(const io::AuthorityFactoryPtr &authorityFactory) const {
auto opNormalized = op->normalizeForVisualization();
std::string opTransfPROJString;
bool opTransfPROJStringValid = false;
if (op->nameStr().find("Ballpark geographic") == 0) {
const auto &opName = op->nameStr();
if (starts_with(opName,
osgeo::proj::operation::
BALLPARK_GEOCENTRIC_TRANSLATION) ||
starts_with(
opName,
osgeo::proj::operation::NULL_GEOGRAPHIC_OFFSET)) {
if (refIsNullTransform) {
res.emplace_back(create(candidateBaseCRS,
d->hubCRS_,
Expand Down
26 changes: 23 additions & 3 deletions test/unit/test_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4646,9 +4646,10 @@ TEST(crs, boundCRS_identify_db) {
auto res = crs->identify(factoryEPSG);
ASSERT_EQ(res.size(), 1U);
EXPECT_EQ(res.front().second, 25);
auto wkt = crs->exportToWKT(
WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get());
EXPECT_TRUE(wkt.find("32122") != std::string::npos) << wkt;
auto boundCRS = dynamic_cast<const BoundCRS *>(res.front().first.get());
ASSERT_TRUE(boundCRS != nullptr);
EXPECT_EQ(boundCRS->baseCRS()->getEPSGCode(), 32122);
EXPECT_EQ(boundCRS->transformation()->method()->getEPSGCode(), 9603);
}

{
Expand All @@ -4665,6 +4666,25 @@ TEST(crs, boundCRS_identify_db) {
EXPECT_EQ(boundCRS->baseCRS()->getEPSGCode(), 3148);
EXPECT_EQ(res.front().second, 70);
}

{
// Identify a WKT with datum WGS84 and TOWGS84
auto obj = WKTParser().attachDatabaseContext(dbContext).createFromWKT(
"GEOGCS[\"WGS84 Coordinate System\",DATUM[\"WGS 1984\","
"SPHEROID[\"WGS 1984\",6378137,298.257223563],"
"TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],"
"PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433],"
"AUTHORITY[\"EPSG\",\"4326\"]]");
auto crs = nn_dynamic_pointer_cast<BoundCRS>(obj);
ASSERT_TRUE(crs != nullptr);
auto res = crs->identify(factoryEPSG);
ASSERT_EQ(res.size(), 1U);
EXPECT_EQ(res.front().second, 100);
auto boundCRS = dynamic_cast<const BoundCRS *>(res.front().first.get());
ASSERT_TRUE(boundCRS != nullptr);
EXPECT_EQ(boundCRS->baseCRS()->getEPSGCode(), 4326);
EXPECT_EQ(boundCRS->transformation()->method()->getEPSGCode(), 9606);
}
}

// ---------------------------------------------------------------------------
Expand Down