Wednesday, September 10, 2014

GeoRails

Yesterday I attended my first class at Railsschool. The topic of the discussion was how to create geospatial applications with Rails. As I've worked at lot with traditional GIS in the past (mainly ArcGIS), I was definitely interested in learning how to apply my geographic skills in the realm of web geography.

We covered the usage of the activerecord-postgis-adapter and rgeo gems. The rgeo gem relies of PostGIS extension for PostgreSQL, which is the recommended choice for working with spatial data.

I am not sure how many hiccups there would be along the way when working with complex datasets and applications (I am sure more than I can imagine), but creating a very simple tutorial-like application was fairly straightforward. The author of the gem wrote a series of blog posts back in 2011, which is still a great reference.

Some pain usually comes with installing PostGIS itself. However, I used a Postgres.app for OSX, which comes bundled with PostGIS and is very easy to install.

One thing to remember is that PostGIS extension needs to be enabled for each of the databases you intend to use. It is possible to do it either manually, that is connecting to the database via psql --dbname=yourdatabasename and running the following commands (taken from the website):

-- Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
-- Enable Topology
CREATE EXTENSION postgis_topology;
-- fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
-- Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;

However, in Rails environment it is easier to run the following command: rake db:gis:setup, which enables the PostGIS extension. As already mentioned, the blog referenced above as well as the  github pages for activerecord-postgis-adapter and rgeo gems provide a lot of instructions.
 

No comments :

Post a Comment