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-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
Check out my book
Interested in Ruby on Rails default testing stack? Take Minitest and fixtures for a spin with my latest book.
Get Test Driving Rails while it's in prerelease.