Skip to content

Commit

Permalink
Merge pull request #3569 from rouault/fix_3568
Browse files Browse the repository at this point in the history
createFromUserInput(): make http://www.opengis.net/def/crs/IAU/2015/XXXX work (fixes #3568)
rouault authored Jan 19, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 86b01b2 + d566d01 commit e54d4b9
Showing 2 changed files with 50 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
@@ -6830,8 +6830,34 @@ static CRSNNPtr importFromCRSURL(const std::string &text,

const auto &auth_name = parts[1];
const auto &code = parts[3];
auto factoryCRS = AuthorityFactory::create(dbContext, auth_name);
return factoryCRS->createCoordinateReferenceSystem(code, true);
try {
auto factoryCRS = AuthorityFactory::create(dbContext, auth_name);
return factoryCRS->createCoordinateReferenceSystem(code, true);
} catch (...) {
const auto &version = parts[2];
if (version.empty() || version == "0") {
const auto authoritiesFromAuthName =
dbContext->getVersionedAuthoritiesFromName(auth_name);
for (const auto &authNameVersioned : authoritiesFromAuthName) {
try {
auto factoryCRS =
AuthorityFactory::create(dbContext, authNameVersioned);
return factoryCRS->createCoordinateReferenceSystem(code,
true);
} catch (...) {
}
}
throw;
}
std::string authNameWithVersion;
if (!dbContext->getVersionedAuthority(auth_name, version,
authNameWithVersion)) {
throw;
}
auto factoryCRS =
AuthorityFactory::create(dbContext, authNameWithVersion);
return factoryCRS->createCoordinateReferenceSystem(code, true);
}
}

// ---------------------------------------------------------------------------
22 changes: 22 additions & 0 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
@@ -12158,6 +12158,23 @@ TEST(io, createFromUserInput_ogc_crs_url) {
ASSERT_TRUE(crs != nullptr);
}

{
auto obj = createFromUserInput(
"http://www.opengis.net/def/crs/IAU/2015/49900", dbContext);
auto crs = nn_dynamic_pointer_cast<GeographicCRS>(obj);
ASSERT_TRUE(crs != nullptr);
}

{
// Not sure if this is intended to be valid (version=0), but let's
// immitate the logic of EPSG, this will use the latest version of IAU
// (if/when there will be several of them)
auto obj = createFromUserInput(
"http://www.opengis.net/def/crs/IAU/0/49900", dbContext);
auto crs = nn_dynamic_pointer_cast<GeographicCRS>(obj);
ASSERT_TRUE(crs != nullptr);
}

EXPECT_THROW(
createFromUserInput("http://www.opengis.net/def/crs", dbContext),
ParsingException);
@@ -12170,6 +12187,11 @@ TEST(io, createFromUserInput_ogc_crs_url) {
"http://www.opengis.net/def/crs/EPSG/0/XXXX", dbContext),
NoSuchAuthorityCodeException);

EXPECT_THROW(
createFromUserInput("http://www.opengis.net/def/crs/IAU/2015/invalid",
dbContext),
NoSuchAuthorityCodeException);

{
auto obj = createFromUserInput(
"http://www.opengis.net/def/crs-compound?1=http://www.opengis.net/"

0 comments on commit e54d4b9

Please sign in to comment.