15

I'm having problems with QGIS. I have some rasters that appear to have NULL values, even though I reclassified them to obtain a Boolean raster.

How can I change the NULL values to 0?

4 Answers 4

16

beside @R.K. answer, you can use r.null in grass too.

r.null - Manages NULL-values of given raster map.

EXAMPLES

Set specific values of a classified map to NULL:

r.null map=landcover.30m setnull=21,22

Set NULL-values of a map to a specific value:

 r.null map=fields null=99

i hope it helps you...

9

I think the RasterCalc plugin should be able to solve your problem. Once you've installed it, you can use the following query (assuming that NULL values corresponds to -9999; you can check this value in Transparency tab of the Layer Properties):

eq( [your_raster]@1, -9999, 0 )

eq means equal to. This tells RasterCalc that all pixels in your raster with NULL values should have their values set to 0. I'm assuming you have a single band raster.

3
  • 1
    This doesn't seem to work (QGIS 1.8 / Rastercalc 0.2.5) - giving "expression invalid" with a loaded raster, e.g. eq( EL_hm@1, NULL, 0 )
    – Simbamangu
    Commented Nov 10, 2012 at 4:35
  • 1
    @Simbamangu, if you will use actual value used as NULL (-9999 for example) - this will work. e.g eq( EL_hm@1, -9999, 0 ) Commented Mar 6, 2013 at 20:47
  • 1
    @SS_Rebelious - you might want to mention in your edit that the NULL value can be set in the preferences (General|Representation for NULL values) and this should be reflected in the expression.
    – Simbamangu
    Commented Mar 7, 2013 at 4:53
2

I don't know if you solved this? There may be a more streamlined way but this works fine for me in the latest QGIS (v2.8.1):

  1. Create a new polygon with an attribute column for height/level. draw a polygon shape with a larger extent than the raster extent you want to change.
  2. rasterise this polygon using raster > conversion > rasterise tool.
  3. using GDAL Analysis tools > fill no data > and the rasterised polygon as the validity layer.
  4. The resultant raster file should now have values where previously there was no data. These will either be some random value below 0 (-9999 for example) or 0. If it is 0 then great you've got what you wanted. If it is not, carry out step 5.
  5. using SAGA > Grid -Tools > Mosaick Raster Layers input the filled raster layer and the rasterised polygon. in overlapping areas select [3] Maximum and set the output extent to your original raster. This should result in a new raster that retains all of your values over 0 while giving your previous no data values a new value of 0.
1

Is there not a simpler solution, using "Fill NoData cells". As the tool states "This algorithm resets the NoData values in the input raster to a chosen value, resulting in a raster dataset with no NoData pixels. This value can be set by the user using the Fill value parameter. The algorithm respects the input raster data type (eg. a floating point fill value will be truncated when applied to an integer raster)." So in one move, you can reset the nodata cells to any new value you want.enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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