Skip to content

Commit

Permalink
Merge pull request #3577 from rouault/wkt_enum_case_insensitive
Browse files Browse the repository at this point in the history
WKT import: make axis direction and range meaning enumeration case insensitive as mandated by spec
  • Loading branch information
rouault authored Jan 21, 2023
2 parents 72a88d7 + c11a0ba commit e59ea65
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
21 changes: 12 additions & 9 deletions src/iso19111/coordinatesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,16 +1356,17 @@ ParametricCS::create(const util::PropertyMap &properties,
// ---------------------------------------------------------------------------

AxisDirection::AxisDirection(const std::string &nameIn) : CodeList(nameIn) {
assert(registry.find(nameIn) == registry.end());
registry[nameIn] = this;
auto lowerName = tolower(nameIn);
assert(registry.find(lowerName) == registry.end());
registry[lowerName] = this;
}

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

//! @cond Doxygen_Suppress
const AxisDirection *
AxisDirection::valueOf(const std::string &nameIn) noexcept {
auto iter = registry.find(nameIn);
auto iter = registry.find(tolower(nameIn));
if (iter == registry.end())
return nullptr;
return iter->second;
Expand All @@ -1375,8 +1376,9 @@ AxisDirection::valueOf(const std::string &nameIn) noexcept {
// ---------------------------------------------------------------------------

RangeMeaning::RangeMeaning(const std::string &nameIn) : CodeList(nameIn) {
assert(registry.find(nameIn) == registry.end());
registry[nameIn] = this;
auto lowerName = tolower(nameIn);
assert(registry.find(lowerName) == registry.end());
registry[lowerName] = this;
}

// ---------------------------------------------------------------------------
Expand All @@ -1387,7 +1389,7 @@ RangeMeaning::RangeMeaning() : CodeList(std::string()) {}

//! @cond Doxygen_Suppress
const RangeMeaning *RangeMeaning::valueOf(const std::string &nameIn) noexcept {
auto iter = registry.find(nameIn);
auto iter = registry.find(tolower(nameIn));
if (iter == registry.end())
return nullptr;
return iter->second;
Expand All @@ -1399,14 +1401,15 @@ const RangeMeaning *RangeMeaning::valueOf(const std::string &nameIn) noexcept {

AxisDirectionWKT1::AxisDirectionWKT1(const std::string &nameIn)
: CodeList(nameIn) {
assert(registry.find(nameIn) == registry.end());
registry[nameIn] = this;
auto lowerName = tolower(nameIn);
assert(registry.find(lowerName) == registry.end());
registry[lowerName] = this;
}

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

const AxisDirectionWKT1 *AxisDirectionWKT1::valueOf(const std::string &nameIn) {
auto iter = registry.find(nameIn);
auto iter = registry.find(tolower(nameIn));
if (iter == registry.end())
return nullptr;
return iter->second;
Expand Down
3 changes: 0 additions & 3 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2634,9 +2634,6 @@ WKTParser::Private::buildAxis(const WKTNodeNNPtr &node,
direction = &AxisDirection::GEOCENTRIC_Z;
} else if (dirString == AxisDirectionWKT1::OTHER.toString()) {
direction = &AxisDirection::UNSPECIFIED;
} else if (!direction &&
AxisDirectionWKT1::valueOf(toupper(dirString)) != nullptr) {
direction = AxisDirection::valueOf(tolower(dirString));
}

if (!direction) {
Expand Down
8 changes: 5 additions & 3 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,8 @@ TEST(wkt_parse, wkt2_geocentric) {
" ID[\"EPSG\",9122]],\n"
" ID[\"EPSG\",8901]],\n"
" CS[Cartesian,3],\n"
" AXIS[\"(X)\",geocentricX,\n"
// nominal value is 'geocentricX' with g lower case.
" AXIS[\"(X)\",GeocentricX,\n"
" ORDER[1],\n"
" LENGTHUNIT[\"metre\",1,\n"
" ID[\"EPSG\",9001]]],\n"
Expand Down Expand Up @@ -2468,7 +2469,8 @@ TEST(wkt_parse, cs_with_AXISMINVAL_AXISMAXVAL_RANGEMEANING) {
" ANGLEUNIT[\"degree\",0.0174532925199433],\n"
" AXISMINVALUE[0],\n"
" AXISMAXVALUE[360],\n"
" RANGEMEANING[wraparound]]]";
// nominal value is 'wraparound' lower case
" RANGEMEANING[wrapAround]]]";
auto obj = WKTParser().createFromWKT(wkt);
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
ASSERT_TRUE(crs != nullptr);
Expand All @@ -2492,7 +2494,7 @@ TEST(wkt_parse, cs_with_AXISMINVAL_AXISMAXVAL_RANGEMEANING) {
EXPECT_EQ(
crs->exportToWKT(
WKTFormatter::create(WKTFormatter::Convention::WKT2_2019).get()),
wkt);
replaceAll(wkt, "wrapAround", "wraparound"));
}

// ---------------------------------------------------------------------------
Expand Down

0 comments on commit e59ea65

Please sign in to comment.