3

I have a vector file which I want to rasterize and adjust its resolution to the reference map, in QGIS.

I tried spatial_sync_raster function in R to set all the rasters into the same resolution as that of the reference raster layer. It worked but the result was not as good as expected, because the outputs came out with different resolutions (see examples below).

I want to set the resolution of "u" as that of "g".

u
class       : RasterLayer 
dimensions  : 130, 228, 29640  (nrow, ncol, ncell)
resolution  : 0.01213899, 0.01213899  (x, y)
extent      : 12.111, 14.87869, 51.68928, 53.26734  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 

g
class       : RasterLayer 
dimensions  : 189, 332, 62748  (nrow, ncol, ncell)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : 12.10837, 14.87503, 51.7, 53.275  (xmin, xmax, ymin, ymax)

Does anyone know how to adjust the resolution whilst rasterizing the vector file?

  • i used "u" as a reference but i wanted to change the resolution of "u" before using the function "spatial_sync_raster". I have now changed the resolution of "u" so that i can use it as a reference for another raster layers. Thank you! :) @AndreSilva – Cynical Realism Dec 18 '14 at 9:28
  • @AndreSilva Okay.The raster file i wanted to take as a reference did not have the resolution I wanted so i wanted to adjust the resolution of that layer before using the function "spatial_sync_raster". Since that file was in vector format I had to rasterise it first. Whilst rasterising it I changed the resolution.(I had to reproject the raster layer so I changed the resolution to my preference) and finally used it as a reference raster layer to set all other raster layers to the same extent,projection and resolution.I'm sorry if my question in the beginning was wrongly put.Thank you tho! – Cynical Realism Dec 18 '14 at 13:38
  • @AndreSilva and yes the "u" ang "g" are the output i got in R. – Cynical Realism Dec 18 '14 at 13:42
2

Use the Rasterize (Vector to Raster) tool in QGIS. Go to Raster -> Conversion -> Rasterize. Assuming your vector file and the reference raster (g) are in the same coordinate reference system (CRS), do the following:

  1. Browse the input file (shapefile).
  2. Define which attribute from shapefile to assign in the raster cells.
  3. Choose path and name for the output raster.
  4. Define the raster size in pixels. This will be equal to nrow and ncol from the reference raster.
  5. Click the edit button to alter the gdal_rasterize command line. Add the argument -te to include: xmin, ymin, xmax and ymax values. Copying such values from the reference raster: -te 12.10837, 51.7, 14.87503, 53.275

enter image description here

The final command line would be like this:

gdal_rasterize -a attribute_name -ts 189 332 -te 12.10837, 51.7, 14.87503, 53.275 <src_datasource> <dst_filename>

For more help in parameterizing the gdal_rasterize tool, see here.

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.