Filters the vertexes of a geometry object by M coordinate range and returns a new geometry object.
Syntax
geometry ST_FilterByM(geometry geom, double precision min, double precision max, boolean returnM)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
geom | geometry | — | The input geometry object. |
min | double precision | null | The minimum M coordinate value. Vertexes with M coordinates below this value are filtered out. |
max | double precision | null | The maximum M coordinate value. Vertexes with M coordinates above this value are filtered out. If null, only min takes effect. |
returnM | boolean | false | Specifies whether to include M coordinates in the returned geometry object. |
Usage notes
Returns a new geometry object containing only the vertexes whose M coordinate is ≥ min and ≤ max.
If
maxis null, onlyminis applied as the filter threshold.If too few vertexes remain after filtering, the function returns an empty geometry object.
If the input geometry object does not contain enough points, ST_SimplifyVW returns a geometry object that contains enough points, while ST_FilterByM returns an empty geometry object.
If the input is a GeometryCollection, objects that do not contain enough points are ignored.
The returned geometry object preserves all dimensions of the input, including Z and M coordinates.
This function may return an invalid geometry object.
Examples
Filter by M coordinate range (M ≥ 2 and M ≤ 4)
SELECT ST_AsText(ST_FilterByM('LINESTRINGM(0 0 0,1 1 1,2 2 2,3 3 3)'::geometry,2,4,true));Output:
st_astext
----------------------------
LINESTRING M (2 2 2,3 3 3)
(1 row)Filter that produces an empty result (only one vertex matches, which is not enough to form a line)
SELECT ST_AsText(ST_FilterByM('LINESTRINGM(0 0 0,1 1 1,2 2 2,3 3 3)'::geometry,3,4,true));Output:
st_astext
--------------------
LINESTRING M EMPTY
(1 row)