Skip to content

Commit

Permalink
Merge pull request #3373 from OSGeo/backport-3371-to-9.1
Browse files Browse the repository at this point in the history
[Backport 9.1] createFromUserInput(): make it work better when approximate name is provided
  • Loading branch information
rouault authored Oct 9, 2022
2 parents cc6693a + 36ff062 commit 5ed73e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7329,6 +7329,24 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text,
}
}

// If there's exactly only one object whose name is equivalent
// to the user input, return it.
IdentifiedObjectPtr identifiedObj;
for (const auto &obj : res) {
if (Identifier::isEquivalentName(obj->nameStr().c_str(),
objectName.c_str())) {
if (identifiedObj == nullptr) {
identifiedObj = obj.as_nullable();
} else {
identifiedObj = nullptr;
break;
}
}
}
if (identifiedObj) {
return identifiedObj;
}

std::string msg("several objects matching this name: ");
bool first = true;
for (const auto &obj : res) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11911,6 +11911,14 @@ TEST(io, createFromUserInput) {
EXPECT_NO_THROW(createFromUserInput("WGS84 UTM zone 31N", dbContext));
EXPECT_NO_THROW(createFromUserInput("ID74", dbContext));

{
// Approximate match of a vertical CRS
auto obj = createFromUserInput("NGF IGN69 height", dbContext);
auto crs = nn_dynamic_pointer_cast<VerticalCRS>(obj);
EXPECT_TRUE(crs != nullptr);
EXPECT_EQ(crs->nameStr(), "NGF-IGN69 height");
}

{
// Exact match on each piece of the compound CRS
auto obj = createFromUserInput("WGS 84 + EGM96 height", dbContext);
Expand Down

0 comments on commit 5ed73e5

Please sign in to comment.