in Ruby

Fix can’t cast RGeo::Geographic::SphericalPointImpl to point

If you are using Rails with activerecord-postgis-adapter 3.1.4 perhaps you got into a point where you were suddenly getting the following error:

can't cast RGeo::Geographic::SphericalPointImpl to point

If you would try to debug what’s going on you would probably go through the following files:

...gem/ruby/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/quoting.rb
...gem/ruby/gems/activerecord-postgis-adapter-3.1.4/lib/active_record/connection_adapters/postgis/spatial_column.rb 

only to find out that Rails returns a point type column instead of desired geography(Point,4326).

The mistake is then obvious, replace your point type in your migrations or schema.rb file with st_point or geography types:

-t.point    "lonlat",                     :geographic => true
+t.geography "lonlat",      limit: {:srid=>4326, :type=>"point", :geographic=>true}, null: false

Write a Comment

Comment