#' @title Remove Holes from SpatialPolygons* objects.
#'
#' @description
#' \code{splitDissolve} removes all holes in polygons.
#'
#' @details
#'
#' @param input SpatialPolygons* object.
#'
#' @return Returns a SpatialPolygons* object without holes.
#'
#' @export
# @examples need to find test data and add examples
remove.holes <- function (input) {
if (!grepl("SpatialPolygon", class(input))) {
stop("\"input\" input not of a \'SpatialPolygon*\' class")
}
is.hole <- unlist(lapply(seq(1, length(input@polygons[[1]]@Polygons)), function(P) input@polygons[[1]]@Polygons[[P]]@hole))
polys <- input@polygons[[1]]@Polygons[!is.hole]
Poly1 <- Polygons(polys,ID=input@polygons[[1]]@ID)
Poly2 <- SpatialPolygons(list(Poly1), proj4string = input@proj4string)
if (grepl("DataFrame", class(input))) {
Poly3 <- SpatialPolygonsDataFrame(Poly2, data = input@data)
return(Poly3)
} else {
return(Poly2)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.