postgis – How to Invert the ST_DWithin() Function in PostGIS

postgispostgresqlspatial-joinst-dwithin

Is it possible to perform a query like this:

SELECT * FROM foo 
    JOIN bar
        ON ST_Dwithin(foo.geom, bar.geom, > 10);
        -- the > 10 means that I want to select everything that is further away then 10

I want to revert the ST_DWithin() function. I want to get all the geometries, that are farther away than 10 from foo.geom.

Is that possible? If not with the ST_DWithin() function, is there another way?

Best Answer

Use a correlated [NOT] EXISTS filter:

SELECT *
FROM   foo
WHERE  NOT EXISTS (
  SELECT 1
  FROM   bar
  WHERE  ST_DWithin(bar.geom, foo.geom, <dist>)
);
Related Question