Skip to content

Commit

Permalink
Merge pull request #1780 from rouault/fix_1779
Browse files Browse the repository at this point in the history
CRS identification: use case insensitive comparison for authority name (fixes #1779)
  • Loading branch information
kbevers authored Dec 9, 2019
2 parents 9750c04 + 5cc1095 commit 9b66a94
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/iso19111/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,9 +1433,17 @@ AuthorityFactory::AuthorityFactory(const DatabaseContextNNPtr &context,
AuthorityFactoryNNPtr
AuthorityFactory::create(const DatabaseContextNNPtr &context,
const std::string &authorityName) {

auto factory = AuthorityFactory::nn_make_shared<AuthorityFactory>(
context, authorityName);
const auto getFactory = [&context, &authorityName]() {
for (const auto &knownName : {"EPSG", "ESRI", "PROJ"}) {
if (ci_equal(authorityName, knownName)) {
return AuthorityFactory::nn_make_shared<AuthorityFactory>(
context, knownName);
}
}
return AuthorityFactory::nn_make_shared<AuthorityFactory>(
context, authorityName);
};
auto factory = getFactory();
factory->d->setThis(factory);
return factory;
}
Expand Down
5 changes: 1 addition & 4 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5669,10 +5669,7 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text,
DatabaseContextNNPtr dbContextNNPtr(NN_NO_CHECK(dbContext));
const auto &authName = tokens[0];
const auto &code = tokens[1];
static const std::string epsg_lowercase("epsg");
auto factory = AuthorityFactory::create(
dbContextNNPtr,
authName == epsg_lowercase ? Identifier::EPSG : authName);
auto factory = AuthorityFactory::create(dbContextNNPtr, authName);
try {
return factory->createCoordinateReferenceSystem(code);
} catch (...) {
Expand Down
32 changes: 32 additions & 0 deletions test/unit/test_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,38 @@ TEST(crs, projectedCRS_identify_db) {

// ---------------------------------------------------------------------------

TEST(crs, projectedCRS_identify_wrong_auth_name_case) {
auto dbContext = DatabaseContext::create();
auto factoryAnonymous = AuthorityFactory::create(dbContext, std::string());
auto obj =
WKTParser()
.attachDatabaseContext(dbContext)
.setStrict(false)
.createFromWKT(
"PROJCS[\"World_Cylindrical_Equal_Area\","
"GEOGCS[\"GCS_WGS_1984\","
"DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\","
"6378137.0,298.257223563]],"
"PRIMEM[\"Greenwich\",0.0],"
"UNIT[\"Degree\",0.0174532925199433]],"
"PROJECTION[\"Cylindrical_Equal_Area\"],"
"PARAMETER[\"False_Easting\",0.0],"
"PARAMETER[\"False_Northing\",0.0],"
"PARAMETER[\"Central_Meridian\",0.0],"
"PARAMETER[\"Standard_Parallel_1\",0.0],UNIT[\"Meter\",1.0],"
"AUTHORITY[\"Esri\",54034]]"); // should be ESRI all caps
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
ASSERT_TRUE(crs != nullptr);
auto res = crs->identify(factoryAnonymous);
ASSERT_EQ(res.size(), 1U);
const auto &ids = res.front().first->identifiers();
ASSERT_EQ(ids.size(), 1U);
EXPECT_EQ(*(ids.front()->codeSpace()), "ESRI");
EXPECT_EQ(ids.front()->code(), "54034");
}

// ---------------------------------------------------------------------------

TEST(crs, mercator_1SP_as_WKT1_ESRI) {

auto obj = PROJStringParser().createFromPROJString(
Expand Down

0 comments on commit 9b66a94

Please sign in to comment.