Skip to content

Commit

Permalink
Merge pull request #3523 from rouault/cleanup_aeqd_s_forward
Browse files Browse the repository at this point in the history
aeqd_s_forward(): cleanup code and improve performance in polar case
  • Loading branch information
a0x8o committed Jan 17, 2024
1 parent dcab008 commit ae19e3b
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18032,6 +18032,7 @@ PROJStringParser::Private::buildProjectedCRS(int iStep,
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> locationtech-main
Expand Down Expand Up @@ -18833,6 +18834,12 @@ PROJStringParser::Private::buildProjectedCRS(int iStep,
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
bool foundStrictlyMatchingMapping = false;
if (mappings.size() >= 2) {
// To distinguish for example +ortho from +ortho +f=0
bool allMappingsHaveAuxParam = true;
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
for (const auto *mappingIter : mappings) {
if (mappingIter->proj_name_aux == nullptr) {
allMappingsHaveAuxParam = false;
Expand Down Expand Up @@ -18902,6 +18909,7 @@ PROJStringParser::Private::buildProjectedCRS(int iStep,
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
Expand Down Expand Up @@ -19458,6 +19466,9 @@ PROJStringParser::Private::buildProjectedCRS(int iStep,
=======
if (mapping) {
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
if (mapping && !foundStrictlyMatchingMapping) {
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
mapping = selectSphericalOrEllipsoidal(mapping, geodCRS);
}

Expand Down
13 changes: 13 additions & 0 deletions src/iso19111/operation/parammappings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5960,6 +5960,7 @@ static const MethodMapping projectionMethodMappings[] = {
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
nullptr, paramsLonNatOrigin},

<<<<<<< HEAD
{EPSG_NAME_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA_SPHERICAL,
EPSG_CODE_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA_SPHERICAL,
"Cylindrical_Equal_Area", "cea", nullptr, paramsCEA},
Expand Down Expand Up @@ -6595,6 +6596,8 @@ static const MethodMapping projectionMethodMappings[] = {
=======

>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
{EPSG_NAME_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA,
EPSG_CODE_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA, "Cylindrical_Equal_Area",
"cea", nullptr, paramsCEA},
Expand Down Expand Up @@ -6642,6 +6645,7 @@ static const MethodMapping projectionMethodMappings[] = {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
Expand Down Expand Up @@ -6872,6 +6876,8 @@ static const MethodMapping projectionMethodMappings[] = {
>>>>>>> 611a44b6fe (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
=======
>>>>>>> 42d859b743 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
=======
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
{EPSG_NAME_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA_SPHERICAL,
EPSG_CODE_METHOD_LAMBERT_CYLINDRICAL_EQUAL_AREA_SPHERICAL,
"Cylindrical_Equal_Area", "cea", "R_A", paramsCEA},
Expand Down Expand Up @@ -6906,6 +6912,7 @@ static const MethodMapping projectionMethodMappings[] = {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 0890f076c7 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
=======
Expand Down Expand Up @@ -7336,6 +7343,8 @@ static const MethodMapping projectionMethodMappings[] = {
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
{EPSG_NAME_METHOD_CASSINI_SOLDNER, EPSG_CODE_METHOD_CASSINI_SOLDNER,
"Cassini_Soldner", "cass", nullptr, paramsNatOrigin},

Expand Down Expand Up @@ -8443,6 +8452,7 @@ static const MethodMapping projectionMethodMappings[] = {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
Expand Down Expand Up @@ -8999,6 +9009,9 @@ static const MethodMapping projectionMethodMappings[] = {
=======
"Lambert_Azimuthal_Equal_Area", "laea", nullptr, paramsLaea},
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
"Lambert_Azimuthal_Equal_Area", "laea", "R_A", paramsLaea},
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)

{PROJ_WKT2_NAME_METHOD_MILLER_CYLINDRICAL, 0, "Miller_Cylindrical", "mill",
"R_A", paramsMiller},
Expand Down
80 changes: 68 additions & 12 deletions src/projections/aeqd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2843,6 +2843,7 @@ static PJ_XY aeqd_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> locationtech-main
Expand Down Expand Up @@ -3751,23 +3752,28 @@ static PJ_XY aeqd_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
=======
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
double coslam, cosphi, sinphi;
=======
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)

if (Q->mode == EQUIT)
{
const double cosphi = cos(lp.phi);
const double sinphi = sin(lp.phi);
const double coslam = cos(lp.lam);
const double sinlam = sin(lp.lam);

sinphi = sin(lp.phi);
cosphi = cos(lp.phi);
coslam = cos(lp.lam);
switch (Q->mode) {
case EQUIT:
xy.y = cosphi * coslam;
goto oblcon;
case OBLIQ:
xy.y = Q->sinph0 * sinphi + Q->cosph0 * cosphi * coslam;
oblcon:

if (fabs(fabs(xy.y) - 1.) < TOL)
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
{
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
if (xy.y < 0.) {
proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN);
return xy;
Expand Down Expand Up @@ -3817,6 +3823,7 @@ static PJ_XY aeqd_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> locationtech-main
Expand Down Expand Up @@ -5394,13 +5401,55 @@ static PJ_XY aeqd_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
=======
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
else {
=======
}
else
{
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
xy.y = acos(xy.y);
xy.y /= sin(xy.y);
xy.x = xy.y * cosphi * sin(lp.lam);
xy.y *= (Q->mode == EQUIT) ? sinphi :
Q->cosph0 * sinphi - Q->sinph0 * cosphi * coslam;
xy.x = xy.y * cosphi * sinlam;
xy.y *= sinphi;
}
}
else if (Q->mode == OBLIQ)
{
const double cosphi = cos(lp.phi);
const double sinphi = sin(lp.phi);
const double coslam = cos(lp.lam);
const double sinlam = sin(lp.lam);
const double cosphi_x_coslam = cosphi * coslam;

xy.y = Q->sinph0 * sinphi + Q->cosph0 * cosphi_x_coslam;

if (fabs(fabs(xy.y) - 1.) < TOL)
{
if (xy.y < 0.) {
proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN);
return xy;
}
else
return aeqd_e_forward(lp, P);
}
else
{
xy.y = acos(xy.y);
xy.y /= sin(xy.y);
xy.x = xy.y * cosphi * sinlam;
xy.y *= Q->cosph0 * sinphi - Q->sinph0 * cosphi_x_coslam;
}
}
else
{
double coslam = cos(lp.lam);
double sinlam = sin(lp.lam);
if (Q->mode == N_POLE)
{
lp.phi = -lp.phi;
coslam = -coslam;
}
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
=======
Expand Down Expand Up @@ -5837,6 +5886,8 @@ static PJ_XY aeqd_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
if (fabs(lp.phi - M_HALFPI) < EPS10) {
proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN);
return xy;
Expand Down Expand Up @@ -5885,6 +5936,7 @@ static PJ_XY aeqd_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
Expand Down Expand Up @@ -6500,6 +6552,10 @@ static PJ_XY aeqd_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
xy.y *= coslam;
break;
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
xy.x = xy.y * sinlam;
xy.y *= coslam;
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
}
return xy;
}
Expand Down
14 changes: 14 additions & 0 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14347,6 +14347,7 @@ TEST(io, projparse_cea_spherical) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
Expand Down Expand Up @@ -14872,6 +14873,10 @@ TEST(io, projparse_cea_spherical_on_ellipsoid) {
=======
>>>>>>> 9b68b76b81 (Fix build with -DPROJ_INTERNAL_CPP_NAMESPACE)
>>>>>>> 26891e6f2b (Fix build with -DPROJ_INTERNAL_CPP_NAMESPACE)
=======
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 "
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
"+ellps=WGS84 +units=m +no_defs +type=crs");
auto obj = PROJStringParser().createFromPROJString(input);
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
Expand Down Expand Up @@ -14917,6 +14922,7 @@ TEST(io, projparse_cea_spherical_on_ellipsoid) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 0890f076c7 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
=======
Expand Down Expand Up @@ -15347,6 +15353,8 @@ TEST(io, projparse_cea_spherical_on_ellipsoid) {
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
TEST(io, projparse_cea_ellipsoidal) {
auto obj = PROJStringParser().createFromPROJString(
"+proj=cea +ellps=GRS80 +type=crs");
Expand Down Expand Up @@ -16014,6 +16022,7 @@ TEST(io, projparse_laea_ellipsoidal) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
Expand Down Expand Up @@ -16244,6 +16253,8 @@ TEST(io, projparse_laea_ellipsoidal) {
>>>>>>> 611a44b6fe (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
=======
>>>>>>> 42d859b743 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
=======
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
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");
Expand Down Expand Up @@ -16291,6 +16302,7 @@ TEST(io, projparse_laea_spherical_on_ellipsoid) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 0890f076c7 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
=======
Expand Down Expand Up @@ -16721,6 +16733,8 @@ TEST(io, projparse_laea_spherical_on_ellipsoid) {
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)
TEST(io, projparse_eqc_spherical) {
auto obj = PROJStringParser().createFromPROJString(
"+proj=eqc +R=6371228 +type=crs");
Expand Down
4 changes: 4 additions & 0 deletions test/unit/test_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2509,6 +2509,7 @@ TEST(operation, lambert_cylindrical_equal_area_spherical_export) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> 885e4882b8 (Merge pull request #3524 from cffk/merid-update-fix)
Expand Down Expand Up @@ -3065,6 +3066,9 @@ TEST(operation, lambert_cylindrical_equal_area_spherical_export) {
=======
"+proj=cea +lat_ts=1 +lon_0=2 +x_0=3 +y_0=4");
>>>>>>> 0a2f6458d1 (Merge pull request #3524 from cffk/merid-update-fix)
=======
"+proj=cea +R_A +lat_ts=1 +lon_0=2 +x_0=3 +y_0=4");
>>>>>>> e827708321 (Merge pull request #3523 from rouault/cleanup_aeqd_s_forward)

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

0 comments on commit ae19e3b

Please sign in to comment.