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_grid_info(): make it work again with remote grids (refs #3238) #3239

Merged
merged 1 commit into from Jun 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 20 additions & 17 deletions src/4D_api.cpp
Expand Up @@ -2294,25 +2294,28 @@ PJ_GRID_INFO proj_grid_info(const char *gridname) {
strncpy (grinfo.gridname, gridname, sizeof(grinfo.gridname) - 1);

/* full path of grid */
if( pj_find_file(ctx, gridname, grinfo.filename, sizeof(grinfo.filename) - 1) )
if( !pj_find_file(ctx, gridname, grinfo.filename, sizeof(grinfo.filename) - 1) )
{
/* grid format */
strncpy (grinfo.format, format.c_str(), sizeof(grinfo.format) - 1);

/* grid size */
grinfo.n_lon = grid.width();
grinfo.n_lat = grid.height();

/* cell size */
grinfo.cs_lon = extent.resX;
grinfo.cs_lat = extent.resY;

/* bounds of grid */
grinfo.lowerleft.lam = extent.west;
grinfo.lowerleft.phi = extent.south;
grinfo.upperright.lam = extent.east;
grinfo.upperright.phi = extent.north;
// Can happen when using a remote grid
grinfo.filename[0] = 0;
}

/* grid format */
strncpy (grinfo.format, format.c_str(), sizeof(grinfo.format) - 1);

/* grid size */
grinfo.n_lon = grid.width();
grinfo.n_lat = grid.height();

/* cell size */
grinfo.cs_lon = extent.resX;
grinfo.cs_lat = extent.resY;

/* bounds of grid */
grinfo.lowerleft.lam = extent.west;
grinfo.lowerleft.phi = extent.south;
grinfo.upperright.lam = extent.east;
grinfo.upperright.phi = extent.north;
};

{
Expand Down
8 changes: 8 additions & 0 deletions test/unit/gie_self_tests.cpp
Expand Up @@ -411,6 +411,14 @@ TEST(gie, info_functions) {
ASSERT_NE(std::string(grid_info.filename), "");
ASSERT_EQ(std::string(grid_info.gridname), "tests/test_hgrid.tif");
ASSERT_EQ(std::string(grid_info.format), "gtiff");
EXPECT_EQ(grid_info.n_lon, 4);
EXPECT_EQ(grid_info.n_lat, 4);
EXPECT_NEAR(grid_info.cs_lon, 0.017453292519943295, 1e-15);
EXPECT_NEAR(grid_info.cs_lat, 0.017453292519943295, 1e-15);
EXPECT_NEAR(grid_info.lowerleft.lam, 0.069813170079773182, 1e-15);
EXPECT_NEAR(grid_info.lowerleft.phi, 0.90757121103705141, 1e-15);
EXPECT_NEAR(grid_info.upperright.lam, 0.12217304763960307, 1e-15);
EXPECT_NEAR(grid_info.upperright.phi, 0.95993108859688125, 1e-15);

grid_info = proj_grid_info("nonexistinggrid");
ASSERT_EQ(std::string(grid_info.filename), "");
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_network.cpp
Expand Up @@ -1641,6 +1641,14 @@ TEST(networking, download_whole_files) {
putenv(const_cast<char *>("PROJ_SKIP_READ_USER_WRITABLE_DIRECTORY="));
putenv(const_cast<char *>("PROJ_USER_WRITABLE_DIRECTORY=./proj_test_tmp"));
putenv(const_cast<char *>("PROJ_FULL_FILE_CHUNK_SIZE=100000"));

proj_context_set_enable_network(nullptr, true);
const auto grid_info = proj_grid_info("dk_sdfe_dvr90.tif");
EXPECT_EQ(std::string(grid_info.filename), "");
EXPECT_EQ(std::string(grid_info.gridname), "dk_sdfe_dvr90.tif");
EXPECT_EQ(std::string(grid_info.format), "gtiff");
proj_context_set_enable_network(nullptr, false);

auto ctx = proj_context_create();
proj_context_set_enable_network(ctx, true);

Expand Down