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 <--> PROJ: correctly map 'Lambert Azimuthal Equal Area (Spherical)' to '+proj=laea +R_A' #3526

Merged
merged 1 commit into from
Dec 30, 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
4 changes: 2 additions & 2 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10695,10 +10695,10 @@ PROJStringParser::Private::buildProjectedCRS(int iStep,
const auto mappings = getMappingsFromPROJName(step.name);
const MethodMapping *mapping = mappings.empty() ? nullptr : mappings[0];

bool foundStrictlyMatchingMapping = false;
if (mappings.size() >= 2) {
// To distinguish for example +ortho from +ortho +f=0
bool allMappingsHaveAuxParam = true;
bool foundStrictlyMatchingMapping = false;
for (const auto *mappingIter : mappings) {
if (mappingIter->proj_name_aux == nullptr) {
allMappingsHaveAuxParam = false;
Expand All @@ -10725,7 +10725,7 @@ PROJStringParser::Private::buildProjectedCRS(int iStep,
}
}

if (mapping) {
if (mapping && !foundStrictlyMatchingMapping) {
mapping = selectSphericalOrEllipsoidal(mapping, geodCRS);
}

Expand Down
10 changes: 5 additions & 5 deletions src/iso19111/operation/parammappings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,14 @@ static const MethodMapping projectionMethodMappings[] = {
{PROJ_WKT2_NAME_METHOD_COMPACT_MILLER, 0, "Compact_Miller", "comill",
nullptr, paramsLonNatOrigin},

{EPSG_NAME_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA_SPHERICAL,
EPSG_CODE_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA_SPHERICAL,
"Cylindrical_Equal_Area", "cea", nullptr, paramsCEA},

{EPSG_NAME_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA,
EPSG_CODE_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA, "Cylindrical_Equal_Area",
"cea", nullptr, paramsCEA},

{EPSG_NAME_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA_SPHERICAL,
EPSG_CODE_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA_SPHERICAL,
"Cylindrical_Equal_Area", "cea", "R_A", paramsCEA},

{EPSG_NAME_METHOD_CASSINI_SOLDNER, EPSG_CODE_METHOD_CASSINI_SOLDNER,
"Cassini_Soldner", "cass", nullptr, paramsNatOrigin},

Expand Down Expand Up @@ -732,7 +732,7 @@ static const MethodMapping projectionMethodMappings[] = {

{EPSG_NAME_METHOD_LAMBERT_AZIMUTHAL_EQUAL_AREA_SPHERICAL,
EPSG_CODE_METHOD_LAMBERT_AZIMUTHAL_EQUAL_AREA_SPHERICAL,
"Lambert_Azimuthal_Equal_Area", "laea", nullptr, paramsLaea},
"Lambert_Azimuthal_Equal_Area", "laea", "R_A", paramsLaea},

{PROJ_WKT2_NAME_METHOD_MILLER_CYLINDRICAL, 0, "Miller_Cylindrical", "mill",
"R_A", paramsMiller},
Expand Down
34 changes: 34 additions & 0 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10040,6 +10040,23 @@ TEST(io, projparse_cea_spherical) {

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

TEST(io, projparse_cea_spherical_on_ellipsoid) {
std::string input("+proj=cea +R_A +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 "
"+ellps=WGS84 +units=m +no_defs +type=crs");
auto obj = PROJStringParser().createFromPROJString(input);
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
ASSERT_TRUE(crs != nullptr);
EXPECT_EQ(crs->derivingConversion()->method()->getEPSGCode(),
EPSG_CODE_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA_SPHERICAL);
EXPECT_EQ(
crs->exportToPROJString(
PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
.get()),
input);
}

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

TEST(io, projparse_cea_ellipsoidal) {
auto obj = PROJStringParser().createFromPROJString(
"+proj=cea +ellps=GRS80 +type=crs");
Expand Down Expand Up @@ -10664,6 +10681,23 @@ TEST(io, projparse_laea_ellipsoidal) {

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

TEST(io, projparse_laea_spherical_on_ellipsoid) {
std::string input("+proj=laea +R_A +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 "
"+ellps=WGS84 +units=m +no_defs +type=crs");
auto obj = PROJStringParser().createFromPROJString(input);
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
ASSERT_TRUE(crs != nullptr);
EXPECT_EQ(crs->derivingConversion()->method()->getEPSGCode(),
EPSG_CODE_METHOD_LAMBERT_AZIMUTHAL_EQUAL_AREA_SPHERICAL);
EXPECT_EQ(
crs->exportToPROJString(
PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
.get()),
input);
}

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

TEST(io, projparse_eqc_spherical) {
auto obj = PROJStringParser().createFromPROJString(
"+proj=eqc +R=6371228 +type=crs");
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ TEST(operation, lambert_cylindrical_equal_area_spherical_export) {
EXPECT_TRUE(conv->validateParameters().empty());

EXPECT_EQ(conv->exportToPROJString(PROJStringFormatter::create().get()),
"+proj=cea +lat_ts=1 +lon_0=2 +x_0=3 +y_0=4");
"+proj=cea +R_A +lat_ts=1 +lon_0=2 +x_0=3 +y_0=4");

EXPECT_EQ(conv->exportToWKT(WKTFormatter::create().get()),
"CONVERSION[\"Lambert Cylindrical Equal Area (Spherical)\",\n"
Expand Down