3

I have a shapefile that is a set of polygons. I would like to export it as a black and white image to use as a mask. I'm not incorporating height data (the shapefile only holds 2D data), but encoding whether a pixel is part of a polygon or not so that I get a replica of the spatial layout of the polygons in a raster image.

How would I do this in QGIS? I cannot find an obvious path.

4

If I understand your issue: I would use the Rasterize (Vector to Raster) algorithm in the processing toolbox. Set your polygon layer as the input. Set the burn in value to 1. Set your desired pixel size in georeferecnce units, and your desired extent etc. This will result in a layer that has 1 as the values in the polygon areas and nodata in all other cells. If you want to have 0 in the other cells use the advanced section and set the pre-initialization value to 0. You may also have to set the nodata value to something like 255. enter image description here

1
  • In my case, in order to get the shapefiles rasterized, I had to use Pixels as the Output raster size units, or else the command would fail. Nov 30 '21 at 7:03
1

You could try to use 'Clip raster by mask layer' to mask your raster layer.

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.