[GIS] How to ‘fill’ a region in a raster layer specified by a shape with a value

fillqgisrrastershapefile

I have a shapefile for a country, made up of a shape per province. I want to create a raster layer in the shape of the country and for each pixel in the area covered by province 1 set the value to value1, for the area covered by province 2, set the pixels to value2, etc. I want the pixels to represent 1km/1km resolution.

I've tried various ways to go about this, but the closest I've come is some combination of creating a constant raster layer and cropping it to the whole country boundary, and I've had some trouble getting anywhere with that and suspect it's not the best way to go about it.

I'm using QGIS, but can switch to anything open-source that helps (GDAL, R, etc).

Best Answer

What you're describing is a basic vector to raster conversion. In your country .shp file, make sure that there's a unique numeric value that corresponds to each province.

See example of NYC, with a number for each of the 5 boroughs. enter image description here

Using the Vector to Raster conversion tool, make sure to define the aforementioned field as your Attribute Field, and the raster resolution to 1 Km.

In this example, I've set a field named "Value" with values 1 - 5, and my resolution is 1000 meters. Note that I'm using a projected CRS in meters (NAD State Plane), and not a geographic CRS, as its units are degrees.

enter image description here

The resulting raster will have the value for each part as was defined in the value field, and cell resolution of 1 Km

enter image description here

Related Question