ruby on rails 4 - Deserialize RGeo column as SphericalPointImpl -


there table rgeo column in rails 4.2.4 , activerecord-postgis-adapter 3.1.2

class createaddresses < activerecord::migration   def change     create_table :addresses |t|       t.st_point :coordinates,   geographic: true, srid: 4326     end      add_index :addresses, :coordinates, using: :gist   end end 

and method groups objects location

def self.group_by_coords     includes(:address).     joins(:address).     group('addresses.coordinates::geometry').     pluck(       'array_agg(realties.id) ids, addresses.coordinates::geometry'     )   end 

with corresponding test:

describe 'group_by_coords'   'correctly group realties'     # create samples     expect(realty.group_by_coords).to eq(       [[[r1.id, r2.id], r1.address.coordinates], [[r3.id], r3.address.coordinates]]     )   end end 

the problem pluck returns rgeo::geos::capipointimpl instead of rgeo::geographic::sphericalpointimpl

expected: [[[1670, 1671], #<rgeo::geographic::sphericalpointimpl:0x3fd37e9b8a20 "point (106.0 10.0)">], [[1672], #<rgeo::geographic::sphericalpointimpl:0x3fd37ab2dddc "point (106.5 10.5)">]] got: [[[1671, 1670], #<rgeo::geos::capipointimpl:0x3fd37a335a44 "point (106.0 10.0)">], [[1672], #<rgeo::geos::capipointimpl:0x3fd37a33560c "point (106.5 10.5)">]] 

i believe in order fix there must specified correct factory. tried specify this

rgeo::activerecord::spatialfactorystore.instance.tap |config|   config.default = rgeo::geos.factory_generator   config.register(rgeo::geographic.spherical_factory(srid: 4326), geo_type: "point", sql_type: "geography") end 

but deserializes points rgeo::geos::capipointimpl more generic , incompatible existing codebase.

so question how make points deserialized rgeo::geographic::sphericalpointimpl ?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -