Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

remove.holes

Remove polygon holes


Description

Removes all holes (null geometry) in polygon sp class objects

Usage

remove.holes(x)

Arguments

x

SpatialPolygons or SpatialPolygonsDataFrame class object

Value

SpatialPolygonsDataFrame object with all holes removed

Note

A hole is considered a polygon within a polygon representing null geometry

Author(s)

Jeffrey S. Evans <jeffrey_evans@tnc.org>

Examples

library(sp)
 Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))
 Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))
 Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5)))
 Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE)
 polys <- SpatialPolygons(list(Polygons(list(Sr1), "s1"),
                 Polygons(list(Sr2), "s2"),
                 Polygons(list(Sr3, Sr4), "s3/4")), 1:3)

opar <- par(no.readonly=TRUE)
   par(mfrow=c(1,2))
     plot(polys, col = 1:3, main="with hole")
     plot(remove.holes(polys), col = 1:3, main="with hole removed")
par(opar)

spatialEco

Spatial Analysis and Modelling Utilities

v1.3-6
GPL-3
Authors
Jeffrey S. Evans [aut, cre], Melanie A. Murphy [ctb], Karthik Ram [ctb]
Initial release
2021-03-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.