Skip to content

Commit

Permalink
Merge pull request #3280 from rouault/fix_3279
Browse files Browse the repository at this point in the history
WKT parser: fix issue when parsing some WKT1 with Hotine_Oblique_Mercator_Azimuth_Center and ignoring rectified_grid_angle (fixes #3279)
  • Loading branch information
rouault authored Aug 5, 2022
2 parents c482ea8 + 89130c3 commit a94f202
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7604,10 +7604,17 @@ WKTParser::guessDialect(const std::string &wkt) noexcept {
for (const auto &pointerKeyword : wkt1_keywords) {
if (ci_starts_with(wkt, *pointerKeyword)) {

if (ci_find(wkt, "GEOGCS[\"GCS_") != std::string::npos ||
(!ci_starts_with(wkt, WKTConstants::LOCAL_CS) &&
ci_find(wkt, "AXIS[") == std::string::npos &&
ci_find(wkt, "AUTHORITY[") == std::string::npos)) {
if ((ci_find(wkt, "GEOGCS[\"GCS_") != std::string::npos ||
(!ci_starts_with(wkt, WKTConstants::LOCAL_CS) &&
ci_find(wkt, "AXIS[") == std::string::npos &&
ci_find(wkt, "AUTHORITY[") == std::string::npos)) &&
// WKT1:GDAL and WKT1:ESRI have both a
// Hotine_Oblique_Mercator_Azimuth_Center If providing a
// WKT1:GDAL without AXIS, we may wrongly detect it as WKT1:ESRI
// and skip the rectified_grid_angle parameter cf
// /~https://github.com/OSGeo/PROJ/issues/3279
ci_find(wkt, "PARAMETER[\"rectified_grid_angle") ==
std::string::npos) {
return WKTGuessedDialect::WKT1_ESRI;
}

Expand Down
32 changes: 32 additions & 0 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,38 @@ TEST(wkt_parse, wkt1_hotine_oblique_mercator_with_rectified_grid_angle) {

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

TEST(wkt_parse,
wkt1_hotine_oblique_mercator_azimuth_center_with_rectified_grid_angle) {
auto wkt = "PROJCS[\"unknown\","
"GEOGCS[\"unknown\","
" DATUM[\"WGS_1984\","
" SPHEROID[\"WGS 84\",6378137,298.257223563]],"
" PRIMEM[\"Greenwich\",0],"
" UNIT[\"degree\",0.0174532925199433]],"
"PROJECTION[\"Hotine_Oblique_Mercator_Azimuth_Center\"],"
"PARAMETER[\"latitude_of_center\",0],"
"PARAMETER[\"longitude_of_center\",0],"
"PARAMETER[\"azimuth\",30],"
"PARAMETER[\"rectified_grid_angle\",0],"
"PARAMETER[\"scale_factor\",1],"
"PARAMETER[\"false_easting\",0],"
"PARAMETER[\"false_northing\",0],"
"UNIT[\"metre\",1]]";

auto obj = WKTParser().createFromWKT(wkt);
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
ASSERT_TRUE(crs != nullptr);

// Check that we have not overriden rectified_grid_angle
auto got_wkt = crs->exportToWKT(
WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get());
EXPECT_TRUE(got_wkt.find("PARAMETER[\"rectified_grid_angle\",0]") !=
std::string::npos)
<< got_wkt;
}

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

TEST(proj_export, wkt2_hotine_oblique_mercator_without_rectified_grid_angle) {
auto wkt = "PROJCRS[\"NAD_1983_Michigan_GeoRef_Meters\",\n"
" BASEGEOGCRS[\"NAD83(1986)\",\n"
Expand Down

0 comments on commit a94f202

Please sign in to comment.