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

+proj=gridshift: make projected grids work with PROJ_NETWORK=ON #4174

Merged
merged 1 commit into from
Jun 18, 2024
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
61 changes: 35 additions & 26 deletions src/transformations/gridshift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions test/gie/gridshift.gie
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------
Expand Down