Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse compound id with two authorities, like ESRI:103668+EPSG:5703 #2669

Merged
merged 3 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6424,6 +6424,46 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text,
}
throw;
}
} else if (tokens.size() == 3) {
// ESRI:103668+EPSG:5703 ... compound
auto tokensCenter = split(tokens[1], '+');
if (tokensCenter.size() == 2) {
if (!dbContext) {
throw ParsingException("no database context specified");
}
DatabaseContextNNPtr dbContextNNPtr(NN_NO_CHECK(dbContext));

const auto &authName1 = tokens[0];
const auto &code1 = tokensCenter[0];
const auto &authName2 = tokensCenter[1];
const auto &code2 = tokens[2];

crs::CRSPtr crs1 = nullptr;
crs::CRSPtr crs2 = nullptr;

const auto authorities = dbContextNNPtr->getAuthorities();
for (const auto &authCandidate : authorities) {
if (ci_equal(authCandidate, authName1)) {
auto factory =
AuthorityFactory::create(dbContextNNPtr, authCandidate);
crs1 =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some compilers require an explict .as_nullable() to cast from a non-null shared pointed to a regular one. But here the best option would probably be to just assign the real authority names to a std::string and then do like the tokens.size() == 2 case avoid the non-null test on crs1 / crs2.
Actually you could skip the ci_equal() test and just use what the user provides. The case-insensitive comparison in the tokens.size() == 2 case was done because of legacy practice of using "epsg:XXXX", but here for a new supported syntax we can be stricter. That will make the code simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Without ci_equal the code is much simpler.

Copy link
Contributor Author

@jjimenezshaw jjimenezshaw Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, projinfo esri:103668+epsg:5703 does work perfectly. However projinfo ogc:CRS84+EPSG:5773 fails. (something that somehow I noticed with --list-crs)

AuthorityFactory::create does a ci_equal for EPSG, ESRI and PROJ.

factory->createCoordinateReferenceSystem(code1, false);
}
if (ci_equal(authCandidate, authName2)) {
auto factory =
AuthorityFactory::create(dbContextNNPtr, authCandidate);
crs2 =
factory->createCoordinateReferenceSystem(code2, false);
}
}
if (crs1 && crs2) {
return CompoundCRS::createLax(
util::PropertyMap().set(IdentifiedObject::NAME_KEY,
crs1->nameStr() + " + " +
crs2->nameStr()),
{NN_NO_CHECK(crs1), NN_NO_CHECK(crs2)}, dbContext);
}
}
}

if (starts_with(text, "urn:ogc:def:crs,")) {
Expand Down
22 changes: 22 additions & 0 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10307,6 +10307,8 @@ TEST(io, createFromUserInput) {
EXPECT_THROW(createFromUserInput("+proj=unhandled +type=crs", nullptr),
ParsingException);
EXPECT_THROW(createFromUserInput("EPSG:4326", nullptr), ParsingException);
EXPECT_THROW(createFromUserInput("ESRI:103668+EPSG:5703", nullptr),
ParsingException);
EXPECT_THROW(
createFromUserInput("urn:ogc:def:unhandled:EPSG::4326", dbContext),
ParsingException);
Expand Down Expand Up @@ -10386,6 +10388,26 @@ TEST(io, createFromUserInput) {
EXPECT_EQ(crs->nameStr(),
"KKJ / Finland Uniform Coordinate System + N60 height");
}

{
auto obj = createFromUserInput("EPSG:2393+EPSG:5717", dbContext);
auto crs = nn_dynamic_pointer_cast<CompoundCRS>(obj);
ASSERT_TRUE(crs != nullptr);
EXPECT_EQ(crs->nameStr(),
"KKJ / Finland Uniform Coordinate System + N60 height");
}
{
auto obj = createFromUserInput("ESRI:103668+EPSG:5703", dbContext);
auto crs = nn_dynamic_pointer_cast<CompoundCRS>(obj);
ASSERT_TRUE(crs != nullptr);
EXPECT_EQ(crs->nameStr(),
"NAD_1983_HARN_Adj_MN_Ramsey_Meters + NAVD88 height");
}
EXPECT_THROW(createFromUserInput("ESRI:42+EPSG:5703", dbContext),
NoSuchAuthorityCodeException);
EXPECT_THROW(createFromUserInput("ESRI:103668+EPSG:999999", dbContext),
NoSuchAuthorityCodeException);

{
auto obj = createFromUserInput(
"urn:ogc:def:crs,crs:EPSG::2393,crs:EPSG::5717", dbContext);
Expand Down