[postgis-users] Spatial query Help: points not in set of polygons

Stephen Woodbridge woodbri at swoodbridge.com
Wed Jan 23 19:26:59 PST 2008


Hi all,

I'm drawing a blank on setting up a query for this.

I have a tables points and a table of polygons. I need to find all the 
points that are not in any of the polygons.

select a.*
   from points a, polygons b
  where a.the_geom && b.the_geom
    and distance(a.the_geom, b.the_geom) > 0.0;

The problem with this is that if a point is in polygon A it will have a 
distance to polygon B, so this in no good.

I thought of doing something like:

select * from points
  where distance(the_geom, union((select the_geom from polygons))) > 0.0;

or

select * from points
  where distance(the_geom, collect((select the_geom from polygons))) > 0.0;

So is there a better way to do this. Seems like there should be. If not 
which of these would you suggest.

Thanks,
   -Steve



More information about the postgis-users mailing list