aboutsummaryrefslogtreecommitdiff
path: root/src/iso19111/factory.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-09-28 14:47:09 +0200
committerEven Rouault <even.rouault@spatialys.com>2021-09-28 14:47:09 +0200
commite6e6e4ca345e774910afa5bbe485c3d9f7851cd4 (patch)
treedd1cd3df30565228b932bbfc1d8d97e142111344 /src/iso19111/factory.cpp
parentf982d9d3104731727c445930bf14008d1c572d0a (diff)
downloadPROJ-e6e6e4ca345e774910afa5bbe485c3d9f7851cd4.tar.gz
PROJ-e6e6e4ca345e774910afa5bbe485c3d9f7851cd4.zip
Add a mapping for versioned authorities, so that one can use IAU:xxxx or IAU_2015:xxxx transparently
Diffstat (limited to 'src/iso19111/factory.cpp')
-rw-r--r--src/iso19111/factory.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp
index 94c2de2c..f08e32b9 100644
--- a/src/iso19111/factory.cpp
+++ b/src/iso19111/factory.cpp
@@ -754,6 +754,14 @@ struct DatabaseContext::Private {
// cppcheck-suppress functionStatic
void cache(const std::string &code, const GridInfoCache &info);
+ struct VersionedAuthName {
+ std::string versionedAuthName{};
+ std::string authName{};
+ std::string version{};
+ int priority = 0;
+ };
+ const std::vector<VersionedAuthName> &getCacheAuthNameWithVersion();
+
private:
friend class DatabaseContext;
@@ -795,6 +803,8 @@ struct DatabaseContext::Private {
lru11::Cache<std::string, std::list<std::string>> cacheAliasNames_{
CACHE_SIZE};
+ std::vector<VersionedAuthName> cacheAuthNameWithVersion_{};
+
static void insertIntoCache(LRUCacheOfObjects &cache,
const std::string &code,
const util::BaseObjectPtr &obj);
@@ -3558,6 +3568,87 @@ DatabaseContext::getNonDeprecated(const std::string &tableName,
// ---------------------------------------------------------------------------
+const std::vector<DatabaseContext::Private::VersionedAuthName> &
+DatabaseContext::Private::getCacheAuthNameWithVersion() {
+ if (cacheAuthNameWithVersion_.empty()) {
+ const auto sqlRes =
+ run("SELECT versioned_auth_name, auth_name, version, priority "
+ "FROM versioned_auth_name_mapping");
+ for (const auto &row : sqlRes) {
+ VersionedAuthName van;
+ van.versionedAuthName = row[0];
+ van.authName = row[1];
+ van.version = row[2];
+ van.priority = atoi(row[3].c_str());
+ cacheAuthNameWithVersion_.emplace_back(std::move(van));
+ }
+ }
+ return cacheAuthNameWithVersion_;
+}
+
+// ---------------------------------------------------------------------------
+
+// From IAU_2015 returns (IAU,2015)
+bool DatabaseContext::getAuthorityAndVersion(
+ const std::string &versionedAuthName, std::string &authNameOut,
+ std::string &versionOut) {
+
+ for (const auto &van : d->getCacheAuthNameWithVersion()) {
+ if (van.versionedAuthName == versionedAuthName) {
+ authNameOut = van.authName;
+ versionOut = van.version;
+ return true;
+ }
+ }
+ return false;
+}
+
+// ---------------------------------------------------------------------------
+
+// From IAU and 2015, returns IAU_2015
+bool DatabaseContext::getVersionedAuthority(const std::string &authName,
+ const std::string &version,
+ std::string &versionedAuthNameOut) {
+
+ for (const auto &van : d->getCacheAuthNameWithVersion()) {
+ if (van.authName == authName && van.version == version) {
+ versionedAuthNameOut = van.versionedAuthName;
+ return true;
+ }
+ }
+ return false;
+}
+
+// ---------------------------------------------------------------------------
+
+// From IAU returns IAU_latest, ... IAU_2015
+std::vector<std::string>
+DatabaseContext::getVersionedAuthoritiesFromName(const std::string &authName) {
+
+ typedef std::pair<std::string, int> VersionedAuthNamePriority;
+ std::vector<VersionedAuthNamePriority> tmp;
+ for (const auto &van : d->getCacheAuthNameWithVersion()) {
+ if (van.authName == authName) {
+ tmp.emplace_back(
+ VersionedAuthNamePriority(van.versionedAuthName, van.priority));
+ }
+ }
+ std::vector<std::string> res;
+ if (!tmp.empty()) {
+ // Sort by decreasing priority
+ std::sort(tmp.begin(), tmp.end(),
+ [](const VersionedAuthNamePriority &a,
+ const VersionedAuthNamePriority &b) {
+ return b.second > a.second;
+ });
+ for (const auto &pair : tmp)
+ res.emplace_back(pair.first);
+ }
+ return res;
+}
+
+// ---------------------------------------------------------------------------
+
std::vector<operation::CoordinateOperationNNPtr>
DatabaseContext::getTransformationsForGridName(
const DatabaseContextNNPtr &databaseContext, const std::string &gridName) {