From 0f543d209f6f26dced0ba2710f4942c3ed6b8dce Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 1 Nov 2024 16:10:35 +0100 Subject: [PATCH] Defered grid loading: do not try to re-open a grid that previously failed to open from the same PJ* instance --- src/transformations/gridshift.cpp | 11 ++++++++--- src/transformations/hgridshift.cpp | 21 +++++++++++++-------- src/transformations/vgridshift.cpp | 21 +++++++++++++-------- src/transformations/xyzgridshift.cpp | 11 +++++++---- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/transformations/gridshift.cpp b/src/transformations/gridshift.cpp index d5524571ab..f97e8b59ce 100644 --- a/src/transformations/gridshift.cpp +++ b/src/transformations/gridshift.cpp @@ -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; @@ -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; diff --git a/src/transformations/hgridshift.cpp b/src/transformations/hgridshift.cpp index a85298b82c..45d939fc40 100644 --- a/src/transformations/hgridshift.cpp +++ b/src/transformations/hgridshift.cpp @@ -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 @@ -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()) { @@ -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()) { diff --git a/src/transformations/vgridshift.cpp b/src/transformations/vgridshift.cpp index 49f642d9b9..eef2806193 100644 --- a/src/transformations/vgridshift.cpp +++ b/src/transformations/vgridshift.cpp @@ -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 @@ -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()) { @@ -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()) { diff --git a/src/transformations/xyzgridshift.cpp b/src/transformations/xyzgridshift.cpp index 6b53c0df36..aa682c7a53 100644 --- a/src/transformations/xyzgridshift.cpp +++ b/src/transformations/xyzgridshift.cpp @@ -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 @@ -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;