From 0ba9d249136ec7adf6e3a44c8148701818d0e63e Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 3 Dec 2018 18:13:05 +0100 Subject: projinfo: add a --area option (refs #1188) --- src/factory.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/factory.cpp') diff --git a/src/factory.cpp b/src/factory.cpp index 91d0c478..7bc9c4d2 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -3642,7 +3642,7 @@ std::list AuthorityFactory::createObjectsFromName( const std::string &searchedName, const std::vector &allowedObjectTypes, bool approximateMatch, - size_t limitResultCount) { + size_t limitResultCount) const { std::string searchedNameWithoutDeprecated(searchedName); bool deprecated = false; @@ -3885,6 +3885,39 @@ AuthorityFactory::createObjectsFromName( // --------------------------------------------------------------------------- +/** \brief Return a list of area of use from their name + * + * @param name Searched name. + * @param approximateMatch Whether approximate name identification is allowed. + * @return list of (auth_name, code) of matched objects. + * @throw FactoryException + */ +std::list> +AuthorityFactory::listAreaOfUseFromName(const std::string &name, + bool approximateMatch) const { + std::string sql( + "SELECT auth_name, code FROM area WHERE deprecated = 0 AND "); + std::vector params; + if (!getAuthority().empty()) { + sql += " auth_name = ? AND "; + params.emplace_back(getAuthority()); + } + sql += "name LIKE ?"; + if (!approximateMatch) { + params.push_back(name); + } else { + params.push_back('%' + name + '%'); + } + auto sqlRes = d->run(sql, params); + std::list> res; + for (const auto &row : sqlRes) { + res.emplace_back(row[0], row[1]); + } + return res; +} + +// --------------------------------------------------------------------------- + //! @cond Doxygen_Suppress std::list AuthorityFactory::createEllipsoidFromExisting( const datum::EllipsoidNNPtr &ellipsoid) const { -- cgit v1.2.3