basic factory & point manipulation questions

49 views
Skip to first unread message

Ivar Vasara

unread,
Jan 6, 2017, 7:05:04 PM1/6/17
to RGeo-Users

Hi All,

First off, thank you for providing rgeo and it's affiliated gems - I am grateful for being able to learn GIS stuff while working in a great language.

Here's an example of some code that I'm trying to port from a activerecord-postgis-adapter '~> 2.2.2.` code base:

--- snip ---
  def location_factory
    # This should be unnecessary with the class method `set_rgeo_factory_for_column`
    # and calling `rgeo_location_for_column(:location)`, however when deployed to Heroku
    # this returns a Proc instead of the factory
    RGeo::Geographic.spherical_factory(srid: 4326)
  end

  def latitude
    location.try :y
  end

  def latitude=(latitude)
    longitude = location.try :x || 0
    self.location = location_factory.point(longitude, latitude)
  end

  def longitude
    location.try :x
  end

  def longitude=(longitude)
    latitude = location.try :y || 0
    self.location = location_factory.point(longitude, latitude)
  end

--- snip ---

I have a few questions about this code...

1) Now that I'm updating to a newer version of rgeo-activerecord, I'll be registering the factory I want to use globally in an initializer. Instead of reproducing the 'location_factory' method to get a handle to the desired factory, how do I 'set it and forget it' and just create a Point object safe in the knowledge that the correct factory has already been configured?

2) Are the longitude/latitude method implementations canonical or does is there a better way to independently manipulate lat/long ?

Thanks for your time
Reply all
Reply to author
Forward
0 new messages