RasterCatToFeatureAttribute

Adds to the features of a vector the values of a raster below them. The points and the lines take the value of a cell, as the elevation of the wells or the land use at the start of the roads; the polygons take the minimum, maximum, mean and sum of the cells inside them, as the mean elevation of the sub-basins or the rain volume on a municipality.

Details

A point takes the value of the cell it falls in, a line the one of the cell of its first, middle or last vertex, as set by the position: the middle one is the vertex in the middle of the list of the vertices, not the point at half of the length. The value goes in the new field, or in the existing field with that name. Novalues are written as -9999. The points and lines outside the raster are left out of the output.

A polygon gets four fields, with the name of the new field followed by _min, _max, _avg and _sum: the minimum, maximum, mean and sum of the valid cells with the center inside the polygon. The sum of a raster of rain heights in mm, for example, times the cell area, gives the volume on the polygon, and the mean of an elevation model the mean elevation of a basin.

Parameters

Adds to the features of a vector the values of a raster below them: the value at the points and lines, the statistics of the cells inside the polygons.

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

Inputs

Parameter

Type

Unit

Default

Description

inRaster

raster file

The raster on which to map the vector features.

inVector

vector file

The vector to use for the geometric mapping.

fNew

String

new

The name for the new field to create (if existing, the field is populated).

pPos

String

middle

The vertex of the lines where to take the value: start, middle or end. Allowed values: start, middle, end.

Outputs

Parameter

Type

Unit

Description

outVector

output file

The extended vector.

Example

The example adds the elevation statistics of the sample elevation model to the cells of GridsGenerator:

import org.hortonmachine.modules.RasterCatToFeatureAttribute

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

var rat2feature = new RasterCatToFeatureAttribute()
rat2feature.inRaster = folder + "dtm_flanginec.tif"
// the cells of GridsGenerator
rat2feature.inVector = folder + "grid.shp"
// the polygons get the fields elev_min, elev_max, elev_avg and elev_sum
rat2feature.fNew = "elev"
rat2feature.outVector = folder + "grid_elev.shp"
rat2feature.process()

Each cell of 500 m has 2500 cells of the elevation model of 10 m inside it. The first cells, along the southern border from the west:

id

elev_min

elev_max

elev_avg

elev_sum

0

961.2

1198.8

1078.6

2696518

1

1137.4

1452.8

1303.8

3259448

2

1341.7

1639.6

1520.5

3801347

3

1612.8

1847.3

1743.0

4357500

The cells colored by their mean elevation:

The cells of the grid colored by their mean elevation