Reputation: 375
I have a geographic table that contains polygons that represent US coastal waters. I want to find the geopoints that fall just outside these regions, say that are just outside by 2 miles. I'm testing the DWithin function, but that is displaying points within my polygons.
with base_tbl1 as (SELECT ais.*, ST_GEOGPOINT(lon, lat) as geo_point
FROM `AIS_positions` as ais)
SELECT *
FROM (
SELECT a.*, ST_DWITHIN(US.geometry, a.geo_point, 0) as test
FROM base_tbl1 as a,
`US_EEZ` as US
)
where test = True
Upvotes: 0
Views: 496
Reputation: 7724
ST_DWITHIN
means "distance between geographies is within X meters", so that includes both regions outside and within the polygon itself.
There are several approaches you can use, two I can think of:
WHERE ST_DWITHIN(US.geometry, a.geo_point, 2 * 1609) AND
NOT ST_INTERSECTS(US.geometry, a.geo_point)
ST_DIFFERENCE(ST_BUFFER(geometry, 2 * 1609), geometry)
You can then test if a point falls into this buffer zone with ST_INTERSECTS
check.
Upvotes: 3