RasterGenerator

Creates a new raster from nothing, on a grid given by its bounds, cell size and reference system, with a constant value or with random values. Its use is to make a grid where there is no data yet, for the modules that take the grid from a raster: Mapcalc, SurfaceInterpolator and the rasterizers, as ScanLineRasterizer. The random values, with a seed to get the same ones at every run, give test data or the noise for a simulation.

Details

It is the module that makes a grid from nothing: Mapcalc, SurfaceInterpolator and the rasterizers need a raster that gives them the grid, and this one gives it where there is no data yet, as for a synthetic terrain or the interpolation of points over a new area. The grid starts at the north-west corner: the number of columns and rows is the extent divided by the cell size, rounded, and the east and south bounds are moved so that the cells have exactly the given size.

The cells get the constant value, or with the random switch a value drawn uniformly between the offset and the offset plus the scale. The seed makes the random raster the same at every run; without it, every run gives a different one.

Parameters

Creates a new raster on a grid defined by its bounds, cell size and reference system, with a constant or random value.

Toolbox folder: Raster Processing
Status: Certified
Keywords: Raster, Generator, Grid, Random
Authors: Andrea Antonello, Silvia Franceschi
Class: org.hortonmachine.modules.RasterGenerator

Inputs

Parameter

Type

Unit

Default

Description

pNorth

Double

The north bound of the grid.

pSouth

Double

The south bound of the grid.

pWest

Double

The west bound of the grid.

pEast

Double

The east bound of the grid.

pXres

Double

The cell size in x.

pYres

Double

The cell size in y.

pCode

CRS code

The code defining the coordinate reference system, composed by authority and code number (ex. EPSG:32632).

pValue

double

0

The value of the cells.

doRandom

boolean

false

If true, the cells get random values instead of the constant one.

pOffset

double

0

The lowest random value.

pScale

double

1.0

The width of the range of the random values.

pSeed

Long

An optional seed, to get the same random values at every run.

Outputs

Parameter

Type

Unit

Description

outRaster

output file

The generated raster.

Example

The example makes a grid of 10 m on an area without data, and fills it with a synthetic terrain through Mapcalc, with a shorter version of the fractal terrain of the Mapcalc page:

import org.hortonmachine.modules.Mapcalc
import org.hortonmachine.modules.RasterGenerator

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

// a grid of 10 m cells on an area of 5 x 4 km without any data
var generator = new RasterGenerator()
generator.pWest = 1650000.0
generator.pEast = 1655000.0
generator.pSouth = 5100000.0
generator.pNorth = 5104000.0
generator.pXres = 10.0
generator.pYres = 10.0
generator.pCode = "EPSG:3003"
generator.outRaster = folder + "new_grid.tif"
generator.process()

// Mapcalc fills the grid with a synthetic terrain: 4 octaves of value noise, as in the Mapcalc page
var mapcalc = new Mapcalc()
mapcalc.inRaster1 = folder + "new_grid.tif"
mapcalc.pFunction = """
images { synthetic_terrain = write; }
z = 800;
amp = 400;
wave = 1200;
foreach (k in 0:3) {
    u = x() / wave;
    v = y() / wave;
    i = floor(u);
    j = floor(v);
    su = (u - i) * (u - i) * (3 - 2 * (u - i));
    sv = (v - j) * (v - j) * (3 - 2 * (v - j));
    h = sin(i * 12.9898 + j * 78.233 + k) * 43758.5453;
    n00 = h - floor(h);
    h = sin((i + 1) * 12.9898 + j * 78.233 + k) * 43758.5453;
    n10 = h - floor(h);
    h = sin(i * 12.9898 + (j + 1) * 78.233 + k) * 43758.5453;
    n01 = h - floor(h);
    h = sin((i + 1) * 12.9898 + (j + 1) * 78.233 + k) * 43758.5453;
    n11 = h - floor(h);
    z += amp * (n00 + (n10 - n00) * su + (n01 - n00) * sv + (n00 - n10 - n01 + n11) * su * sv);
    amp *= 0.45;
    wave /= 2;
}
synthetic_terrain = z;
"""
mapcalc.outRaster = folder + "synthetic_terrain.tif"
mapcalc.process()
A synthetic terrain of hills, computed by Mapcalc on the grid of RasterGenerator.

The synthetic terrain computed by Mapcalc on the new grid.