diff --git a/src/transformations/gridshift.cpp b/src/transformations/gridshift.cpp index 260b5b05ca..ab1470b842 100644 --- a/src/transformations/gridshift.cpp +++ b/src/transformations/gridshift.cpp @@ -909,37 +909,41 @@ PJ *PJ_TRANSFORMATION(gridshift, 0) { return pj_gridshift_destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); } + bool isKnownGrid = false; bool isProjectedCoord = false; - if (P->ctx->defer_grid_opening) { - Q->m_defer_grid_opening = true; - } else { + + if (!P->ctx->defer_grid_opening || + !pj_param(P->ctx, P->params, "tcoord_type").i) { const char *gridnames = pj_param(P->ctx, P->params, "sgrids").s; gMutex.lock(); const auto iter = gKnownGrids.find(gridnames); - const bool isKnownGrid = iter != gKnownGrids.end(); + isKnownGrid = iter != gKnownGrids.end(); if (isKnownGrid) { + Q->m_defer_grid_opening = true; isProjectedCoord = iter->second; } gMutex.unlock(); - if (isKnownGrid) { - Q->m_defer_grid_opening = true; - } else { - Q->m_grids = pj_generic_grid_init(P, "grids"); - /* Was gridlist compiled properly? */ - if (proj_errno(P)) { - proj_log_error(P, _("could not find required grid(s).")); - return pj_gridshift_destructor( - P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); - } - if (!Q->checkGridTypes(P, isProjectedCoord)) { - return pj_gridshift_destructor( - P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); - } + } - gMutex.lock(); - gKnownGrids[gridnames] = isProjectedCoord; - gMutex.unlock(); + if (P->ctx->defer_grid_opening || isKnownGrid) { + Q->m_defer_grid_opening = true; + } else { + const char *gridnames = pj_param(P->ctx, P->params, "sgrids").s; + Q->m_grids = pj_generic_grid_init(P, "grids"); + /* Was gridlist compiled properly? */ + if (proj_errno(P)) { + proj_log_error(P, _("could not find required grid(s).")); + return pj_gridshift_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); + } + if (!Q->checkGridTypes(P, isProjectedCoord)) { + return pj_gridshift_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } + + gMutex.lock(); + gKnownGrids[gridnames] = isProjectedCoord; + gMutex.unlock(); } if (pj_param(P->ctx, P->params, "tinterpolation").i) { @@ -994,12 +998,17 @@ PJ *PJ_TRANSFORMATION(gridshift, 0) { } } - if (isProjectedCoord) { - P->left = PJ_IO_UNITS_PROJECTED; - P->right = PJ_IO_UNITS_PROJECTED; + if (isKnownGrid || pj_param(P->ctx, P->params, "tcoord_type").i) { + if (isProjectedCoord) { + P->left = PJ_IO_UNITS_PROJECTED; + P->right = PJ_IO_UNITS_PROJECTED; + } else { + P->left = PJ_IO_UNITS_RADIANS; + P->right = PJ_IO_UNITS_RADIANS; + } } else { - P->left = PJ_IO_UNITS_RADIANS; - P->right = PJ_IO_UNITS_RADIANS; + P->left = PJ_IO_UNITS_WHATEVER; + P->right = PJ_IO_UNITS_WHATEVER; } return P; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9ec53dc567..2b2141a32f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -60,6 +60,8 @@ proj_add_gie_test("Deformation" "gie/deformation.gie") proj_add_gie_test("geotiff_grids" "gie/geotiff_grids.gie") proj_add_gie_test("defmodel" "gie/defmodel.gie") proj_add_gie_test("gridshift" "gie/gridshift.gie") +# Does not really require the network, but test running with PROJ_NETWORK=ON +proj_add_gie_network_dependent_test("gridshift_network_enabled" "gie/gridshift.gie") endif() if(TIFF_ENABLED AND CURL_ENABLED AND RUN_NETWORK_DEPENDENT_TESTS) diff --git a/test/gie/gridshift.gie b/test/gie/gridshift.gie index fec8e50106..98cf0657aa 100644 --- a/test/gie/gridshift.gie +++ b/test/gie/gridshift.gie @@ -251,6 +251,19 @@ accept -598000.000 -1160020.000 0.000 expect -5597999.885 -6160019.978 0.000 roundtrip 1 +------------------------------------------------------------------------------- +operation +proj=pipeline \ + +step +proj=krovak +lat_0=49.5 +lon_0=24.8333333333333 +alpha=30.2881397527778 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel \ + +step +proj=gridshift +grids=tests/test_gridshift_projected.tif \ + +step +inv +proj=mod_krovak +lat_0=49.5 +lon_0=24.8333333333333 +alpha=30.2881397222222 +k=0.9999 +x_0=5000000 +y_0=5000000 +ellps=bessel +------------------------------------------------------------------------------- + +tolerance 0.5 mm + +accept 16.610452439 49.202425040 0.000 +expect 16.610455233 49.202425034 0.000 +roundtrip 1 + ------------- # Error cases -------------