Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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 <code>within</code> in MySQL documentation.</p> <blockquote> <p>Note</p> <p>Currently, MySQL does not implement these functions according to the specification. Those that are implemented return the same result as the corresponding MBR-based functions. This includes functions in the following list other than Distance() and Related(). </p> <p>These functions may be implemented in future releases with full support for spatial analysis, not just MBR-based support.</p> </blockquote> <p><a href="http://dev.mysql.com/doc/refman/5.4/en/functions-that-test-spatial-relationships-between-geometries.html" rel="nofollow noreferrer">From here</a></p> <p>I used a <a href="http://alienryderflex.com/polygon/" rel="nofollow noreferrer">point-in-poly ray-tracing</a> algorithm, which can be quite accurate outside of polar regions if the lines aren't long. Otherwise you'll need to solve spherical triangles.</p> <p>The simple implementation is like this:</p> <pre><code>create table point (x int, y int...) /* int values (int(lat * 10^6)) for better performance */ create table poly (x1 int, y1 int, x2 int, y2 int...) /* temporary table for 1 poly only */ </code></pre> <p>query that selects points inside the poly:</p> <pre><code>select point_id from point, poly where ((y&lt;y2 and y&gt;=y1) or (y&lt;y1 and y&gt;=y2)) and ((x&lt;x2 and x&gt;=x1) or (x&lt;x1 and x&gt;=x2)) group by point_id having sum(x1*(y2-y1)*sign(y2-y1) &lt; x*(y2-y1)*sign(y2-y1) - (y-y1)*(x2-x1)) % 2 </code></pre> <p>Counts 20,000 points vs a poly of 40 lines in 0.06 seconds on Pentium with 2.5Ghz. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload