繁体   English   中英

PostGIS ActiveRecord适配器不起作用

[英]PostGIS ActiveRecord Adapter not works

我遵循了设置链接,希望将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 |
+----+--------+------------+------------+-------+------+------+-----+-----+
|    |        |            |            |       |      |      |     |     |
+----+--------+------------+------------+-------+------+------+-----+-----+

database.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

您提供的链接显示了一个非常相似的示例,该示例表明您执行操作。

也就是说,提供无效的WKT

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

无法解析,并且将值静默设置为nil。 (有效的WKT看起来像POINT(-122 47) )。

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

factory.point(-122, 47)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM