VectorFilter

Keeps the features of a vector that satisfy a filter, written in ECQL: a condition on their fields, as the sub-basins larger than a hectare, or on their geometry, as the features inside a box or near a point.

Details

The filter is written in ECQL, the extended Common Query Language of GeoTools and GeoServer. It compares the fields, by the names they have in the vector, with values and with each other, and joins the comparisons with AND, OR and NOT, as in area > 10000 AND avgelev < 1800. Text values go between single quotes, as name = ‘Rio Torto’, and LIKE matches them with % as wildcard: name LIKE ‘Rio%’. Other forms are netnum IN (1, 2, 3), avgelev BETWEEN 1500 AND 2000 and name IS NULL. The comparisons can use expressions too, as maxelev - minelev > 300.

The geometry, the_geom in a shapefile, is filtered with the spatial functions, with geometries in WKT and in the crs of the vector: INTERSECTS(the_geom, POINT(1638500 5112500)), BBOX(the_geom, 1637000, 5111000, 1638000, 5112000) or DWITHIN(the_geom, POINT(1638500 5112500), 100, meters).

Parameters

Keeps the features of a vector that satisfy a filter on their attributes or on their geometry.

Toolbox folder: Vector Processing
Status: Certified
Keywords: Filter, Vector, CQL, ECQL, Select
Authors: Andrea Antonello
Class: org.hortonmachine.modules.VectorFilter

Inputs

Parameter

Type

Unit

Default

Description

inVector

vector file

The vector to filter.

pCql

String

The ECQL filter, as area > 10000 AND name LIKE ‘Rio%’.

Outputs

Parameter

Type

Unit

Description

outVector

output file

The filtered vector.

Example

The example keeps the cells of the grid of RasterCatToFeatureAttribute that are high, with a mean elevation above 1900 m and no part below 1700 m:

import org.hortonmachine.modules.VectorFilter

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

var filter = new VectorFilter()
// the cells with the elevation of RasterCatToFeatureAttribute
filter.inVector = folder + "grid_elev.shp"
// the cells above 1900 m, also in the lower part
filter.pCql = "elev_avg > 1900 AND elev_min > 1700"
filter.outVector = folder + "grid_high.shp"
filter.process()

Of the 49 cells, 3 satisfy both conditions: two on the ridge along the northern border and one on the eastern border:

The three cells of the grid above 1900 m