Notes to self

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-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

Work with me

I have some availability for contract work. I can be your fractional CTO, a Ruby on Rails engineer, or consultant. Write me at strzibny@strzibny.name.

RSS