Skip to content

Commit

Permalink
createFromUserInput(): parse compound id with two authorities, like E…
Browse files Browse the repository at this point in the history
…SRI:103668+EPSG:5703 (#2669)
  • Loading branch information
jjimenezshaw authored Apr 13, 2021
1 parent 58b991b commit a850aac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6424,6 +6424,30 @@ 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];

auto factory1 = AuthorityFactory::create(dbContextNNPtr, authName1);
auto crs1 = factory1->createCoordinateReferenceSystem(code1, false);
auto factory2 = AuthorityFactory::create(dbContextNNPtr, authName2);
auto crs2 = factory2->createCoordinateReferenceSystem(code2, false);
return CompoundCRS::createLax(
util::PropertyMap().set(IdentifiedObject::NAME_KEY,
crs1->nameStr() + " + " +
crs2->nameStr()),
{crs1, crs2}, dbContext);
}
}

if (starts_with(text, "urn:ogc:def:crs,")) {
Expand Down Expand Up @@ -6803,6 +6827,7 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text,
* <li> OGC URN combining references for compound coordinate reference systems
* e.g. "urn:ogc:def:crs,crs:EPSG::2393,crs:EPSG::5717"
* We also accept a custom abbreviated syntax EPSG:2393+5717
* or ESRI:103668+EPSG:5703
* </li>
* <li> OGC URN combining references for references for projected or derived
* CRSs
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

0 comments on commit a850aac

Please sign in to comment.