[R-sig-Geo] Write sf object to spatialite database
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Thu Nov 10 17:15:00 CET 2016
Thanks for trying.
I guess the sqlite session needs to be loaded with the spatialite
libraries before we can use the spatial functions, like
AddGeometryColumn, where it breaks on my machine:
> st_write_db(con, sf, "meuse_tbl", dropTable = FALSE)
Error in sqliteSendQuery(con, statement, bind.data) :
error in statement: no such function: AddGeometryColumn
For postgis, we of course assume that the database has the PostGIS
extensions loaded, on a "raw" PostgreSQL database you'll get the same
error, I'd expect.
To get back to your first question: does your st_drivers() include
spatialite?
> x = st_drivers()
> x[x$name == "SQLite",]
name long_name write copy is_raster is_vector
151 SQLite SQLite / Spatialite TRUE FALSE FALSE TRUE
In that case, you may want to use st_write instead.
On 10/11/16 15:47, Loïc Dutrieux wrote:
> Hi,
>
> Is it possible to write sf objects to spatialite databases? I tried to
> adapt the postgis example of the st_write_db function but I get the
> following error:
>
> Error in sqliteSendQuery(con, statement, bind.data) :
> error in statement: no such function: AddGeometryColumn
>
> Cheers,
> Loïc
>
> library(sf)
> library(sp)
> library(RSQLite)
>
> data(meuse)
> sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992)
>
> # I created the db with QGIS, I don't know how to do otherwise
> con <- dbConnect(RSQLite::SQLite(), '~/sandbox/db.sqlite')
>
> st_write_db(con, sf, "meuse_tbl", dropTable = FALSE)
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
Journal of Statistical Software: http://www.jstatsoft.org/
Computers & Geosciences: http://elsevier.com/locate/cageo/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20161110/2ec3af19/attachment.bin>
More information about the R-sig-Geo
mailing list