How do you execute GIS queries on Heroku using a common database?

I have a table of geocoded locations with latitude and longitude. I would like my database query to return a filtered list of them, ordered by distance from a fixed point.

There are several options that I have studied:

  • The Postgresql earthdistance contrib is probably closest to my needs; however, I did not find any signs that this is installed on the heroku db server.
  • PostGIS is the most often given solution for GIS, but the hero does not have it, and support for the hero confirmed that they do not intend to do this in the near future.

I need a solution that works with Rails3.

If there are no options, I will have to implement my own haversine function, which seems to repeat the ingenuity of the wheel. Any better options?

+5
source share
4 answers

I would (July 2011) recommend using a geocoder

gem 'geocoder'

http://www.rubygeocoder.com/

You can also use geokit-rails3, as I mentioned earlier, but it is not complete and is not supported.

gem 'geokit-rails3'

http://github.com/jlecour/geokit-rails3

+8
source

Geokit will process all distance calculations using haversine in the database. He also works great with the hero and postgres. Highly recommend.

Geokit Gem Rails Geokit Integration

all code taken from github

class Location < ActiveRecord::Base
  acts_as_mappable :default_units => :miles, 
                   :default_formula => :sphere, 
                   :distance_field_name => :distance,
                   :lat_column_name => :lat,
                   :lng_column_name => :lng
end


Store.find :all, :bounds=>[sw_point,ne_point]

bounds=Bounds.from_point_and_radius(home,5)
stores=Store.find :all, :include=>[:reviews,:cities] :bounds=>bounds
stores.sort_by_distance_from(home)
+3
0

Heroku ( 2013) - PostGIS. ( ): https://devcenter.heroku.com/articles/heroku-postgres-extensions-postgis-full-text-search#postgis

PostGIS:

- PostgreSQL. , PostGIS " " PostgreSQL, ()

PostGIS v1.5 Heroku Postgres - .

0
source

All Articles