[GIS] How to insert Polyhedralsurface into POSTGIS

3dpostgis

I am unable to store a polyhedralsurface object in my POSTGIS database.

My table has two columns:

name character varying,
geom geometry(POLYHEDRALSURFACE)

I am trying to insert the following geometry:

INSERT INTO public.geometries(
        name, geom)
VALUES ('Cube', ST_GeomFromEWKT('SRID=4326;POLYHEDRALSURFACE( 
((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),  
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), 
((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), 
((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),  
((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)),  
((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) 
)'));

but POSTGIS throws an error:

Geometry has Z dimension but column does not

Best Answer

Found solution :D

You can either set your geometry as GeometryZ at time of creation like this

geom geometry(GeometryZ,4326)

Or use AddGeometryColumn function

SELECT AddGeometryColumn( 'geometries', 'geom', 4326, 'GEOMETRY', 3 );

If anyone has a better solution, please comment. Thanks!

Related Question