I am really struggling to understand this one. The former case (using GDALSetRasterNoDataValue) works as expected, the second (using SetNoDataValue) does not. Here is a minimal replicable example (I am using GNU C++20 and link this against libgdal.34.3.8.3.dylib):
GDALAllRegister();
auto driver = GetGDALDriverManager()->GetDriverByName("GTiff");
int err_code{};
auto out_handle1 = GDALDatasetUniquePtr(driver->Create("/Users/kristianbehrens/Desktop/work/sprawl_russia/codebases/data/test1.tif", 100, 100, 1, GDALDataType::GDT_Float64, nullptr));
GDALSetRasterNoDataValue(out_handle1->GetRasterBand(1), 9999.0);
std::cout << "OUTPUT METHOD 1:n";
double novalue1 = GDALGetRasterNoDataValue(out_handle1->GetRasterBand(1), &err_code);
std::cout << "(novalue1, err_code) = (" << novalue1 << ", " << err_code << ")n";
auto out_handle2 = GDALDatasetUniquePtr(driver->Create("/Users/kristianbehrens/Desktop/work/sprawl_russia/codebases/data/test2.tif", 100, 100, 1, GDALDataType::GDT_Float64, nullptr));
err_code = out_handle2->GetRasterBand(1)->SetNoDataValue(9999.0);
std::cout << "OUTPUT METHOD 2:n";
double novalue2 = out_handle2->GetRasterBand(1)->GetNoDataValue(&err_code);
std::cout << "(novalue2, err_code) = (" << novalue2 << ", " << err_code << ")n";
Here is the runtime output produced by the code:
I don’t understand the “ERROR 1: GetNoDataValue() should be called instead” part. Any ideas? Obviously, something goes wrong but the error message is not very helpful. When looking at the output files created, I then get the following when calling gdalinfo from the shell:
The second one is obviously wrong for the no value information (though the rest seems fine). Any idea what I am missing (probably something obvious, as usual…). Thanks a lot in advance for your help.