【问题标题】:PostGIS ActiveRecord Adapter not worksPostGIS ActiveRecord 适配器不起作用
【发布时间】:2014-04-26 17:19:49
【问题描述】:

我按照link 的设置想将PostGIS ActiveRecord Adapter 集成到我的项目中,我的Rails 项目已经通过postgis-and-rails-a-simple-approach 安装了postgis

我按照这些步骤到Working With Spatial Data

然后启动 Rails 控制台

c = Spatial.new()

c.lonlat = 'POINT(-122,48)'

2.1.0 :004 > c
+----+--------+------------+------------+-------+------+------+-----+-----+
| id | lonlat | created_at | updated_at | shap1 | shp2 | path | lon | lat |
+----+--------+------------+------------+-------+------+------+-----+-----+
|    |        |            |            |       |      |      |     |     |
+----+--------+------------+------------+-------+------+------+-----+-----+

数据库.yml

 16 #
 17 development:
 18   adapter: postgis
 19   encoding: unicode
 20   database: goodshot_development
 21   schema_search_path: public,postgis

迁移文件

class CreateSpatials < ActiveRecord::Migration
  def change
    create_table :spatials do |t|
      t.column :shap1, :geometry
      t.geometry :shp2
      t.line_string :path, :srid => 3785
      t.point :lonlat, :geographic => true
      t.point :lon
      t.point :lat
      t.index :lonlat, :spatial => true
      t.timestamps
    end
  end
end

【问题讨论】:

    标签: ruby-on-rails postgresql activerecord postgis


    【解决方案1】:

    您提供的link 显示了一个非常相似的示例,说明该做什么,而这正是您所做的。

    即提供无效的WKT

    record.lonlat = 'POINT(-122, 47)'
    

    解析失败,并默默地将值设置为 nil。 (有效的 WKT 类似于 POINT(-122 47))。

    该链接描述了几种构造几何的替代方法,例如:

    factory.point(-122, 47)
    

    【讨论】:

    • 我更新了 activerecord-postgis-adapter README 以修复不正确的文档(删除了逗号)。
    猜你喜欢
    • 1970-01-01
    • 2011-04-26
    • 2016-09-15
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多