In QGIS, I have two layers: raster and vector (green colored) of the same area of interest. Now, I want to assign "1" to the pixels which lie within the green region, and for the rest assign 0. How can I handle that? Is that possible?
1 Answer
Rasterize the polygon layer: Menu Raster / Conversion /Rasterize (Vector to Raster)
Set 1
for A fixed value to burn
and set Assign a specified nodata value to output bands
to Not set
. You get a new raster layer with pixels = 1 where the polygons are and 0 everywhere else. Use the desired extent for the new raster (e.g. select the extent and resolution of your existing raster). Be aware that all layers have the same CRS.
Output: white=1, black=0