From 7f27b8d38c30118ff4fd5eddb1c9fcc6d94b40ea Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 30 Sep 2019 12:00:47 +0200 Subject: AuthorityFactory::getDescriptionText(): return CRS object in priority --- src/iso19111/factory.cpp | 23 +++++++++++++++++------ test/unit/test_factory.cpp | 5 +++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 9ecc0906..9be04580 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -3947,7 +3947,8 @@ AuthorityFactory::getAuthorityCodes(const ObjectType &type, /** \brief Gets a description of the object corresponding to a code. * * \note In case of several objects of different types with the same code, - * one of them will be arbitrarily selected. + * one of them will be arbitrarily selected. But if a CRS object is found, it + * will be selected. * * @param code Object code allocated by authority. (e.g. "4326") * @return description. @@ -3956,14 +3957,24 @@ AuthorityFactory::getAuthorityCodes(const ObjectType &type, */ std::string AuthorityFactory::getDescriptionText(const std::string &code) const { - auto sql = "SELECT name FROM object_view WHERE auth_name = ? AND code = " - "? ORDER BY table_name"; - auto res = d->runWithCodeParam(sql, code); - if (res.empty()) { + auto sql = "SELECT name, table_name FROM object_view WHERE auth_name = ? " + "AND code = ? ORDER BY table_name"; + auto sqlRes = d->runWithCodeParam(sql, code); + if (sqlRes.empty()) { throw NoSuchAuthorityCodeException("object not found", d->authority(), code); } - return res.front()[0]; + std::string text; + for (const auto &row : sqlRes) { + const auto &tableName = row[1]; + if (tableName == "geodetic_crs" || tableName == "projected_crs" || + tableName == "vertical_crs" || tableName == "compound_crs") { + return row[0]; + } else if (text.empty()) { + text = row[0]; + } + } + return text; } // --------------------------------------------------------------------------- diff --git a/test/unit/test_factory.cpp b/test/unit/test_factory.cpp index 881b7605..af1374bd 100644 --- a/test/unit/test_factory.cpp +++ b/test/unit/test_factory.cpp @@ -1324,6 +1324,11 @@ TEST(factory, AuthorityFactory_getDescriptionText) { NoSuchAuthorityCodeException); EXPECT_EQ(factory->getDescriptionText("10000"), "RGF93 to NGF IGN69 height (1)"); + + // Several objects have 4326 code, including an area of use, but return + // the CRS one. + EXPECT_EQ(factory->getDescriptionText("4326"), + "WGS 84"); } // --------------------------------------------------------------------------- -- cgit v1.2.3