I need to convert all the values in a raster to one certain value. How can I do this? (I tried using raster calculator, but any operation that would result in a raster having all one value makes it create a raster with no data for whatever reason)

I tired using constant grid, and it also makes rasters with no data

My inputs were: enter image description here

The raster I created showed no data:

enter image description here

To make sure, I looked at the histogram of data values, and it confirms no data (the data should be all 1) enter image description here

  • Miltiply raster with zero and + value. R*0+1
    – nagib
    May 12 '18 at 6:47

Just in case you have nodata value in your original raster, SAGA Constant Grid would come in handy.

From QGIS Processing toolbox, go to SAGA | Raster Tools.

On the Constant grid window:

  • Name: Give any name (value, my_raster, ...) (*1)
  • Constant Value: Your aimed value.
  • Data Type: Select your required data type (*2)
  • Target Grid System: Select [1] grid or grid system
  • Ignore Cellsize, Left, Right, Bottom, Top, and Fit
  • Target System [optional]: Select your original raster layer.
  • Ignore Advanced parameters.

(*1) Honestly I do not know why this is needed.

(*2) as of QGIS 2.18.19, it seems SAGA returns Float32 raster regardless which Data Type we choose. If you need integer raster (e.g. 0-255), please try Convert data storage type to obtain 1-byte integer following this operation.


The appearance of output layer (name Target Grid) may not look successful, in the Layers panel.

If in doubt, please check the cell values by (1) Load min/max values. or (2) using Identify Feature tool.

  • It didn't work (I put a picture of the error in the original question)
    – Shane
    May 13 '18 at 8:05
  • @Shane I think you have forgotten your original raster layer to put into the Target System. That's why your picture (error message) does not show -TEMPLATE option.
    – Kazuhito
    May 13 '18 at 8:31
  • I see that now...
    – Shane
    May 13 '18 at 20:27
  • I'm not sure what happened the first time I tried, but the pictures were from a run that was solely to reproduce the error; clearly I'd gotten a bit sloppy by that point
    – Shane
    May 13 '18 at 20:32
  • @Shane your raster with cell value 1 was created successfully.
    – Kazuhito
    May 13 '18 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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