Largest polygon in a SpatialPolygons object

get_largest_polygon(sp, ...)

Arguments

sp

object with class sp::SpatialPolygons that may contain one or more closed polygons.

...

additional arguments are ignored.

Details

This function returns the largest polygon in a sp::SpatialPolygons object, notably when there are multiple polygons contained in one object. The function calculates the largest area using rgeos:gArea().

If two polygons have identical area, the first polygon is returned.

This function calls a helper function sp::disaggregate() which creates one sp::SpatialPolygons object for each individual polygon in the source object.

Examples

circles <- get_venn_shapes(c(A=1, B=2, "A&B"=3), proportional=TRUE)
col3 <- c("#FF000077", "#0000FF77")
sp::plot(circles)

circles_u12 <- union_polygons(circles[1:2]);
circles_i12 <- intersect_polygons(circles[1:2]);

# one SpatialPolygons object with multiple polygon pieces
circles_d12 <- rgeos::gDifference(circles_u12, circles_i12)
plot(circles_d12, add=TRUE, col="gold", lwd=3)

circles_d12_largest <- get_largest_polygon(circles_d12);
plot(circles_d12_largest, add=TRUE, border="red", lwd=5);