I am using Postgres 9.5.2 and PostGIS 2.2.2.

According to the documentation ST_PointOnSurface should not drop Z. This is what happens. If I run

SELECT ST_AsText(cell) AS pt FROM cells LIMIT 1

I get

POLYGON Z ((157.215247156568 3779.5275740661 76.0620819960913,157.215247156568 3937.00787401575 76.0620819960913,3.4336355447806e-07 3937.00787401575 66.9291338782187,3.43363565136201e-07 3779.5275740661 66.9291338782187,157.215247156568 3779.5275740661 76.0620819960913))

as expected (Z conserved). However, if I run

SELECT ST_AsText(ST_PointOnSurface(cell)) AS pt FROM cells LIMIT 1


SELECT ST_AsText(ST_Centroid(cell)) AS pt FROM cells LIMIT 1

I get

POINT(78.6076237499659 3858.26772404092)

and the 3rd coordinate is gone.

Am I doing something wrong?


The ST_PointOnSurface documentation doesn't specifically mention POLYGON Z, so assume it doesn't work for now.

The ST_Centroid documentation doesn't mention Z at all.

However, you can incorporate ST_3DClosestPoint into your statement to get the closest 3D point between the cell and its center (or point on surface).

SELECT ST_AsText( ST_3DClosestPoint(cell,ST_PointOnSurface(cell))) AS pt
FROM cells LIMIT 1

SELECT ST_AsText( ST_3DClosestPoint(cell,ST_Centroid(cell))) AS pt
FROM cells LIMIT 1

POINT Z (78.6076237499658 3858.26772404092 71.495607937155)

Here is a list of all 3D functions

  • This kind of work, but the point can get on the edge of surface. This is a flat surface with the Z forced on the point. See the difference between ST_3DClosestPoint and ST_PointOnSurface. – Rojj Jul 6 '16 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.