The function readOGR
in the rgdal
package is used to bring vector spatial data sources into R. readOGR()
relies upon OGR (part of the GDAL/OGR library) for format conversion. Unfortunately, while OGR supports the ability to subset columns (with the -select
switch) or rows (with the -where
switch), or even to request a layer using a full SQL statement, none of that functionality is available in readOGR
. Every so often this gets discussed in the mailing lists, but the functionality has not yet been implemented.
If your data is already in a SQL database though, you’re in luck. You can accomplish the same thing within R by creating a spatial view in-database, loading the spatial view with readOGR
, then dropping the view. I’ve created a function that does just that for PostGIS data sources. Continue reading Subsetting in readOGR