[postgis-users] 3d box intersection queries

Matthias nitro at dr-code.org
Fri Apr 15 21:12:07 PDT 2011


Hello,

My entities are defined as boxes in 3d. Now I want to be able to query all  
entities within a certain (bigger) 3d bounding box. What's the recommended  
way to do this with PostGIS? Usually I'd just use an r-tree for this task,  
but I want to use it within the context of a database.

For a start I downloaded the postgis 2.0 windows experimental binaries and  
performed a query like

SELECT ST_3DIntersects(box1, box2) FROM (SELECT

ST_GeomFromEWKT('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)) )') AS box1,

ST_GeomFromEWKT('POLYHEDRALSURFACE(
((2 0 0, 2 0 1, 2 1 1, 2 1 0, 2 0 0)),
((2 0 0, 2 1 0, 3 1 0, 3 0 0, 2 0 0)),
((2 0 0, 3 0 0, 3 0 1, 2 0 1, 2 0 0)),
((3 1 0, 3 1 1, 3 0 1, 3 0 0, 3 1 0)),
((2 1 0, 2 1 1, 3 1 1, 3 1 0, 2 1 0)),
((2 0 1, 3 0 1, 3 1 1, 2 1 1, 2 0 1)) )') AS box2

) as foo;

which test if two cubes intersect.

Now the polyhedrastuff looks a bit like overkill for simple 3d boxes. Is  
there a better/faster/memory saving way to do this?

-Matthias



More information about the postgis-users mailing list