[R-sig-Geo] Remove holes from a SpatialPolygon
Mark Payne
markpayneatwork at gmail.com
Tue Dec 31 13:09:06 CET 2013
Hi,
I have a SpatialPolygon that I have created through a series of
processing steps. The SP consists of one outer-boundary, with a series
of holes punched in it - think of it as the coastline of an island
with a series of lakes in it. However, I am only interested in the
"external" coastline and don't want the "lakes". How do I best remove
these holes?
Here is what I have tried so far (bufr is the object of interest)
holes <- sapply(bufr at polygons[[1]]@Polygons,slot,"hole")
bufr.hole.free <- bufr
bufr.hole.free at polygons[[1]]@Polygons <-
bufr.hole.free at polygons[[1]]@Polygons[!holes]
bufr.hole.free at polygons[[1]]@plotOrder <-
as.integer(rank(bufr.hole.free at polygons[[1]]@plotOrder[holes]))
However, this fails when I try to use it later with rgeos:
roi.raw <- gDifference(bufr.hole.free,borders)
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, "rgeos_difference") :
lengths of comment and Polygons slot differ
How should I remove the holes in a manner that maintains the integrity
of the SpatialPolygons class?
Mark
More information about the R-sig-Geo
mailing list