Skip to content

Commit

Permalink
Merge pull request #3239 from rouault/fix_3238
Browse files Browse the repository at this point in the history
proj_grid_info(): make it work again with remote grids (refs #3238)
  • Loading branch information
rouault committed Jun 27, 2022
2 parents da259fe + 4af6147 commit 9e59ec3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
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

0 comments on commit 9e59ec3

Please sign in to comment.