terpak
terpak

Reputation: 1151

PostgreSQL: How to resolve "Could not generate outside point" error in ST_Intersects

I've encountered a bug in my radial geospatial search where if a user defines an circle whose radius extends over either pole, I encounter the PostGIS error: "BOOM! Could not generate outside point" thrown by the call to ST_Intersects. I know why this is happening, but is there a way for me to trim the buffered geography/geometry I am querying with so that it does not cause ST_Intersects to encounter any outside points?

My issue can be replicated with the following query:

SELECT ST_intersects(
    ST_BUFFER(
        ST_geomFromGeoJSON('{"type":"Point","coordinates":[-110.390625,42.293564192170095]}')::geography,
        17712927.122199997
    ),
    ST_geomFromGeoJSON('{"type":"Point","coordinates":[-28.828124999999996,84.7060489350415]}')::geography
);

Upvotes: 1

Views: 344

Answers (1)

terpak
terpak

Reputation: 1151

After looking over the documentation again, I noticed that they advise not to use ST_Buffer for radial searching. Instead, using ST_DWithin(geography, geography, meters) will avoid this issue.

The following query will satisfy my question:

SELECT ST_DWithin(
    ST_geomFromGeoJSON('{"type":"Point","coordinates":[-110.390625,42.293564192170095]}')::geography,
    ST_geomFromGeoJSON('{"type":"Point","coordinates":[-28.828124999999996,84.7060489350415]}')::geography,
    17712927.122199997
);

Upvotes: 1

Related Questions