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).

  • 1
    Have you tried Raster -> Conversion -> Rasterize? Aug 29 '16 at 21:00

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

  • Thanks very much, that was very helpful and has gotten me most of the way there. I had to first reproject using this snippet I found elswehwere as I was getting errors: ogr2ogr -t_srs EPSG:102001 translated_output_dir shapefile.shp </br> Also it seems the attribute column I added needed to be in integers for the rasterization to work (I tried decimal values first and it gave me NaNs). </br> The problem I have now is that I can't save the new layer. I get "filename is not a supported raster data source"
    – user81613
    Aug 31 '16 at 2:53
  • Sorry, edit timed out before I could add in line breaks and @HDunn
    – user81613
    Aug 31 '16 at 3:00
  • Reprojected it and then I could save it
    – user81613
    Aug 31 '16 at 3:04

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.