ST_Force3DM

更新时间:
复制 MD 格式

Forces a geometry into XYM mode, retaining X and Y coordinates, adding M (measure) coordinates, and removing Z coordinates if present.

Syntax

geometry ST_Force3DM(geometry geomA);

Parameters

ParameterDescription
geomAThe input geometry to convert.

Description

ST_Force3DM converts any geometry to XYM mode:

  • No M coordinate present: M is set to 0 for all vertices.

  • Z coordinate present: Z is removed from all vertices.

Supports circular strings and curves.

Examples

Convert a 2D point to XYM

No M coordinate is present, so M is set to the default 0:

SELECT ST_AsEWKT(ST_Force3DM(ST_GeomFromEWKT('POINT(1 2)')));
  st_asewkt
---------------
 POINTM(1 2 0)
(1 row)

Strip Z from a 3D point and add M

Z is removed and M is set to 0:

SELECT ST_AsEWKT(ST_Force3DM(ST_GeomFromEWKT('POINT(1 2 3)')));
  st_asewkt
---------------
 POINTM(1 2 0)
(1 row)

Convert a circular string with Z coordinates

Z is stripped from all vertices; M is set to 0:

SELECT ST_AsEWKT(ST_Force3DM(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
                        st_asewkt
------------------------------------------------
 CIRCULARSTRINGM(1 1 0,2 3 0,4 5 0,6 7 0,5 6 0)
(1 row)

Convert a polygon with Z coordinates

Z is stripped from all rings; M is set to 0:

SELECT ST_AsEWKT(ST_Force3DM('POLYGON((0 0 1,0 5 1,5 0 1,0 0 1),(1 1 1,3 1 1,1 3 1,1 1 1))'));
                         st_asewkt
---------------------------------------------------------------
 POLYGONM((0 0 0,0 5 0,5 0 0,0 0 0),(1 1 0,3 1 0,1 3 0,1 1 0))
(1 row)

See also