I have some experience with PostgreSQL, but not with PostGIS, and for the life of me I can't make my bounding box take the Z axis into account.

I have a points table with XYZ columns. I add another one:

ALTER TABLE foo ADD COLUMN the_geom Geometry(PointZ,4326);

Then I populate the_geom column with my XYZ coordinates:

SET the_geom =  ST_SetSRID(ST_MakePoint (x,y,z), 4326)

I confirmed my 3 dimensions with:

SELECT f_geometry_column As col_name, 
    coord_dimension As ndims 
FROM geometry_columns

And finally, I can query my data against the bounding box with:

FROM foo
WHERE  the_geom &&  ST_3DMakeBox( ST_MakePoint(0,0,0), ST_MakePoint(6600, 15500, 0)  )

Which should return no rows since in the bounding box the Z axis is 0 and all my Z data is greater than zero, but the query only filters the X and Y axes, not caring about the Z axis.

What am I'm doing wrong, please?

  • As stupid as it looks, just found out about the &&& operator. I've installed the latest postgis (2.1.7) but still no luck... – José Luis Jun 9 '15 at 14:26
  • 1
    It seems like something like this: SELECT * from foo where the_geom &&& 'LINESTRING(0 0 0 ,6600 15500 3107.5)'; really works. – José Luis Jun 9 '15 at 16:04

Try creating an n-d index on your geometry column:

CREATE INDEX foo_gix_nd ON foo USING GIST (the_geom gist_geometry_ops_nd);

Some more information is available here:


  • As a matter of fact I did, found the same link you mentioned. Thanks! Just wished there was an easy way to visually confirm the results...QGIS seems to be 2D only and GRASS GIS is super complicated... – José Luis Jun 17 '15 at 12:07
  • Why do you need to visualize this? your points ahve a z-coord, it is either within the z-bounds in the bbox, or it is not, should be easy enough to tell. – chodgson Jun 17 '15 at 22:25

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.