9

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.

There must be a simple way, but I've been unable to find any functions that do this... Any tips are greatly appreciated!

12

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.

  • Perfect! I had to use the old name (ST_Force_2D), as I'm on PostGIS < 2.1, but it was all there in the manual. I knew that function had to exist somewhere... Thanks a bunch! – Xavier Holt Nov 21 '13 at 19:26

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.