(EDIT: Sorry. Forgot to mention. Postgresql 13, PostGIS: 3.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1. Sorry about that).
The following 2 queries, in my opinion, should return "true" in both cases. The point is clearly within the polygon (square). Displaying both certainly indicates so. I am starting to wonder what fondamental thing I am missing here.
To be honest, I have been circling around this issue for years, as I am never able to find something "final" to understand what is happening. In this case, the point is somewhat near the edge of the polygon, but from time to time I had the same issues with points that were well within the polygon.
The only difference between the 2 queries is that one uses geometry the other uses geography. As you can see, we use 0.0 for the distance value. This is like an intersects.
OH, and by the way, using intersects yields the same results. I am very confused about this.
select
ST_Dwithin(
St_GeometryFromText(
'POLYGON((-95.979486 41.676556,-81.432269 41.676556,-81.432269 30.196043,-95.979486 30.196043,-95.979486 41.676556))', 4326),
ST_GeometryFromText('POINT (-87.70551 30.24481)', 4326),
0
)
select
ST_Dwithin(
St_GeographyFromText(
'POLYGON((-95.979486 41.676556,-81.432269 41.676556,-81.432269 30.196043,-95.979486 30.196043,-95.979486 41.676556))'),
St_GeographyFromText('POINT (-87.70551 30.24481)'),
0
)
EDIT. Sorry, not sure of the right etiquette. Following the great responses, I am adding some more context, in case somebody finds it interesting.
I am working on a "world" dataset containing country polygons. Since some of these are huge, I have elected to st_subdivide them.
![st_subdivide usa] https://imgur.com/IQRz8vg
And when zooming we can see EXACTLY what is explained in the answer below:
![zoom st_subdivide usa] https://imgur.com/fgmpBx0
So wow, perfect explanation, thank you very much.
I know that I should not use geography, well, "should not". However, I also need to work a lot with distances and expansion, and geom(4326) is quite annoying with units I find.
