polylabelr (version 0.2.0)

poi: Pole of Inaccessibility (Visual Center) of a Polygon

Description

This function computes and returns the approximate pole of inaccessibility for a polygon using a quadtree-based algorithm developed by the people from Mapbox.

Usage

poi(x, y = NULL, precision = 1)

Arguments

x

a vector of x coordinates or a matrix or data.frame of x and y coordinates, a list of components x and y, a time series (see grDevices::xy.coords() for details), or a simple features object from package sf.

y

a vector of y coordinates. Only needs to be provided if x is vector.

precision

the precision to use when computing the center

Value

A list with items

x

x coordinate of the center

y

y coordinate of the center

dist

distance to the enclosing polygon

Details

If there are any NA values in the input, they will be treated as separators for multiple paths (rings) of the polygon, mimicking the behavior of graphics::polypath().

See Also

grDevices::xy.coords(), graphics::polypath()

Examples

Run this code
# NOT RUN {
plot_path <- function(x, y, ...) {
  plot.new()
  plot.window(range(x, na.rm = TRUE), range(y, na.rm = TRUE))
  polypath(x, y, ...)
}

x <- c(5, 10, 10, 5, 5, 6, 6, 7, 7, 6, 8, 8, 9, 9, 8)
y <- c(5, 5, 10, 10, 5, 6, 7, 7, 6, 6, 8, 9, 9, 8, 8)

plot_path(x, y, col = "grey", border = NA)

points(poi(x, y))

# }
# NOT RUN {
# Find visual centers for North Carolina counties
library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
locations = do.call(rbind, poi(nc, precision=0.01))
plot(st_geometry(nc))
points(locations)
# }

Run the code above in your browser using DataLab