[postgis-users] Invoking GIST index on 2 disjoints within a query
Kevin Neufeld
kneufeld at refractions.net
Thu Apr 3 14:35:47 PDT 2008
Hi Dylan,
You could try something like this:
SELECT <some stuff>
FROM a
LEFT JOIN b ON (ST_Intersects(a.the_geom, b.the_geom))
LEFT JOIN c ON (ST_Intersects(a.the_geom, c.the_geom))
WHERE b.the_geom IS NULL
AND c.the_geom IS NULL;
-- Kevin
Dylan Lorimer wrote:
> Hi,
>
> So I have probably a simple question but I don't use PostGIS enough to
> know the right way to go about this. Hoping someone can help.
>
> So I've got 3 spatial tables, each containing a bunch of polygon
> geometries. Let's call the tables A, B, C. What I want is to find out
> which polygons in table A are disjoint from all polygons in tables B
> and C. Meaning, which polygons in A have 0 overlap with polygons in B
> or C.
>
> I seem to have no troubles doing this when using only 2 tables, but
> adding the 3rd is messing things up. Oh, and I also want to invoke the
> GIST indexes to speed things up.
>
> Here's the (slightly generalized) query I think I should be using:
>
> SELECT <some stuff> FROM A, B, C WHERE disjoint(A.the_geom,
> B.the_geom) AND disjoint(A.the_geom, C.the_geom) AND <some other
> attribute filters> AND A.the_geom && B.the_geom AND A.the_geom &&
> C.the_geom;
>
> I've not seen this query complete successfully as it takes so long,
> but I think something is wrong with it as running it against only A
> and B is really quick and there aren't too many geometries in the
> tables.
>
> Thoughts?
>
> Cheers,
> dylan
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
More information about the postgis-users
mailing list