aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-11-28 00:07:18 +0100
committerEven Rouault <even.rouault@spatialys.com>2020-11-28 00:15:11 +0100
commit4de6f0bd24051ed60d9c0a98dbba1da376457f12 (patch)
tree9404b91022e079de90b2f80b8e0f84dc8220f3ba /src
parent24c3bbb299798db775ef10101ee8aa76f8320bbf (diff)
downloadPROJ-4de6f0bd24051ed60d9c0a98dbba1da376457f12.tar.gz
PROJ-4de6f0bd24051ed60d9c0a98dbba1da376457f12.zip
createObjectsFromName(): in exact match, make looking for 'ETRS89 / UTM zone 32N' return only the exact match
Diffstat (limited to 'src')
-rw-r--r--src/iso19111/factory.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp
index 03fd5267..7c9eac00 100644
--- a/src/iso19111/factory.cpp
+++ b/src/iso19111/factory.cpp
@@ -6155,6 +6155,8 @@ AuthorityFactory::createObjectsFromNameEx(
auto sqlRes = d->run(sql, params);
bool isFirst = true;
bool firstIsDeprecated = false;
+ bool foundExactMatch = false;
+ std::size_t hashCodeFirstMatch = 0;
for (const auto &row : sqlRes) {
const auto &name = row[3];
if (approximateMatch) {
@@ -6242,11 +6244,38 @@ AuthorityFactory::createObjectsFromNameEx(
}
throw std::runtime_error("Unsupported table_name");
};
- res.emplace_back(PairObjectName(getObject(table_name, code), name));
+ const auto obj = getObject(table_name, code);
+ if (metadata::Identifier::canonicalizeName(obj->nameStr()) ==
+ canonicalizedSearchedName) {
+ foundExactMatch = true;
+ }
+
+ const auto objPtr = obj.get();
+ if (res.empty()) {
+ hashCodeFirstMatch = typeid(*objPtr).hash_code();
+ } else if (hashCodeFirstMatch != typeid(*objPtr).hash_code()) {
+ hashCodeFirstMatch = 0;
+ }
+
+ res.emplace_back(PairObjectName(obj, name));
if (limitResultCount > 0 && res.size() == limitResultCount) {
break;
}
}
+
+ // If we found a name that is an exact match, and all objects have the
+ // same type, and we are not in approximate mode, only keep the objet(s)
+ // with the exact name match.
+ if (foundExactMatch && hashCodeFirstMatch != 0 && !approximateMatch) {
+ std::list<PairObjectName> resTmp;
+ for (const auto &pair : res) {
+ if (metadata::Identifier::canonicalizeName(
+ pair.first->nameStr()) == canonicalizedSearchedName) {
+ resTmp.emplace_back(pair);
+ }
+ }
+ res = std::move(resTmp);
+ }
}
auto sortLambda = [](const PairObjectName &a, const PairObjectName &b) {