Skip to contents

Define label positions for JamPolygon using polylabelr::poi()

Usage

labelr_JamPolygon(
  jp,
  precision = 1,
  add_to_jp = FALSE,
  subset_multipart = TRUE,
  ...
)

Arguments

jp

JamPolygon

precision

numeric passed to polylabelr::poi(), default 1.

add_to_jp

logical default FALSE, indicating whether to add "label_x","label_y" into jp@polygons for persistence.

subset_multipart

logical default TRUE, whether to subset multipart polygons to label the largest area.

...

additional arguments are ignored.

Value

matrix with columns "x", "y", "dist"

Details

This function is a simple wrapper for polylabelr::poi(), which recognizes holes inside polygons.

Todo:

  • Consider basic support for non-overlapping label positions.

    1. First pass might be to use non-overlapping regions of a polygon among a set of polygons.

    2. Second pass would be to use the region with fewest overlaps among other polygons in the set, to define the label position. This rule could serve to solve (1) as well.

Examples

df3 <- data.frame(name=c("polygon1", "polygon2"),
label=c("polygon A", "polygon B"),
x=I(list(
   list(c(1, 6, 6, 1),
      c(2, 5, 5, 2),
      c(3, 4, 4, 3)),
   list(
      c(12, 15, 15, 12) - 3,
      c(13, 14, 14, 13) - 3)
)),
y=I(list(
   list(c(1, 1, 6, 6),
      c(2, 2, 5, 5),
      c(3, 3, 4, 4)),
   list(
      c(2, 2, 5, 5),
      c(3, 3, 4, 4))
)),
fill=jamba::alpha2col(c("gold", "firebrick"), alpha=0.7))
jp3 <- new("JamPolygon", polygons=df3);
plot(jp3);