I have a raster (TIFF file) and I would like to draw a mask on it. So, I basically create a shapefile and draw polygons on the area I wanted to mask. Then, I would like to rasterize this shapefile by creating a raster with the same extent than the raster file. This new raster must have only 0 and 1 values (1 for accepting value, 0 for not accepting).

The problem is that with the common Vector to Raster on the default plugin of QGIS, if I select the raster to get the extent (on the options), it's creating a TIFF with the initial raster value and change only the value on the polygon.

I can't draw these kind of mask on PhotoShop because the TIFF is on int16 and so, if I open it on PhotoShop I have a black image.

At this stage, the image isn't referenced. I just want to overlay a mask of 0-1 value upside the initial raster.

Is there a simple way to do tha? I can't find anything on the web... Plugin "Mask" don't do what I want.


Instead of using the original raster as the input extent you could create a duplicate of that original, reset its values to something else using the raster calculator, and then use that new dataset as the extent input.

In raster calculator:

Create a new raster using a formula like:

InputRaster/InputRaster * x

Make 'x' a unique value that you can easily change later i.e. not one you want to use for your polygons. Make sure the output raster is set to have the same extent as the original.

Create your polygons and run the polygon to raster tool. Use the newly created raster as your extent input. This will stamp your polygon values on top.

Use one of the raster reclassify tools to set the value of 'x' to whatever you need it to be.

  • Thank's for your answer. When I write "IMGname@1" / "IMGname@1", the outfile tif resulting from this operation is a tif full of nan. It's strange
    – Lionel
    Oct 8 '18 at 11:55
  • Hi - that is a little odd. I would suggest loading it into QGIS and then doing a right-click -> save as and saving it as a new file. There may be something about the file that QGIS doesn't like. If not can you share the file and I can take a look? Oct 8 '18 at 13:52

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.