VectorReshaper

Changes the attributes and the geometries of a vector with expressions: it adds fields computed from the other fields or from the geometry, replaces existing ones, and removes the fields not needed. The geometries can be transformed as well, into buffers, centroids or convex hulls.

Details

The expressions are written one per line, as name=expression in ECQL. An expression with the name of an existing field replaces it, a new name adds a field; the other fields are kept, except the ones listed to be removed. The type of each field is taken from its value on the first feature.

Some examples, for a layer whose geometry field is the_geom, as in shapefiles:

  • the_geom=centroid(the_geom): the centroids of the polygons.

  • the_geom=buffer(the_geom, 20.0): a buffer of 20 map units.

  • the_geom=convexHull(the_geom): the convex hulls.

  • area=area(the_geom) and length=geomLength(the_geom): new fields with the area and the perimeter.

  • newfield=-1: a new field with a constant value.

Parameters

Module to reshape a vector.

Toolbox folder: Vector Processing
Status: Certified
Keywords: Reshape, Vector, OmsVectorFilter
Authors: Andrea Antonello, Jody Garnett
Class: org.hortonmachine.modules.VectorReshaper

Inputs

Parameter

Type

Unit

Default

Description

inVector

vector file

The vector to reshape.

pCql

String

The ECQL reshape function.

pRemove

String

The list of fields to remove, comma separated.

Outputs

Parameter

Type

Unit

Description

outVector

output file

The new reshaped vector.

Example

The example runs on the polygons of the sub-basins of BasinShape, extracted from the sample elevation model of the manual:

import org.hortonmachine.modules.VectorReshaper

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

var reshaper = new VectorReshaper()
// the sub-basins of BasinShape
reshaper.inVector = folder + "subbasins.shp"
// two new fields: the relief of the sub-basin and its area in square kilometers
reshaper.pCql = """relief=maxelev-minelev
area_km2=area/1000000"""
// the height is not needed any more
reshaper.pRemove = "height"
reshaper.outVector = folder + "subbasins_reshaped.shp"
reshaper.process()

The first sub-basins, before:

netnum

area

perimeter

maxelev

minelev

avgelev

height

1

38100

2360

2143.2

1731.3

2009.0

2013.9

2

10500

680

2150.3

2023.9

2099.7

2098.9

3

10000

640

2148.4

2023.1

2088.0

2085.4

and after:

netnum

area

perimeter

maxelev

minelev

avgelev

relief

area_km2

1

38100

2360

2143.2

1731.3

2009.0

411.9

0.0381

2

10500

680

2150.3

2023.9

2099.7

126.4

0.0105

3

10000

640

2148.4

2023.1

2088.0

125.3

0.0100