I have a line made up of two points. I am creating a buffer around that line of 18520m (10 Nautical Miles) using ST_Buffer.
I have a third point and I want to test if that is within the buffer or not.
When I test the distance from the original line to the third point (using ST_Distance), I get a distance of 18630m. Clearly, outside of the buffer of 18520m.
When I test the distance from the buffer to the third point (using ST_Distance), I get a distance of 0m - implying that the point is inside the buffer of 18520.
When I test whether the third point is within the buffer (using ST_Intersects), I get a value of 'true' - implying that the point is inside the buffer of 18520.
However, the distance from the line to the third point being 18630m AND the third point being within the buffer of 18520m cannot both be true. So where am I going wrong?
Have a look at the following script to replicate my results:
WITH myconstants (bufferGeography, myLat, myLon) as (
values (
ST_Buffer(
ST_GeogFromText('SRID=4326;LINESTRING(-4.275000095367432 60.314998626708984, -32.579489389701344 59.51950893947703)'
)
, 18520)
,59.6793
,-32.6768
)
)
SELECT
ST_Distance(ST_GeogFromText('SRID=4326;LINESTRING(-4.275000095367432 60.314998626708984, -32.579489389701344 59.51950893947703)'),ST_Point(myLon, myLat)::geography) AS DistanceFromLine
,ST_Distance(bufferGeography,ST_Point(myLon, myLat)::geography) AS DistanceFromBuffer
,ST_Intersects(bufferGeography, ST_Point(myLon, myLat)::geography) AS WithinBuffer
FROM myconstants;
This gives the following output:
"distancefromline" "distancefrombuffer" "withinbuffer"
18630.52586952 0 true
What is wrong?