dazuma/activerecord-postgis-adapter — Issue #15: Saving a Polygon with WFT format
Author: nodrog
Created: 2012-01-24 22:19:19+00:00
State: open

hi, thanks for this great gem and all the other associated gems, great work.

I have a problem though and its probably because i am being stupid, but i have tried to read as much as i can and i just cannot figure it out..

i am trying to save a polygon to the db by supplying a polygon in WFT.

a.geometry = "POLYGON((1.7162916854424444 103.45203161621089, 1.4678221588572677 103.42868566894526, 1.250903373422990
=> "POLYGON((1.7162916854424444 103.45203161621089, 1.4678221588572677 103.42868566894526, 1.2509033734229906 103.75003576660151, 1.6682474647616954 104.06726599121089, 1.7162916854424444 103.45203161621089))"
ruby-1.9.2-p290 :005 > a.geometry
=> nil
ruby-1.9.2-p290 :006 > a.save

as you can see the geometry column does not get set but know error. if i try a simple set of integers all seems to work:

ruby-1.9.2-p290 :046 > a.geometry = "POLYGON((35 10, 10 20, 15 40, 45 45, 35 10))"
=> "POLYGON((35 10, 10 20, 15 40, 45 45, 35 10))"
ruby-1.9.2-p290 :047 > a.save
(0.2ms) BEGIN
(0.6ms) UPDATE "areas" SET "geometry" = '0020000003000010e600000001000000054041800000000000402400000000000040240000000000004034000000000000402e00000000000040440000000000004046800000000000404680000000000040418000000000004024000000000000', "updated_at" = '2012-01-24 21:49:35.021586' WHERE "areas"."id" = 1
(1.1ms) COMMIT
=> true

my migration looks like this:

class CreateAreas < ActiveRecord::Migration

def self.up
create_table :areas do |t|
t.string :name
t.references :account
t.string :color
t.string :description
t.polygon :geometry, :geographic => true
t.timestamps
end

add_index :areas, :name
add_index :areas, :geometry, :spatial => true
end

def self.down
drop_table :areas
end

end

and by model:

class Area < ActiveRecord::Base
set_rgeo_factory_for_column(:geometry, RGeo::Geographic.spherical_factory)
belongs_to :account
end

Any help would be much appreciated, many thanks