ST_FilterByM

更新时间:
复制 MD 格式

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

ParameterTypeDefaultDescription
geomgeometryThe input geometry object.
mindouble precisionnullThe minimum M coordinate value. Vertexes with M coordinates below this value are filtered out.
maxdouble precisionnullThe maximum M coordinate value. Vertexes with M coordinates above this value are filtered out. If null, only min takes effect.
returnMbooleanfalseSpecifies 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 max is null, only min is 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)