-1

I read many threads here to change the nodata value of my raster to desired value - in my case from -99999 to -9999. It seems I can not use spider or anything similliar as I do not have admin rights. I also tried reclassify (SAGA) but when I run it, the module required me to fill all fields (single, range, simple table) although I picked the single method to use because it seems I have to choose at least one method. In the bottom part of the Reclassify box I set the nodata to desired value but its failed. Report said the range and simple table data must be filled.

Then I found that QGIS 2.18 is suitable for that and it does the work, however when I run the same Reclassify in QGIS 2.18 I got following report

'NoneType' object has no attribute 'crs' See log for more details

Can anyone please navigate me to change the nodata somehow regardsless its QGIS or for instance R?

1
  • Not sure, but how about NAvalue(your_raster_object) <- -9999 ? ... or you mighty be struggling to replace the value.. like r[r == -99999] <- -9999...
    – Kazuhito
    Apr 28, 2020 at 16:46

1 Answer 1

1

You can follow the piping advice from @Kazuhito but alternately, pipe in NA ie., r[r == -99999] <- NA. This is the native R no data value. When you then use raster::writeRaster the no data will parsed to the correct output format value. This is safer than forcing a no data value such as -9999 (which is an ESRI convention). If you say, write a geoTiff, specifying a nodata value as -9999 will cause the NA value to be parsed incorrectly because the functions does not know what this value represents so, will output it as a real vlaue.

You could also use the mvFlag = -99999 argument in rgdal::readGDAL to specify the NA value and skip having to pipe a value. I would recommend then coercing using raster::raster and then using raster::writeRaster as it is simpler that working through all of the augments of rgdal::writeGDAL.

2
  • Does the approach you've suggested work for georeferenced raster also? I followed both suggestions of You and Kazuhito and set the value to -9999, however when I upload the raster to QGIS and view the information, scroll down to the bottom where the NAvalue is displayed it states the value -3.4e+38? Why it does not states the value -9999? The code is install.packages("raster") install.packages('rgdal') install.packages('sp') library(raster) library(sp) library(rgdal) x <- raster("Pokus.tif") NAvalue(x) <- -9999 NAvalue(x) writeRaster(x, "pokusNA", format = "GTiff")
    – Petr
    Apr 29, 2020 at 6:41
  • When I then inspect the generated raster for NAvalue with NAvalue(x) it states -inf. Why not -9999?
    – Petr
    Apr 29, 2020 at 6:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.