I'd like to extract a list of polygons from a SpatialPolygonsDataFrame that include more than one area (so a polygon with a hole for example, or just 2 areas in one polygon entry in general). There was a question answered previously which was very close to what I want but it wasn't testing for whether or not more than one area was listed, and it did not preserve the indices for which polygon had more than one area listed within it.
In the answer posted by @cengel, there are ways to list all the areas of the polygon, to get a list of polygons in the file, and to get the areas of a prespecified polygon, which is close but not what my specific question is:
-Example poly from cited question (without holes or multiple areas)
mp <- readWKT("MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))")
-total area
sapply(slot(mp, "polygons"), slot, "area")
-get list of individual polys
p <- lapply(mp@polygons , slot , "Polygons")
-areas of individual polygons
lapply(p[[1]], function(x) slot(x, "area"))
My structure looks more like this:
And the polygons with multiple areas like this:
There are two areas even though for some reason they don't show up in the list. I can plot them individually by using:
plot(poly@polygons[[112]]@Polygons[[2]]@coords,type = "l", asp=1)
(this is showing that I'm plotting the 2nd of 2 areas)
So basically, I'd like a list of which polygons have areas with more than one entry, but also which polygons those are (the index).