[GIS] How to exclude missing values from raster layer

qgisraster

In my raster layers the value -999 means "missing". Those points completely mess up any colormap in qgis because qgis treats them as normal values and includes them in the classification.

I would like to ask

1) is there any raster format that allows for missing values ? (I mostly use geotiff)

2) how can I replace -999 with for example 0 in every raster-cell? QGIS raster-calculator does not seem to do this. I did not find anything like an inline if-function like if(val=-999,0,val)

Best Answer

Two options are available

You can either set values to zero '999 -> 0' or remove them entirely from the raster '999 -> nodata'.

  1. Set to zero '999 -> 0' with the raster calculator (Raster > Raster Calculator):

    ("my_rasterA@1" > -999) * "my_rasterA@1"

  2. Set to NA '999 -> nodata', use Translate (Raster > Conversion > Translate) Save the output from the previous step with the raster calculator and use it as the input for this step.

    gdal_translate -a_nodata 0 -of GTiff "C:/Users/Desktop/my_rasterA.tif" "C:/Users/Desktop/my_output.tif"

*** note: when using translate be sure to add the -a_nodata 0 in the little editing window at the bottom & click ok while you are still in editing mode.