On 23 January 2012 17:22, Big G <[email protected]> wrote: > I'm using MySQL and the polygons are encoded using > google.maps.geometry.encoding.encodePath > > I'm just wondering if there is a better way of finding which polygons > contain the point rather than using foreach loop on all the polygons as > eventually there could be up to 20,000 polygons in the DB. > > any ideas/help would be much appreciated
I have that many, and I don't have spatial extensions in MySQL. I have a table containing all the boundary points of each polygon, and another table containing the bounds of each polygon (a rectangle). I use this denormalised data to determine a subset of possible polygons for the point, and then test each polygon in that subset to find the one(s) containing the point. I don't use encoded polygons server-side, although I do encode the polygon in the server and send that compressed data to the client to display the polygon. It is fast: try it at http://www.acny.org.uk/parishfinder.php . Although the map is a Version 2 map, all the expensive processing is server-side so that doesn't matter. Just click anywhere in England; using Firebug or something similar will allow you to see how each server interaction works -- it's getparish_new.php which finds the right polygon and encodes the boundary and that's generally around 350ms, occasionally up to 750ms, which isn't bad to find and draw a polygon. I don't know how this would compare to upgrading to a spatially-equipped version of MySQL. I suspect that I gain with the denormalised bounding rectangles and lose slightly on the point-in-polygon analysis; but to encode the boundary it's necessary to have actual coordinates, and I don't have to decode those from spatial data before using them. It's probably fairly similar. -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
