Add this line to your application's Gemfile:
gem 'postgres_ext-postgis'
And then execute:
$ bundle
Or install it yourself as:
$ gem install postgres_ext-postgis
Just require 'postgres_ext/postgis'
and use ActiveRecord as you normally would!
postgres\ext extends ActiveRecord's data type handling and query methods
in both Arel and ActiveRecord.
Adding a geomtry column to your table is simple! You can create a plain geometry column, or specify your spatial type and projection:
create_table :districts do |t|
t.geometry :location
t.geometry :district_boundries, spatial_type: :multipolygon, srid: 4326
end
PostGIS geometry types are converted to RGeo objects. You can set your PostGIS types in ActiveRecord using either the Extended Well-Known Binary (WKB) or Extended Well-Known Text (WKT) representation:
user.location = 'SRID=4623;POINT(1 1)'
Using the contains querying interface from postgres_ext that arrays utilize, we can query if geometry column contains the specified object
District.where.contains(district_boundries: user.location)
We are very thankful for the many contributors
This gem follows Semantic Versioning
Please do! We are always looking to improve this gem. Please see our Contribution Guidelines on how to properly submit issues and pull requests.
DockYard, Inc. © 2014