ruby - Rails - PostGIS + postgis_adapter Geometry Problem -
i use postgis_adapter alongside postgresql 9.0.4, postgis 1.5.2 , rails 3.1.0 on ruby 1.9.2. described in the postgis_adapter readme, tried perform
model.create(:geom => point.from_x_y(10,20))
postgres responds with
error: parse error - invalid geometry hint: must specify valid ogc wkt geometry type such point, linestring or polygon
the created georuby object looks this:
#<georuby::simplefeatures::point:0x0000010420a620 @srid=4326, @with_z=false, @with_m=false, @y=20, @x=10, @z=0.0, @m=0.0>
hopefully got idea.
executive summary: may work if change to:
model.create(:the_name_of_your_geo_column => point.from_x_y(10,20))
longer version, high probability of ruby howlers: i've barely written word of rb saw 1 many great projects week continue in state of ignorance. working through error messages in irb
(starting 0 in language familiar postgis):
activerecord::base.establish_connection(:adapter=>'postgresql',:database=>'moveable') pt = tablepoint.new(:data => "hello!",:geom => point.from_x_y(1,2)) nameerror: uninitialized constant point
so, require 'postgis_adapter'
, then:
pgerror: error: relation "table_points" not exist
this must awesome naming convention in activerecord i've heard about. create table called table_points
because don't know database model/sync methods are.
moveable=> create table table_points(data text, geo_something geometry);
notice here used geometry
rather geography
because first instinct problem modeling methods in database adapter layer created point types. not @ all, actually. again in irb
,
pt = tablepoint.new(:geom => point.from_x_y(1,2)) activerecord::unknownattributeerror: unknown attribute: geom
no attribute named geom? see happen, again in psql
:
moveable=> alter table table_points add column geom geometry; alter table
then:
irb(main):014:0> pt = tablepoint.new(:geom => point.from_x_y(10,20)) => #<tablepoint data: nil, geo_something: nil, geom: #<georuby::simplefeatures::point:0x1022555f0 @y=20, @with_m=false, @x=10, @m=0.0, @with_z=false, @z=0.0, @srid=-1>> irb(main):015:0> pt.save => true
unbelievable! if did:
pt = tablepoint.new(:data => 'is possible?', :geom => point.from_x_y(38,121), :geo_something => point.from_x_y(37,120)) => #<tablepoint data: "is possible?", geo_something: #<georuby::simplefeatures::point:0x102041098 @y=120, @with_m=false, @x=37, @m=0.0, @with_z=false, @z=0.0, @srid=-1>, geom: #<georuby::simplefeatures::point:0x1020410c0 @y=121, @with_m=false, @x=38, @m=0.0, @with_z=false, @z=0.0, @srid=-1>> irb(main):023:0> pt.save => true
even more unbelievable!
moveable=> select * table_points; data | geo_something | geom --------+-----------------+-------- | | 0101000000000 | 010100000000000 | | 010100000000000 | ...ble? | 00005e400000000 | 010000405e40 (4 rows)
i hesitate post answer because of fundamental lack of familiarity ruby above works (mindbendingly, me), , may able adapt case.
Comments
Post a Comment