Functions / PostGIS / ST_Force4D
PostGISGeometry Editors

ST_Force4D

What is ST_Force4D?

ST_Force4D returns an XYZM geometry. Any missing Z or M ordinates are filled with zero or with user-supplied values.

SQL
1ST_Force4D(geometry geom)geometry
2ST_Force4D(geometry geom, float Zvalue, float Mvalue)geometry

The function preserves SRID and geometry type. It is the most flexible dimensional promotion available — both Z and M ordinates are present on the output.

When would you use ST_Force4D?

Use ST_Force4D for full OGC-compatible 4D output — for instance when building geometry(PointZM, 4326) columns used to store altitude alongside time or chainage measures. It is the canonical promotion for aviation, marine, and asset-management datasets that need both elevation and a measure.

In pipeline integrity analyses, XYZM preserves both real-world elevation and pipeline chainage on the same vertex, making downstream ST_LocateAlong queries correctly reflect physical position.

FAQs

What defaults are used for Z and M?

Zero for both, unless the three-argument form is used (PostGIS 3.1+).

Does it change geometry type?

No. A LineString stays a LineString — only dimensionality changes.

How do I confirm the result is XYZM?

Check ST_NDims(geom) — it should return 4. Alternatively ST_AsEWKT(geom) will include both Z and M tags.

Can ST_Force4D be used to pad inputs before union or intersection?

Yes. Matching dimensionality before set-theoretic operations avoids implicit coercion and ensures predictable Z/M propagation from input to output.