Skip to content
Prev 18304 / 29559 Next

spatialite from R

On 05/17/2013 04:04 AM, Gilles San Martin wrote:
These questions are fine for either R-sig-geo or Spatialite mailing 
lists (I've copied them on this email). Since you're most interested in 
R, maybe start with R-sig-geo

I haven't done this in a while but here are my notes:
library(RSQLite)
m <- dbDriver("SQLite")
con <- dbConnect(m, dbname = "test.db",loadable.extensions = TRUE)
sql <- "SELECT load_extension('libspatialite.so')"
rs <- dbGetQuery(con, sql)

Once you've done that you can run any query you want, the only tricky 
part is that you can't retrieve spatial blobs in any sensible way via 
this method. However if you have made a view, I believe that readOGR can 
then pull that whole view over as an sp object.

The code above is linux specific since an .so is a .dll on Windows. Also 
you'll need the RSQLite, RGDAL and Spatialite installed on the system 
thats going to use it. If you can't rely on your users to be able to 
install those things you might want to find a different way.

Thanks,
Alex