Monday, November 4, 2013

Burn or rasterize vectors onto GeoTiff images

Once a while I get an unusual request like burning contour vector lines onto GeoTiff images. It's a good thing the open source software GDAL has a gdal_rasterize utility to do the job. Here is an illustrated example of burning vector lines onto a raster image.
Input vector contour lines
Input raster GeoTiff file


  1. Open up a Windows Command Prompt.
  2. Type in the following command, (assuming the GDAL installation bin folder is in the system path).

    C:\> gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 0 -burn 0 -l contour contour.shp lub_tile1.tif

    Note 1: -burn 255 -burn 0 -burn 0 means burn the RGB color values (255, 0, 0).
    Note 2: -b 1 -b 2 -b 3 means to use the three bands of R, G, and B.
    Note 3: this utility will overwrite the input raster file, so make sure there is a backup copy of the file.


    The contour.shp vector lines are burned onto the GeoTiff file lub_tile1.tif.

4 comments:

  1. Thanks for the post. I had to expand the layers of my tiff to hold the three color band layers like below:

    [root@mysrv01 /]# gdal_translate -ot Byte -expand rgb /root/wfs2tiff/wmstiff.tif /root/wfs2tiff/wmsnew.tif

    Then it worked perfectly for me. Maybe this will help someone else.

    ReplyDelete
  2. To get this working, I had to expand the color layers from 1 layer to 3 layers like so:

    [root@mysrv01 /]# gdal_translate -ot Byte -expand rgb /somewhere/wmstiff.tif /somewhere/wmsnew.tif

    Then it worked perfectly. Maybe this will help someone else.

    ReplyDelete
  3. Thanks for the post. I had to expand the layers of my tiff to hold the three color band layers like below:

    [root@mysrv01 /]# gdal_translate -ot Byte -expand rgb /root/wfs2tiff/wmstiff.tif /root/wfs2tiff/wmsnew.tif

    Then it worked perfectly for me. Maybe this will help someone else.

    Can you control the output contour line widths in any way?

    ReplyDelete
  4. Thank you for posting this. I was able to overlay lines from a shapefile on top of a geotiff image, but the lines are very thin. Is there another option I could specify to increase the line width output?

    ReplyDelete