Announcing PostgresExt-PostGIS

gis
Dan McClain

Partner & Developer

Dan McClain

Today I released the first version of postgres_ext-postgis, which extends ActiveRecord to support PostGIS data types and some querying. This is definitely a beta release, but ready to the point where people can play around with it.

Migrations

With postgres_ext-postgis, you can easily add geometry columns:

create_table :districts do |t|
  t.geometry :district_boundries
end

If you’d like to include your projection or geometry type, just include them as options to your column:

create_table :districts do |t|
  t.geometry :district_boundries, spatial_type: :multipolygon, srid: 4326
end

Type Casting

Your geometry columns will be typecasted into RGeo objects. You can set your attributes with RGeo objects or EWKT/EWKB strings. EWKT/EWKB strings will be converted to RGeo objects:

user.location = 'SRID=4623;POINT(1 1)'

Querying

For now, the only added querying method for ActiveRecord is contains:

District.where.contains(district_boundries: user.location)

The above query will utilize PostGIS’s ST_CONTAINS to see if the district_boundries column contains the user.location. I plan to add a convience method to convert EWKT strings to RGeo object, something like PostgreExt.geom('SRID=4623;POINT(1 1)'), to make generating queries from, say, a mobile user’s current location a bit easier.

As I get feedback and use postgres_ext-postgis, more features will get added. Stay tuned!

Newsletter

Stay in the Know

Get the latest news and insights on Elixir, Phoenix, machine learning, product strategy, and more—delivered straight to your inbox.

Narwin holding a press release sheet while opening the DockYard brand kit box