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

WKT parser: fix issue when parsing some WKT1 with Hotine_Oblique_Mercator_Azimuth_Center and ignoring rectified_grid_angle (fixes #3279) #3280

Merged
merged 1 commit into from
Aug 5, 2022
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
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