Get SpatialPolygons polylabelr coordinate

sp_polylabelr(sp, apply_holes = TRUE, ...)

Arguments

sp

sp::SpatialPolygons object

apply_holes

logical indicating whether to apply any polygon holes when present in sp.

...

additional arguments are ignored

Value

list with items x with x coordinate, y with y coordinate, and dist with distance to the enclosing polygon.

Details

This function is a simple wrapper function around polylabelr::poi() for sp::SpatialPolygons input. This function does two things:

  1. It finds the largest polygon in the sp::SpatialPolygons input, which may contain multiple disconnected polygons.

  2. It applies "holes" inside the polygon when present, to prevent the label from being chosen inside the hole.

Examples

setlist <- list(A=letters, B=sample(letters, 4));
vo <- venndir(setlist, proportional=TRUE, do_plot=FALSE);
sp <- vo$venn_spdf[1,];
plot(sp, col="gold")
xy <- sp_polylabelr(sp);
points(xy, pch=20, cex=4, col="navy")


# example with a hole inside
sp <- sp_ellipses(xcenter=1, ycenter=1, xradius=0.5, yradius=1);
sp_hole <- sp_ellipses(xcenter=1, ycenter=1, xradius=0.2, yradius=0.5);
sp_donut <- rgeos::gDifference(sp, sp_hole);
plot(sp_donut, col="gold")
spt <- sp_polylabelr(sp_donut);
text(x=spt$x, y=spt$y, add=TRUE, labels="label")