Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Ruby on Rails plugin enabling Spatial Associations, where the association is defined by a spatial function.

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 tasks
Octocat-spinner-32 test
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb
Octocat-spinner-32 install.rb
Octocat-spinner-32 uninstall.rb

SpatialAssociations provides helper methods for ActiveRecord::Base that enable spatially constrained associations.

A Spatial Association is one where the coupling between models is determined by the result of a geometric function, rather than a relational key-based linking.

This plugin assumes that you are using PostGIS, and that your geometric columns are all named 'geometry'.

Helpers Available

is_enclosed_by :model
	i.e. a city is_enclosed_by a state.
encloses :models
	i.e. a state encloses cities.


Say I have two spatial enabled models, City and State.

Add the helpers to the appropriate models:

	class City < ActiveRecord::Base
		is_enclosed_by :state

	class State < ActiveRecord::Base
		encloses :cities

I can now use these associations as follows:

@someCitysState = @someCityObject.state # => Returns a state object that spatially encloses the receiving city.

@someStatesCities = @someStateObject.cities # => Returns an array of City objects which are spatially enclosed by the receiving state.

Copyright (c) 2008 Bradley Spaulding, released under the MIT license
Something went wrong with that request. Please try again.