From Open Foris Wiki

Jump to: navigation, search

Rasterizes a shapefile to the resolution of a reference image

Usage: oft-shptif.bash [-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}] -i <shapefile> -ref <raster_reference> -o <raster_output> [-fn fieldname] [-nocompress]

(the old version of oft-shptif.bash <shapefile> <raster_reference> <raster_output> [fieldname] can still be used)

  • Input files:
    • shapefile that is supposed to be rasterized
    • reference raster image - the shapefile will be rasterized to the same extent and resolution of this image


 [-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}]: output data type
 [-fn fieldname]: the ''fieldname'' of the attribute of the shapefile that is supposed to be rasterized
 If no ''fieldname'' is specified, every polygon will be assigned an arbitrary, but unique ID. 
 [-nocompress]: The tool uses the ''compression'' option as provided by the gdal_rasterize command. This results in considerably smaller file sizes, but is known to lead to problems with certain software, i.e. Idrisi. 
 If -nocompress is specified, the output image will not be compressed.


  • Get Example data set
  • For this exercise following tools are used: oft-shptif.bash

1. We are going to rasterize the shapefile shapefiles/landuse.shp with images/landsat_t1.tif as a reference image. We are interested in the landuse specified in the shapefile, so we choose landuse as field name.

2. Run oft-shptif.bash:

 oft-shptif.bash -ot Byte -i shapefile/landuse.shp -ref images/landsat_t1.tif -ot results/raster_landuse.tif -fn landuse

3. Open the output results/raster_landuse.tif in QGIS, or use it for further calculations. For all areas without landuse information in the shapefile, value 0 will be recorded in the output image.

Back to Open Foris Toolkit Main Page

Back to Tools & Exercises

Personal tools