PostGIS and MySql Spatial Extensions in Rails


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
linestring, polygon,etc…) to ActiveRecord. Currently the only
databases are MySql and PostGIS.
With this release, geometric columns should behave like columns of any
basic types in all areas: migration, data access, dumping in ruby schema
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

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

Here is the model to use it:

class Restaurant < ActiveRecord::Base

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 .

It is distributed under the MIT license.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs