2010-08-05 51 views
5

我有一張地理編碼的經緯度表。我想讓我的數據庫查詢返回一個已過濾的列表,按固定點的距離排序。如何使用共享數據庫在Heroku上進行GIS查詢?

有,我已經學習了幾個選項:

  • Postgresql's earthdistance contrib可能是最接近我的需要;然而,我發現沒有跡象表明這是安裝在heroku的數據庫服務器上。
  • PostGIS是最常用的GIS解決方案,但是heroku沒有安裝它,而且heroku的支持證實他們在不久的將來不打算這樣做。

我需要一個可以與Rails3一起使用的解決方案。

如果沒有更好的選擇,我將不得不實現我自己的半束縛函數,這肯定似乎重新發明了方向盤。有更好的選擇嗎?

回答

3

Geokit將在數據庫中處理使用haversine的所有距離計算。它也適用於heroku和postgres。強烈推薦。

Geokit Gem Rails Geokit Integration

所有代碼從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) 
+0

我忘了提及這是Rails3,因此GeoKit不是一個選項,因爲與ActiveModel不兼容。 – 2010-08-05 18:59:22

0

POSTGIS目前處於beta版(2012年3月) https://addons.heroku.com/spacialdb

+0

儘管名字狡猾,但這不是Heroku的Postgres數據庫,而只是另一個第三方服務。 – 2012-03-14 09:39:45

+0

https://devcenter.heroku.com/articles/is-postgis-available – 2012-09-29 14:24:27

0

現在的Heroku(2月2013年)對PostGIS的測試水平的支持。全部細節在其網站上提供(需要登錄):https://devcenter.heroku.com/articles/heroku-postgres-extensions-postgis-full-text-search#postgis

的PostGIS:

增加了對地理對象到PostgreSQL對象關係型數據庫的支持。實際上,PostGIS「在空間上啓用」PostgreSQL服務器,允許它用作地理信息系統(GIS)的後端空間數據庫。

Heroku上的PostGIS v1.5支持Postgres處於測試階段,可能會更改未來。

相關問題