Learn R Programming

surveillance (version 1.23.1)

polyAtBorder: Indicate Polygons at the Border

Description

Determines which polygons of a "SpatialPolygons" object are at the border, i.e. have coordinates in common with the spatial union of all polygons (constructed using unionSpatialPolygons).

Usage

polyAtBorder(SpP, snap = sqrt(.Machine$double.eps),
             method = "sf", ...)

Value

logical vector of the same length as SpP also inheriting its row.names.

Arguments

SpP

an object of class "SpatialPolygons".

snap

tolerance used to consider coordinates as identical.

method

method to use for unionSpatialPolygons. Defaults to sf, since polyclip uses integer arithmetic, which causes rounding errors usually requiring tuning of (i.e., increasing) the tolerance parameter snap (see example below).

...

further arguments passed to the chosen method.

Author

Sebastian Meyer

Examples

Run this code
## Load districts of Germany
load(system.file("shapes", "districtsD.RData", package = "surveillance"))

## Determine districts at the border and check the result on the map
if (requireNamespace("sf")) {
    atBorder <- polyAtBorder(districtsD, method = "sf")
    if (interactive()) plot(districtsD, col = atBorder)
    table(atBorder)
}

## For method = "polyclip", a higher snapping tolerance is required
## to obtain the correct result
if (requireNamespace("polyclip")) {
    atBorder <- polyAtBorder(districtsD, snap = 1e-6, method = "polyclip")
    if (interactive()) plot(districtsD, col = atBorder)
    table(atBorder)
}

Run the code above in your browser using DataLab