Skip to content

Commit

Permalink
Defered grid loading: do not try to re-open a grid that previously fa…
Browse files Browse the repository at this point in the history
…iled to open from the same PJ* instance
  • Loading branch information
rouault committed Nov 1, 2024
1 parent 99f8976 commit 17b2c2b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
11 changes: 8 additions & 3 deletions src/transformations/gridshift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct GridInfo {
struct gridshiftData {
ListOfGenericGrids m_grids{};
bool m_defer_grid_opening = false;
int m_error_code_in_defer_grid_opening = 0;
bool m_bHasHorizontalOffset = false;
bool m_bHasGeographic3DOffset = false;
bool m_bHasEllipsoidalHeightOffset = false;
Expand Down Expand Up @@ -724,12 +725,16 @@ PJ_XYZ gridshiftData::grid_apply_internal(
// ---------------------------------------------------------------------------

bool gridshiftData::loadGridsIfNeeded(PJ *P) {
if (m_defer_grid_opening) {
if (m_error_code_in_defer_grid_opening) {
proj_errno_set(P, m_error_code_in_defer_grid_opening);
return false;
} else if (m_defer_grid_opening) {
m_defer_grid_opening = false;
m_grids = pj_generic_grid_init(P, "grids");
if (proj_errno(P)) {
m_error_code_in_defer_grid_opening = proj_errno(P);
if (m_error_code_in_defer_grid_opening) {
return false;
}
m_defer_grid_opening = false;
bool isProjectedCoord;
if (!checkGridTypes(P, isProjectedCoord)) {
return false;
Expand Down
21 changes: 13 additions & 8 deletions src/transformations/hgridshift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct hgridshiftData {
double t_epoch = 0;
ListOfHGrids grids{};
bool defer_grid_opening = false;
int error_code_in_defer_grid_opening = 0;
};
} // anonymous namespace

Expand All @@ -31,11 +32,13 @@ static PJ_XYZ pj_hgridshift_forward_3d(PJ_LPZ lpz, PJ *P) {
point.lpz = lpz;

if (Q->defer_grid_opening) {
Q->grids = pj_hgrid_init(P, "grids");
if (proj_errno(P)) {
return proj_coord_error().xyz;
}
Q->defer_grid_opening = false;
Q->grids = pj_hgrid_init(P, "grids");
Q->error_code_in_defer_grid_opening = proj_errno(P);
}
if (Q->error_code_in_defer_grid_opening) {
proj_errno_set(P, Q->error_code_in_defer_grid_opening);
return proj_coord_error().xyz;
}

if (!Q->grids.empty()) {
Expand All @@ -53,11 +56,13 @@ static PJ_LPZ pj_hgridshift_reverse_3d(PJ_XYZ xyz, PJ *P) {
point.xyz = xyz;

if (Q->defer_grid_opening) {
Q->grids = pj_hgrid_init(P, "grids");
if (proj_errno(P)) {
return proj_coord_error().lpz;
}
Q->defer_grid_opening = false;
Q->grids = pj_hgrid_init(P, "grids");
Q->error_code_in_defer_grid_opening = proj_errno(P);
}
if (Q->error_code_in_defer_grid_opening) {
proj_errno_set(P, Q->error_code_in_defer_grid_opening);
return proj_coord_error().lpz;
}

if (!Q->grids.empty()) {
Expand Down
21 changes: 13 additions & 8 deletions src/transformations/vgridshift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct vgridshiftData {
double forward_multiplier = 0;
ListOfVGrids grids{};
bool defer_grid_opening = false;
int error_code_in_defer_grid_opening = 0;
};
} // anonymous namespace

Expand Down Expand Up @@ -57,12 +58,14 @@ static PJ_XYZ pj_vgridshift_forward_3d(PJ_LPZ lpz, PJ *P) {
point.lpz = lpz;

if (Q->defer_grid_opening) {
Q->defer_grid_opening = false;
Q->grids = pj_vgrid_init(P, "grids");
deal_with_vertcon_gtx_hack(P);
if (proj_errno(P)) {
return proj_coord_error().xyz;
}
Q->defer_grid_opening = false;
Q->error_code_in_defer_grid_opening = proj_errno(P);
}
if (Q->error_code_in_defer_grid_opening) {
proj_errno_set(P, Q->error_code_in_defer_grid_opening);
return proj_coord_error().xyz;
}

if (!Q->grids.empty()) {
Expand All @@ -81,12 +84,14 @@ static PJ_LPZ pj_vgridshift_reverse_3d(PJ_XYZ xyz, PJ *P) {
point.xyz = xyz;

if (Q->defer_grid_opening) {
Q->defer_grid_opening = false;
Q->grids = pj_vgrid_init(P, "grids");
deal_with_vertcon_gtx_hack(P);
if (proj_errno(P)) {
return proj_coord_error().lpz;
}
Q->defer_grid_opening = false;
Q->error_code_in_defer_grid_opening = proj_errno(P);
}
if (Q->error_code_in_defer_grid_opening) {
proj_errno_set(P, Q->error_code_in_defer_grid_opening);
return proj_coord_error().lpz;
}

if (!Q->grids.empty()) {
Expand Down
11 changes: 7 additions & 4 deletions src/transformations/xyzgridshift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct xyzgridshiftData {
bool grid_ref_is_input = true;
ListOfGenericGrids grids{};
bool defer_grid_opening = false;
int error_code_in_defer_grid_opening = 0;
double multiplier = 1.0;
};
} // anonymous namespace
Expand All @@ -54,11 +55,13 @@ struct xyzgridshiftData {
static bool get_grid_values(PJ *P, xyzgridshiftData *Q, const PJ_LP &lp,
double &dx, double &dy, double &dz) {
if (Q->defer_grid_opening) {
Q->grids = pj_generic_grid_init(P, "grids");
if (proj_errno(P)) {
return false;
}
Q->defer_grid_opening = false;
Q->grids = pj_generic_grid_init(P, "grids");
Q->error_code_in_defer_grid_opening = proj_errno(P);
}
if (Q->error_code_in_defer_grid_opening) {
proj_errno_set(P, Q->error_code_in_defer_grid_opening);
return false;
}

GenericShiftGridSet *gridset = nullptr;
Expand Down

0 comments on commit 17b2c2b

Please sign in to comment.