RasterTransformer

Flips, rotates, scales and translates a raster. The flips and the rotation move the values on the grid; the scale and the translation change only where the raster lies, its georeference. The typical uses are a raster with a wrong georeference, as a scanned map placed by hand or a grid with the rows upside down, and the rotation of a model to align it with a direction, as the axis of a valley or of a flume.

The rotation needs new values for the cells of the rotated grid: the nearest cell suits the classes, the bilinear interpolation the continuous values, as the elevation. To change the reference system of a raster, use RasterReprojector.

Details

The transformations are applied in this order: the flips, the rotation, the scale, the translation. The flips mirror the columns (horizontal) or the rows (vertical) on the same grid. The rotation, counterclockwise in degrees, turns the raster around the pivot, which is the given point or else the center of the raster: the result covers the whole rotated raster, on cells of the same size, and the cells outside of it are novalue. Their values come from the nearest input cell, or are interpolated between the four nearest cell centers with the bilinear interpolation, that suits the continuous values but not the classes. The other transformations don’t touch the values.

The scale multiplies the size of the cells around the same pivot, and the translation moves the raster, in the units of its reference system: they change only where the raster lies, as to fix a raster with a wrong georeference or a scan placed by hand. The bounds output is the outline of the transformed raster, rotated with it.

Parameters

Flips, rotates, scales and translates a raster.

Toolbox folder: Raster Processing
Status: Certified
Keywords: Transform, Rotate, Flip, Scale, Translate, Raster
Authors: Andrea Antonello
Class: org.hortonmachine.modules.RasterTransformer

Inputs

Parameter

Type

Unit

Default

Description

inRaster

raster file

The raster to transform.

pInterpolation

String

nearest neightbour

The interpolation of the values of the rotated raster. Allowed values: nearest neightbour, bilinear.

pTransX

Double

m

The translation along the X axis.

pTransY

Double

m

The translation along the Y axis.

pScaleX

Double

The scale factor along the X axis.

pScaleY

Double

The scale factor along the Y axis.

doFlipHorizontal

boolean

false

Flip horizontally, mirroring the columns.

doFlipVertical

boolean

false

Flip vertically, mirroring the rows.

pNorth

Double

The northing of the pivot of rotation and scale (default the center of the raster).

pEast

Double

The easting of the pivot of rotation and scale (default the center of the raster).

pAngle

Double

degrees

The counterclockwise rotation angle.

Outputs

Parameter

Type

Unit

Description

outRaster

output file

The transformed raster.

outBounds

output file

The outline of the transformed raster.

Example

The example runs on the sample elevation model of the manual, dtm_flanginec.tif in docs/manual/modules/maps/data. It rotates the elevation model by 30 degrees counterclockwise:

import org.hortonmachine.modules.RasterTransformer

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

// the elevation model turned by 30 degrees counterclockwise around its center
var transformer = new RasterTransformer()
transformer.inRaster = folder + "dtm_flanginec.tif"
transformer.pAngle = 30.0
// the elevation is continuous: the values are interpolated
transformer.pInterpolation = "bilinear"
transformer.outRaster = folder + "dtm_rotated.tif"
// the outline of the rotated raster
transformer.outBounds = folder + "dtm_rotated_bounds.shp"
transformer.process()
The elevation model rotated by 30 degrees, on a larger grid with novalue corners.

The elevation model rotated by 30 degrees: the grid covers the whole rotated raster, the corners outside of it are novalue.