Spatialite with ruby

Posted by Kashif on July 05, 2009

I would like to detail the process of getting spatialite, the geospatial extension to sqlite3, working with ruby. Its a bit involved so I though others might find it useful.

To begin with one needs to compile sqlite3 with the R*Tree module turned on. By default this is not the case and on my Linux gentoo box I needed to change the sqlite3 ebuild as follows:

Once sqlite3 is installed, we need to install spatialite. On gentoo I created the following ebuild:

Once spatialite is installed we need to add a method to the sqlite3-ruby gem to enable the loading and unloading of extensions. By default this is not allowed due to security reasons, but one needs it to load the libspatialite extension. I have forked Jamis’ repo and pushed the changes to my branch here on github. Feel free to merge or pull from me.

Once this version of sqlite3-ruby is installed, we can use it in ruby as follows: