diff --git a/src/4D_api.cpp b/src/4D_api.cpp index 5746e74906..03d8a171cb 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -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; }; { diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 7e963afb0f..d519329591 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -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), ""); diff --git a/test/unit/test_network.cpp b/test/unit/test_network.cpp index 73265008b3..07b1c5bd18 100644 --- a/test/unit/test_network.cpp +++ b/test/unit/test_network.cpp @@ -1641,6 +1641,14 @@ TEST(networking, download_whole_files) { putenv(const_cast("PROJ_SKIP_READ_USER_WRITABLE_DIRECTORY=")); putenv(const_cast("PROJ_USER_WRITABLE_DIRECTORY=./proj_test_tmp")); putenv(const_cast("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);