【发布时间】:2016-03-02 23:14:25
【问题描述】:
我已经开始使用原始 SQL 的以下范围:
class DeliveryZone < ActiveRecord::Base
def self.contains(addressable)
point = addressable.lonlat
where(<<-SQL.squish)
ST_Intersects("delivery_zones"."shape", ST_GeomFromText('#{point}'))
SQL
end
end
其中delivery_zones.shape 是geography(Polygon,4326),point 是geography(Point,4326),对于 PostgreSQL 类型。
在 Rails 控制台中,它们分别是 #<RGeo::Geos::CAPIPolygonImpl> 和 #<RGeo::Geos::CAPIPointImpl>。
我想写一些类似的东西
where(arel_table[:shape].st_intersects(point))
...但这给了我这个错误:
RuntimeError:不支持:RGeo::Geos::CAPIPointImpl
希望从我的模型中获取原始 SQL 的帮助!另外,我是 RGeo/PostGIS 新手,所以请不要以为我知道自己在做什么。 :D
【问题讨论】:
标签: ruby-on-rails-4 activerecord postgis rgeo