13

How do I get rid of the Z dimension in PostGIS?

Specifically, I have some MultiPolygonZs that I want to copy into another table as MultiPolygons. I don't care about the Z values - it's okay to just throw them away.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Xavier Holt
  • 835
  • 1
  • 8
  • 18

1 Answers1

20

You should be able to do this with ST_Force2D

This is the example from the manual:

SELECT  ST_AsEWKT(ST_Force2D('POLYGON((0 0 2,0 5 2,5 0 2,0 0 2),(1 1 2,3 1 2,1 3 2,1 1 2))'));

                  st_asewkt
----------------------------------------------
 POLYGON((0 0,0 5,5 0,0 0),(1 1,3 1,1 3,1 1))

It might be possible to use a CAST operator as well (depending on some implicit, not well documented rules), but I'd go with the function on this.

BradHards
  • 12,881
  • 2
  • 37
  • 70