Skip to content
Prev 2700 / 29559 Next

Subsetting SpatialPolygonsDataFrame and empty ID slots

On Mon, 29 Oct 2007, Agustin Lobo wrote:

            
Please treat all the long named access thingies in sp as deprecated - they 
will be flagged as such in the next release, and removed one release after 
that. S4 is not like that.

library(sp)
library(rgdal)
example(readOGR)
class(Up)
getSlots(class(Up))
class(slot(Up, "polygons")[[1]])
getSlots(class(slot(Up, "polygons")[1]))

So:

sapply(slot(Up, "polygons"), function(x) slot(x, "ID"))
Of course there is an ID, but you can get at either by:

sapply(slot(pols, "polygons"), function(x) slot(x, "ID"))

or

rownames(as(pols, "data.frame"))
Returning to the original question, subsetting is simply by the "[" 
operator, just like any other data.frame:

sites_Lupuna <- length(grep("Lupuna", as.character(pols$Site))) > 0
summary(sites_Lupuna)
pols_Lupuna <- pols[sites_Lupuna,]

Just think of Spatial*DataFrame objects as data.frame objects and things 
will be much clearer.

Roger
PS. PolySet objects are really for drawing coastlines in this context.