Learn R Programming

cartography (version 2.2.1)

getBorders: Extract Polygons Borders

Description

Extract borders between polygons.

Usage

getBorders(x, id, spdf, spdfid = NULL)

Arguments

x

an sf object, a simple feature collection or a SpatialPolygonsDataFrame.

id

name of the identifier variable x or spdf, default to the first column. (optional)

spdf

deprecated, a SpatialPolygonsDataFrame. This SpatialPolygonsDataFrame has to be projected (planar coordinates).

spdfid

deprecated, name of the identifier variable in spdf, default to the first column of the spdf data frame. (optional)

Value

An sf object (MULTILINESTRING) of borders is returned. This object has three id variables: id, id1 and id2. id1 and id2 are ids of units that neighbour a border; id is the concatenation of id1 and id2 (with "_" as separator).

See Also

discLayer, getOuterBorders

Examples

Run this code
# NOT RUN {
library(sf)
mtq <- st_read(system.file("gpkg/mtq.gpkg", package="cartography"))
# Get borders
mtq.borders <- getBorders(x = mtq)
# Plot polygons
plot(st_geometry(mtq), border = NA, col = "grey60")
# Plot borders
plot(st_geometry(mtq.borders), 
     col = sample(x = rainbow(nrow(mtq.borders))), 
     lwd = 3, add = TRUE)
# }

Run the code above in your browser using DataLab