[postgis-users] PostGIS on Rails (IvyGIS) implementation...

Robert Thau rst at alum.mit.edu
Thu Apr 20 12:19:04 PDT 2006

Sean Gillies wrote:

 > Nice work! How did you get PostGIS geometries to work with Active  
 > Record? Or do you work around?

Well, here's most of the "Park" model from the "Canada" sample app:

  class Park < ActiveRecord::Base

    include IvyGIS::GISRecord
    geometry_column :the_geom, IvyGIS::MultiPolygon

    def self.find_by_list_params(params)
      self.find :all,
        :select => "id, name_e, " +
           "simplify(the_geom, #{params[:scale].to_f/2}) as the_geom",
        :conditions => (located_by params, 'the_geom')


What "geometry_column" does is arrange for WKB parsing and rendering
when translating the column of that name to the corresponding attribute.
You can also invoke the parser directly, a la 


if you have a computed column with a name you haven't predeclared.

Note the somewhat awkward business of "simplify"ing the geometry
column for display --- I didn't want to do that in Ruby.  (The SVG/VML
rendering is slow enough!  If it was only SVG, I'd be very likely
using PostGIS's own SVG rendering --- it's not hard to write in Ruby,
but for large collections of geometries, it's slower than you'd like).

Hope this helps --- and sorry for breaking threading; I subscribed
to the list in digest mode.


More information about the postgis-users mailing list