I'm trying to create a basic app using the activerecord-postgis-adapter gem and am following the instructions in the readme.
According to the readme, a point is supposed to use the spherical factory, but I get a CAPIPointImpl type instead of a SphericalPointImpl for a point. This means that a distance calculation doesn't work.
Here is what I am trying:
record = MySpatialTable.create
record.lonlat = 'POINT(-122 47)'
record.lonlat
returns #<RGeo::Geos::CAPIPointImpl:0x3ff57d7645c8 "POINT (-122.0 47.0)">
I am using ruby 2.3.1, rails 5, postgres 9.6 and postgis 2.3
This is my schema:
create_table "my_spatial_tables", force: :cascade do |t|
t.geography "lonlat", limit: {:srid=>4326, :type=>"point", :geographic=>true}
t.index ["lonlat"], name: "index_my_spatial_tables_on_lonlat", using: :gist
end
My initialization:
RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
config.default = RGeo::Geos.factory_generator
config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
end
And my database config:
default: &default
adapter: postgis
encoding: unicode
schema_search_path: public, postgis
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %