0

我想在我的 postgres 数据库中创建一个表,其中一列是 multipolgyon。我怎么做?

我所做的事情因此失败了 undefined method multipolygon for #<ActiveRecord::ConnectionAdapters::PostgreSQLTableDefinition:0x4ac6f70>

使用此迁移:

class CreateBezirkes < ActiveRecord::Migration
  def change
    create_table :bezirkes do |t|
      t.string :NameK
      t.integer :BezNr
      t.string :Bez_Rz
      t.string :Namek_Num
      t.string :Namek_Rz
      t.string :NameG
      t.string :Label
      t.integer :Bez
      t.integer :District_Code
      t.integer :StatAustria_Bez_Code
      t.integer :StatAustria_Gem_Code
      t.float :Flaeche
      t.float :Umfang
      t.timestamp :Akt_Timestamp
      t.multipolygon :Koordinaten
      t.integer :main_id
    end
    execute <<-SQL
      ALTER TABLE bezirkes
          ADD CONSTRAINT fk_bezirkes_mains
          FOREIGN KEY (main_id)
          REFERENCES mains(id)
    SQL
  end
end
4

3 回答 3

2

你可以使用postgis gem。它基于Rgeo,它提供了一些不错的空间方法。

否则就这样做:

 t.column :koordinaten, :multipolygon

注意:根据 Rails 约定,您的列名不应以大写字母开头。

于 2012-11-10T17:13:42.110 回答
1

首先,让我们确认您已经安装了activerecord-postgis-adapter gem,并且您的 Postgresql 数据库已正确配置了 postgis(根据本教程)。我想强调一下,postgis 安装是针对每个模式的,而不是全局的,因此将它安装在模式 A 中并不意味着它将为同一台机器上的任何其他模式安装。

接下来,看起来某些版本的 postgit 适配器没有创建多多边形列的方法(至少我的没有),所以您有 2 个选项:使用 geomerty/geography 列(您将有相应的方法,但会丢失数据检查 PostgreSQL 端)或使用通用 t.column 方法创建列,例如:

t.column :Koordinaten, :multipolygon

希望这可以帮助。

于 2012-11-10T17:13:25.647 回答
0

确保你有你的adapter设置postgisconfig/database.yml

于 2015-01-13T04:16:12.710 回答