SELECT `NAME` FROM world_boundaries
WHERE Within(GeomFromText('POINT(8.5929098 50.0286713)'), ogc_geom);
Why does this query return 3 countries when it should return one.
It returns:
1. France
2. Germany (correct one)
3. America
Is my country boundaries data flawed or is there some trick with these geometry functions?
MySQL can’t check a point in poly yet. It will check if your point is within the ([minX, maxX], [minY, maxY]). Also, I don’t see
withinin MySQL documentation.From here
I used a point-in-poly ray-tracing algorithm, which can be quite accurate outside of polar regions if the lines aren’t long. Otherwise you’ll need to solve spherical triangles.
The simple implementation is like this:
query that selects points inside the poly:
Counts 20,000 points vs a poly of 40 lines in 0.06 seconds on Pentium with 2.5Ghz. 🙂