RGeo snippets

RGeo is a wonderfully efficient and complex Ruby library to help you talk to PostGIS and take advantage of it.

Here's a snippet I made (simple question) to find pois close to a location:

  def self.closest(lon, lat, radius)
    point = GEOFACTORY.point(lon, lat).projection
    where{st_distance(coords, point)<radius}

It's using squeel to make the sql generation much easier (hope Sqeel makes it into rails4). 2.5ms on my slow MBA, not calculating haversine distances, optimized with an index. What else could you hope for? Butter?

Publié le 31 Oct 2012
Écrit par Cyril