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

Description Usage Arguments Details Value Source See Also Examples

View source: R/poi.R

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

1
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

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().

Value

A list with items

x

x coordinate of the center

y

y coordinate of the center

dist

distance to the enclosing polygon

Source

Garcia-Castellanos & Lombardo, 2007. Poles of inaccessibility: A calculation algorithm for the remotest places on earth Scottish Geographical Journal, Volume 123, 3, 227-233. https://dx.doi.org/10.1080/14702540801897809

https://github.com/mapbox/polylabel

https://blog.mapbox.com/a-new-algorithm-for-finding-a-visual-center-of-a-polygon-7c77e6492fbc

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)

## End(Not run)

Example output

Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
Reading layer `nc' from data source `/usr/lib/R/site-library/sf/shape/nc.shp' using driver `ESRI Shapefile'
Simple feature collection with 100 features and 14 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
geographic CRS: NAD27

polylabelr documentation built on April 19, 2020, 3:58 p.m.