ScanLineRasterizer

Converts polygons into a raster: the cells whose center is inside a polygon get a value, the others are novalue. The value can be:

  • a constant, to make a mask of the polygons;

  • the value of a numeric field of each polygon, as a class of land use or a parameter of a soil map, to turn a vector map into the input raster of a model;

  • the value of a raster, when neither of the others is given: the raster is then cut with the polygons.

The grid of the raster is given by its bounds and its number of rows and columns, or it is taken from a raster, which must have the coordinate reference system of the polygons. Only polygons are supported. For lines, use LinesRasterizer; for points, PointsRasterizer.

The module crosses the polygons with a line through the centers of each row of cells, the scanline, and fills the cells between the crossings, in parallel for the polygons. On geometries where this fails, the point in polygon mode checks the center of each cell instead: it is slower, needs a raster for the grid and uses only a constant value.

Details

The polygons are intersected with a line through the centers of each row of cells, the scanline, and the cells between the intersections are filled. The grid is given by its bounds and number of rows and columns, or taken from a raster, which must have the CRS of the polygons.

The value of the cells is the constant value if given, else the value of the field of each polygon. With a raster and neither of them, the cells take the values of the raster: the result is the raster cut with the polygons.

Only polygons are supported. Where they overlap, the cells take the value of one of them. If the scanline fails on complex geometries, the point in polygon mode checks the center of each cell against the union of the polygons instead: it is slower, needs a raster for the grid, and uses only the constant value.

Parameters

Converts polygons to a raster: the cells whose center is inside a polygon get a value, the others are novalue. The value is a constant, the one of a field of the polygon, or the one of a raster, which so gets cut by the polygons.

Toolbox folder: Raster Processing
Status: Certified
Keywords: Raster, Vector, Rasterize
Authors: Andrea Antonello
Class: org.hortonmachine.modules.ScanLineRasterizer

Inputs

Parameter

Type

Unit

Default

Description

inVector

vector file

The polygons to rasterize.

pValue

Double

The constant value of the cells inside the polygons. If given, it is used instead of the field.

fCat

String

The numeric field of the polygons with the value of their cells.

pNorth

Double

The north bound of the region to consider

pSouth

Double

The south bound of the region to consider

pWest

Double

The west bound of the region to consider

pEast

Double

The east bound of the region to consider

pRows

Integer

The rows of the region to consider

pCols

Integer

The cols of the region to consider

pUsePointInPolygon

Boolean

false

If true, the slower point in polygon mode is used, for the geometries where the scanline fails. It needs the raster and the constant value.

inRaster

raster file

An optional raster that gives the grid, instead of bounds, rows and columns; without value and field, also the values of the cells.

Outputs

Parameter

Type

Unit

Description

outRaster

output file

The rasterized polygons.

Example

The example runs on the sample elevation model of the manual, dtm_flanginec.tif in docs/manual/modules/maps/data, each module on the outputs of the previous ones. It rasterizes the subbasins of BasinShape with their mean elevation:

import org.hortonmachine.modules.ScanLineRasterizer

// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"

// the subbasins of BasinShape, each with its mean elevation, on the grid of the elevation model
var rasterizer = new ScanLineRasterizer()
rasterizer.inVector = folder + "subbasins.shp"
rasterizer.inRaster = folder + "dtm_flanginec.tif"
rasterizer.fCat = "avgelev"
rasterizer.outRaster = folder + "subbasins_avgelev.tif"
rasterizer.process()
The subbasins rasterized with their mean elevation: each subbasin is a single value, from the low ones near the outlet to the high ones near the ridges.

The subbasins rasterized with their mean elevation: each subbasin is a single value, from the low ones near the outlet to the high ones near the ridges.