RasterVectorIntersector

Cuts a raster with polygons: it keeps the values of the cells inside the polygons, or with the inverse switch the ones outside, and sets the others to novalue, on the same grid. It keeps, for example, the elevation of a basin from its polygon, or blanks the lakes of an elevation model.

It does in one step what ScanLineRasterizer, with the raster as grid, and CutOut do in two. To also shrink the grid to the polygons, use RasterResizer.

Details

A cell is inside when its center is inside a polygon, as in ScanLineRasterizer, that makes the mask of the polygons on the grid of the raster; CutOut then keeps the values under the mask, or the ones outside of it with the inverse switch. The other cells become novalue, the grid doesn’t change: to also shrink the grid to the polygons, RasterResizer is the tool.

It is the one step version of ScanLineRasterizer with the raster as grid, followed by CutOut, for example to keep the elevation of a basin from its polygon, or to blank the lakes of an elevation model.

Parameters

Cuts a raster with polygons: keeps the cells inside them, or with the inverse switch the cells outside.

Toolbox folder: Raster Processing
Status: Certified
Keywords: Raster, Vector, Intersect, Clip, Mask
Authors: Andrea Antonello
Class: org.hortonmachine.modules.RasterVectorIntersector

Inputs

Parameter

Type

Unit

Default

Description

inVector

vector file

The polygons to cut the raster with.

inRaster

raster file

The raster to cut.

doInverse

boolean

false

If true, keeps the cells outside of the polygons instead of the ones inside.

Outputs

Parameter

Type

Unit

Description

outRaster

output file

The cut raster.

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 cuts the elevation with the high cells of the VectorFilter example, and with its inverse:

import org.hortonmachine.modules.RasterVectorIntersector

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

// the elevation inside the high cells of the VectorFilter example
var intersector = new RasterVectorIntersector()
intersector.inRaster = folder + "dtm_flanginec.tif"
intersector.inVector = folder + "grid_high.shp"
intersector.outRaster = folder + "dtm_high_cells.tif"
intersector.process()

// and the elevation outside of them
intersector = new RasterVectorIntersector()
intersector.inRaster = folder + "dtm_flanginec.tif"
intersector.inVector = folder + "grid_high.shp"
intersector.doInverse = true
intersector.outRaster = folder + "dtm_not_high_cells.tif"
intersector.process()
The elevation inside the high cells of the VectorFilter example.

The elevation inside the high cells.

The elevation outside of the high cells, with the inverse switch.

The elevation outside of them, with the inverse switch.