Re: Points within polygons
Maybe I have been working too many hours. But I am also seing problems with finding points with in polygons.
Here is a very specific example. I have a point in my database table that looks like:
POINT(-80.785128155473 26.347442530646)
I am executing the following SQL:
SELECT id, ASTEXT(location) FROM waypoints_cluster_10 WHERE
WITHIN( location, GEOMFROMTEXT( 'POLYGON(( -81.19171 27.3090129,-81.19171 26.1525330, -80.09308 26.1525330,-80.09308 27.3090129,-81.19171 27.3090129 ))'))
So am I crazy or should this SQL have returned at least this point. I am 100% sure there are many more that are in that polygon but that is a concreate example.
Now if I try this:
SELECT id, COUNT, ASTEXT(location) FROM waypoints_cluster_10
WHERE
WITHIN( GEOMFROMTEXT( 'POINT(-80.785128155473 26.347442530646)' ), GEOMFROMTEXT( 'POLYGON(( -81.19171 27.3090129,-81.19171 26.1525330, -80.09308 26.1525330,-80.09308 27.3090129,-81.19171 27.3090129 ))'))
That returns all the points in the DB. Doesn't that mean that WITHIN( GEOMFROMTEXT( 'POINT(-80.785128155473 26.347442530646)' ), GEOMFROMTEXT( 'POLYGON(( -81.19171 27.3090129,-81.19171 26.1525330, -80.09308 26.1525330,-80.09308 27.3090129,-81.19171 27.3090129 ))'))
Is correct?
What am I overlooking?
Note: I have also tried with polygon verteces in clockwise order and I get the exact same result.
Note: The polygon is supposed to be a simple box.
I am also executing this with many other polygons and most seem to work. But there a few like the one above that don't seem to want to work and I cannot figure out the problem. Is it my code, is it the DB?
The polygons come from a map application where you can zoom and scroll. And most of the time I get the points with in my region correctly. But sometimes I do not.
Any thoughts ?
Mike did you ever resolve your main issu by simply making the polygon counter clockwise. To me that did not seem to make a difference.