From 9577f8e018a7fd3fe57fc934259f441cbf22cb1d Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 2 Dec 2018 22:27:51 +0100 Subject: identify: improve GeographicCRS identification when the CRS name has no match --- src/crs.cpp | 4 +++- test/unit/test_crs.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/crs.cpp b/src/crs.cpp index 21df43b4..699af09a 100644 --- a/src/crs.cpp +++ b/src/crs.cpp @@ -1329,6 +1329,7 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { } } } else { + bool gotAbove25Pct = false; for (int ipass = 0; ipass < 2; ipass++) { const bool approximateMatch = ipass == 1; auto objects = authorityFactory->createObjectsFromName( @@ -1348,6 +1349,7 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { metadata::Identifier::isEquivalentName( thisName.c_str(), crs->nameStr().c_str()); res.emplace_back(crsNN, eqName ? 90 : 70); + gotAbove25Pct = true; } else { res.emplace_back(crsNN, 25); } @@ -1356,7 +1358,7 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { break; } } - if (res.empty() && thisDatum) { + if (!gotAbove25Pct && thisDatum) { if (!thisDatum->identifiers().empty()) { searchByDatum(); } else { diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index 91ed145c..74f85d50 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -1974,6 +1974,28 @@ TEST(crs, projectedCRS_identify_db) { EXPECT_EQ(res.front().first->getEPSGCode(), 3044); EXPECT_EQ(res.front().second, 100); } + { + // Identify from a WKT ESRI with bad PROJCS and GEOGCS names. + auto obj = WKTParser().attachDatabaseContext(dbContext).createFromWKT( + "PROJCS[\"Lambert Conformal Conic\",GEOGCS[\"grs80\"," + "DATUM[\"D_North_American_1983\"," + "SPHEROID[\"Geodetic_Reference_System_1980\"," + "6378137,298.257222101]],PRIMEM[\"Greenwich\",0]," + "UNIT[\"Degree\",0.017453292519943295]]," + "PROJECTION[\"Lambert_Conformal_Conic\"]," + "PARAMETER[\"standard_parallel_1\",34.33333333333334]," + "PARAMETER[\"standard_parallel_2\",36.16666666666666]," + "PARAMETER[\"latitude_of_origin\",33.75]," + "PARAMETER[\"central_meridian\",-79]," + "PARAMETER[\"false_easting\",609601.22]," + "PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]"); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + auto res = crs->identify(factoryEPSG); + ASSERT_EQ(res.size(), 1); + EXPECT_EQ(res.front().first->getEPSGCode(), 32119); + EXPECT_EQ(res.front().second, 70); + } { // No equivalent CRS to input one in result set auto obj = -- cgit v1.2.3