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:


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


I am writing a complete guide on web application deployment. Ruby with Puma, Python with Gunicorn, NGINX, PostgreSQL, Redis, networking, processes, systemd, backups, and all your usual suspects. 20 chapters and 2 case studies already available.

More →