Functions / PostGIS / ST_Force3D
PostGISGeometry Editors

ST_Force3D

What is ST_Force3D?

ST_Force3D promotes a geometry to three-dimensional XYZ. Missing Z values default to 0, and an optional second argument overrides the default fill value. It is an alias for ST_Force3DZ.

SQL
1ST_Force3D(geometry geom)geometry
2ST_Force3D(geometry geom, float Zvalue)geometry

Any M ordinate present on the input is dropped. The function is idempotent on XYZ geometry and preserves SRID and type.

When would you use ST_Force3D?

Use ST_Force3D before writing to a geometry(PointZ, 4326) column or to a format that expects consistent Z — CityGML, 3D tiles, or an elevation-augmented shapefile. It is also useful when mixing 2D and 3D inputs in a union, where matching dimensionality prevents implicit coercion errors.

In AEC and BIM workflows, use the two-argument form to assign a floor elevation (e.g. ST_Force3D(footprint, 12.5)) when promoting 2D building footprints to 3D massing blocks.

FAQs

What Z value is assigned to existing 2D vertices?

Zero by default, or the Zvalue supplied in the two-argument form (added in PostGIS 3.1).

Does it preserve M ordinates?

No. ST_Force3D produces XYZ geometry and drops M. Use ST_Force4D if you need XYZM.

What is the difference between ST_Force3D and ST_Force3DZ?

They are aliases. ST_Force3D was added as a shorter name. Both produce XYZ. If you need XYM instead, use ST_Force3DM.

How can I lift a 2D polygon to a known elevation?

Use the two-argument form: ST_Force3D(polygon, 42.0) sets Z = 42 on every vertex. For varying elevations, use ST_SetZ per vertex via a ST_DumpPoints / reconstruction loop.