PostGISGeometry Editors

ST_Force3DM

What is ST_Force3DM?

ST_Force3DM produces an XYM geometry. Any existing Z values are discarded, and missing M ordinates default to zero (or an optional user value).

SQL
1ST_Force3DM(geometry geom)geometry
2ST_Force3DM(geometry geom, float Mvalue)geometry

M is an OGC-standard "measure" ordinate often used for linear referencing — the distance along a road centreline, chainage along a pipeline, or percentage progress along a route.

When would you use ST_Force3DM?

Use ST_Force3DM to introduce an M dimension on 2D linear features before applying linear-referencing functions such as ST_LocateAlong or ST_AddMeasure. It is also the right call when migrating a schema to geometry(LineStringM, 3857) and needing to initialize existing 2D rows.

In transit and utility analytics, M values derived from ST_LineLocatePoint are often written back via ST_Force3DM combined with vertex-level updates.

FAQs

Does ST_Force3DM preserve existing Z values?

No. Z is dropped. Use ST_Force4D to keep both Z and M.

What default M is used?

Zero, unless the optional Mvalue argument is supplied (PostGIS 3.1+).

How do I populate real M values along a line?

Use ST_AddMeasure(geom, start_m, end_m) to interpolate M linearly along a LineString based on segment length. ST_Force3DM merely promotes the dimension; ST_AddMeasure assigns meaningful values.

Can I round-trip through WKT with M values preserved?

Yes, but use ST_AsEWKT — the OGC ST_AsText strips the M tag in older PostGIS releases. EWKT writes POINT M (x y m) explicitly.