/activerecord-postgis-adapter

ActiveRecord connection adapter for PostGIS, based on postgresql and rgeo

Primary LanguageRubyOtherNOASSERTION

PostGIS ActiveRecord Adapter

The activerecord-postgis-adapter is a plugin that provides access to features of the PostGIS geospatial database from ActiveRecord. Technically, it extends the standard postgresql adapter to provide support for the spatial data types and features added by the PostGIS extension. It uses the RGeo library to represent spatial data in Ruby.

Original project: github.com/dazuma/activerecord-postgis-adapter/

About the PostGIS Adapter

This is a brief summary covering how to use activerecord-postgis-adapter. For full documentation, see Documentation.rdoc.

Features

The adapter provides three basic capabilities.

First, it provides *spatial migrations*. It extends the ActiveRecord migration syntax to support creating spatially-typed columns and spatial indexes. You can control the various PostGIS-provided attributes such as srid, dimension, and geographic vs geometric math.

Second, it recognizes spatial types and casts them properly to RGeo geometry objects. The adapter can configure these objects automatically based on the srid and dimension in the database table, or you can tell it to convert the data to a different form. You can also set attribute data using WKT format.

Third, it lets you include simple spatial data in queries. WKT format data and RGeo objects can be embedded in where clauses. If you include the Squeel gem, the adapter also supports advanced queries utilizing the standard SQL spatial function set.

Requirements

The adapter has the following requirements.

  • Ruby 2.0.0 or later.

  • PostgreSQL 9.0 or later.

  • PostGIS 2.0, or later.

  • ActiveRecord 4.0.2 or later.

  • rgeo and rgeo-activerecord.

Installation and Configuration

To install this adapter in a Rails application, add it to your Gemfile:

gem 'activerecord-postgis-adapter'

and run bundle install to update your bundle.

Alternately, if you are not using bundler, install it separately as a gem:

gem install activerecord-postgis-adapter

Please note that this adapter uses the rgeo gem, which may have additional dependencies. Please see the README documentation for rgeo for more information.

Once you have installed the adapter, you’ll need to edit your config/database.yml to call for it. At minimum, this means changing the adapter name from “postgresql” to “postgis”. It may also require other settings to ensure that other functions (such as rake test) continue to work as expected. We recommend reading the Configuration section in the Documentation.rdoc file carefully before starting to use this adapter.

Development and Support

Original project info:

Documentation is available at dazuma.github.com/activerecord-postgis-adapter/rdoc

Source code is hosted on Github at github.com/dazuma/activerecord-postgis-adapter

Contributions are welcome. Fork the project on Github.

Report bugs on Github issues at github.org/dazuma/activerecord-postgis-adapter/issues

Support available on the rgeo-users google group at groups.google.com/group/rgeo-users

Contact the author at dazuma at gmail dot com.

Acknowledgments

The PostGIS Adapter and its supporting libraries (including RGeo) are written by Daniel Azuma (www.daniel-azuma.com).

Development is supported by Pirq. (pirq.com).

This adapter implementation owes some debt to the spatial_adapter plugin (github.com/fragility/spatial_adapter). Although we made some different design decisions for this adapter, studying the spatial_adapter source gave us a head start on the implementation.

License

github.com/neighborland/activerecord-postgis-adapter/LICENSE.txt