9

Rasterizing a vector (shp) I face the following problem: I want my output file (the rasterized vector) to have the same resolution and dimensions as an existing raster.

If I understand the interface correctly, the option "keep size and resolution of existing layer" should do this job. However, there is no option to choose an existing layer. Any hints?

Of course, I can achieve (at least approximately) what I want to do using the –te and –tr parameters. However it would be interesting to know if and how the "keep seize and resolution of existing layer" works.

7
  • The gdal_rasterize command can use an existing raster; before 1.8 the raster had to exist before running the command. If you can copy the existing raster and then supply it to the gdal_rasterize then it should do what you want. Jul 24 '14 at 0:17
  • 1
    Sorry Michael, I´m afraid I don´t understand what you mean. I currently use this parametres: gdal_rasterize -a adecuado -l vector_2 -tr 15.00 -15.00 -te 403326.00 1853140.00 461517.00 "...\\vector_2.shp" ".../output.tif" This works. However, my question would be if have to put this values (resolution, extension) manually, or can I use the "keep size and resolution of existing layer" option to load this values automatically from a given raster file?
    – Flo
    Jul 24 '14 at 0:53
  • What I am saying is that if you copy existing.tif to output.tif and then use gdal_rasterize (with no fancy options) "...\\vector_2.shp" ".../output.tif" it will use the existing raster thus keeping the cell size and extent. Jul 24 '14 at 0:56
  • 3
    Yes, that is the intent. The C function for rasterize (GDALRasterizeGeometries) must have an existing raster; if you supply a raster path to the tool that doesn't exist the first thing it does is create the raster and then rasterize using that. Jul 24 '14 at 3:16
  • 3
    It does not overwrite existing raster it just burns pixels into it. Create a background raster from a big polygon that covers your data as all white and you should be fine.
    – user30184
    Jul 24 '14 at 9:34
1

In QGIS, you should be able to achieve this with the GDAL Rasterize (Overwrite with Attribute) algorithm (available in the Processing Toolbox).

  1. Make a copy of your raster layer (Layer-> Save as...) - specify a file name (e.g. baseraster.tif) and location.

  2. Run the Rasterize (Overwrite with Attribute) algorithm.

    1. Choose the vector layer you would like to rasterize as Input vector layer.

    2. Choose baseraster.tif as Input raster layer.

    3. Choose the attribute of the input vector layer to use for the rasterization in Field to use for burn in value.

    4. Do not tick/check Add burn in values to existing raster values.

The output raster should have the same resolution, extent and no data cells as the base raster, and cell/pixel values should be taken from the input vector 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.