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

CRS identification: use case insensitive comparison for authority name (fixes #1779) #1780

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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