From 67758b2c67ea329116b59818c038797667c4e1d1 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 26 Nov 2018 15:47:57 +0100 Subject: Redirect epsg:XXXX and IGNF:XXXX CRS expansions to the database, and remove the data/epsg and data/IGNF files --- src/factory.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/factory.cpp') diff --git a/src/factory.cpp b/src/factory.cpp index 3c360d13..f58b66a0 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -157,6 +157,8 @@ struct DatabaseContext::Private { }; private: + friend class DatabaseContext; + std::string databasePath_{}; bool close_handle_ = true; sqlite3 *sqlite_handle_{}; @@ -164,6 +166,7 @@ struct DatabaseContext::Private { PJ_CONTEXT *pjCtxt_ = nullptr; int recLevel_ = 0; bool detach_ = false; + std::string lastMetadataValue_{}; void closeDB(); @@ -704,6 +707,22 @@ const std::string &DatabaseContext::getPath() const { return d->getPath(); } // --------------------------------------------------------------------------- +/** \brief Return a metadata item. + * + * Value remains valid while this is alive and to the next call to getMetadata + */ +const char *DatabaseContext::getMetadata(const char *key) const { + auto res = + d->run("SELECT value FROM metadata WHERE key = ?", {std::string(key)}); + if (res.empty()) { + return nullptr; + } + d->lastMetadataValue_ = res[0][0]; + return d->lastMetadataValue_.c_str(); +} + +// --------------------------------------------------------------------------- + //! @cond Doxygen_Suppress DatabaseContextNNPtr DatabaseContext::create(void *sqlite_handle) { -- cgit v1.2.3 From ba111ac8323ff194039a06db87d1fb17ed8175b3 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 3 Dec 2018 16:44:21 +0100 Subject: Export to ESRI WKT: make it use verbatim WKT definition from the database when possible --- src/factory.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/factory.cpp') diff --git a/src/factory.cpp b/src/factory.cpp index f58b66a0..91d0c478 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -852,6 +852,29 @@ DatabaseContext::getAliasFromOfficialName(const std::string &officialName, return res[0][0]; } +// --------------------------------------------------------------------------- + +/** \brief Return the 'text_definition' column of a table for an object + * + * @param tableName Table name/category. + * @param authName Authority name of the object. + * @param code Code of the object + * @return Text definition (or empty) + * @throw FactoryException + */ +std::string DatabaseContext::getTextDefinition(const std::string &tableName, + const std::string &authName, + const std::string &code) const { + std::string sql("SELECT text_definition FROM \""); + sql += replaceAll(tableName, "\"", "\"\""); + sql += "\" WHERE auth_name = ? AND code = ?"; + auto res = d->run(sql, {authName, code}); + if (res.empty()) { + return std::string(); + } + return res[0][0]; +} + //! @endcond // --------------------------------------------------------------------------- @@ -3807,6 +3830,11 @@ AuthorityFactory::createObjectsFromName( break; } } + if (res.empty() && !deprecated) { + return createObjectsFromName(searchedName + " (deprecated)", + allowedObjectTypes, approximateMatch, + limitResultCount); + } auto sortLambda = [](const common::IdentifiedObjectNNPtr &a, const common::IdentifiedObjectNNPtr &b) { -- cgit v1.2.3