From a850aac5e0de3f86f2e4cf29f211e88744db5133 Mon Sep 17 00:00:00 2001 From: Javier Jimenez Shaw Date: Tue, 13 Apr 2021 14:48:35 +0200 Subject: [PATCH] createFromUserInput(): parse compound id with two authorities, like ESRI:103668+EPSG:5703 (#2669) --- src/iso19111/io.cpp | 25 +++++++++++++++++++++++++ test/unit/test_io.cpp | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index d4b3dcb04b..c59e21f48c 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -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,")) { @@ -6803,6 +6827,7 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text, *
  • 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 *
  • *
  • OGC URN combining references for references for projected or derived * CRSs diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index cd880a3f22..b7081c2179 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -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); @@ -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(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(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);