I have a polygon layer (>600000 features) in a Spatialite database and I want to overcome to run out of RAM by selecting only the features I need for subsequent workflow.
I can connect to my Spatialite database using RSQLite
with the following code:
dbfile="Path/To/field.sqlite"
sqlite=dbDriver("SQLite")
con=dbConnect(sqlite,dbfile, loadable.extensions=TRUE )
I can also query my table and get an tabular output:
above1600<-dbGetQuery(con,"SELECT * from height_aspect where height >= 1600")
But I do not understand how to get a SpatialPolygon layer.
Do I have to convert the output or do I need to initialise the database as a spatial one?
I researched the web for a while but could not find anything that helps me.
Best Answer
You might consider using
rgdal
to read in the features from a Spatialite database based on the following example.From your terminal, check the layer names in your Spatialite database:
Then within R, do as follows:
Check that your version of rgdal supports Spatialite (you will see SQLite/Spatialite TRUE)
Use
readOGR
to read in your vector layer, e.g.:Check that everything has been correctly imported:
Check the output visually: