Hi Ruud,

> when I fetch the records, i only want those records which have a distance 
> *equal
to or below the given distance*.

The usual technique in the geospatial world is to first select the points
from the containing rectangle (bounding box, or BBOX), which is a much
simpler calculation that helps discard most of the unwanted points. Then
calculate the distance against the points inside that BBOX. Something like:

SELECT * FROM table
WHERE
  LAT >= :min_lat
  AND LAT <= :max_lat
  AND LON >= :min_lon
  AND LON <= :max_lon
HAVING (distance_calculation) <= :radius

The HAVING condition is only checked against the rows satisfying the WHERE
conditions, so it's a good way to refine your selection with an expensive
calculation.

Obviously you'll want to index LAT and LON fields as well.

Details on formulae for bbox and distance calculations:
http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates


-- 
Oscar Fonts
www.geomati.co <http://geomati.co>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to