Reproject and rasterize a vector dataset
Reproject and rasterize a vector dataset. The grid of the rasterized output can be set by using a reference image, or by setting all parmeters (origin, size, spacing) by hand. In the latter case, at least the spacing (ground sampling distance) is needed (other parameters are computed automatically). The rasterized output can also be in a different projection reference system than the input dataset.
There are two rasterize mode available in the application. The first is the binary mode: it allows rendering all pixels belonging to a geometry of the input dataset in the foreground color, while rendering the other in background color. The second one allows rendering pixels belonging to a geometry with respect to an attribute of this geometry. The field of the attribute to render can be set by the user. In the second mode, the background value is still used for unassociated pixels.
This application has several output images and supports “multi-writing”. Instead of computing and writing each image independently, the streamed image blocks are written in a synchronous way for each output. The output images will be computed strip by strip, using the available RAM to compute the strip size, and a user defined streaming mode can be specified using the streaming extended filenames (type, mode and value). Note that multi-writing can be disabled using the multi-write extended filename option: &multiwrite=false, in this case the output images will be written one by one. Note that multi-writing is not supported for MPI writers.
Input vector dataset
-in vectorfile Mandatory
The input vector dataset to be rasterized
-out image [dtype] Mandatory
An output image containing the rasterized vector dataset
Input reference image
A reference image from which to import output grid and projection reference system information.
Output size x
Output size along x axis (useless if support image is given)
Output size y
Output size along y axis (useless if support image is given)
Output EPSG code
EPSG code for the output projection reference system (EPSG 4326 for WGS84, 32631 for UTM31N…,useless if support image is given)
Output Upper-left x
Output upper-left corner x coordinate (useless if support image is given)
Output Upper-left y
Output upper-left corner y coordinate (useless if support image is given)
Spacing (GSD) x
Spacing (ground sampling distance) along x axis (useless if support image is given)
Spacing (GSD) y
Spacing (ground sampling distance) along y axis (useless if support image is given)
-background float Default value: 0
Default value for pixels not belonging to any geometry
-mode [binary|attribute] Default value: binary
Choice of rasterization modes
- Binary mode
In this mode, pixels within a geometry will hold the user-defined foreground value
- Attribute burning mode
In this mode, pixels within a geometry will hold the value of a user-defined field extracted from this geometry.
-mode.binary.foreground float Default value: 255
Value for pixels inside a geometry
From the command-line:
otbcli_Rasterization -in qb_RoadExtract_classification.shp -out rasterImage.tif -spx 1. -spy 1.
import otbApplication app = otbApplication.Registry.CreateApplication("Rasterization") app.SetParameterString("in", "qb_RoadExtract_classification.shp") app.SetParameterString("out", "rasterImage.tif") app.SetParameterFloat("spx", 1.) app.SetParameterFloat("spy", 1.) app.ExecuteAndWriteOutput()