PostGIS and MySql Spatial Extensions in Rails


#1

Hello,

This post is to announce a new release of the Spatial Adapter for Rails,
which is a plugin that adds support for columns of geometric types
(point,
linestring, polygon,etc…) to ActiveRecord. Currently the only
supported
databases are MySql and PostGIS.
With this release, geometric columns should behave like columns of any
other
basic types in all areas: migration, data access, dumping in ruby schema
mode…
For example, here is how you would define a “restaurants” table in a
migration, along with a spatial index on the geometric column:

ActiveRecord::Schema.define do
create_table “restaurants”, :force => true do |t|
t.column “data”, :string
t.column “geom”, :point, :null=>false, :srid => 123
end

add_index “restaurants”, “geom”, :spatial=>true
end

Here is the model to use it:

class Restaurant < ActiveRecord::Base
end

And you would access the geom column in the following way:

rt = Restaurant.find_first
puts rt.geom.x #access the geom column like any other

Documentation and instructions for installation are available at
http://thepochisuperstarmegashow.com/projects/ .

It is distributed under the MIT license.

guilhem