Learn R Programming

cartography (version 1.2)

getBorders: Extract SpatialPolygonsDataFrame Borders

Description

Extract borders between SpatialPolygonsDataFrame units.

Usage

getBorders(spdf, spdfid = NULL, tol = 1)

Arguments

spdf
a SpatialPolygonsDataFrame. This SpatialPolygonsDataFrame has to be projected (planar coordinates).
spdfid
identifier field in spdf, default to the first column of the spdf data frame. (optional)
tol
tolerance to detect contiguity (in map units). You may not want to change this parameter.

Value

  • A SpatialLinesDataFrame of borders is returned. This object has three id fields: 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

Examples

Run this code
data(nuts2006)
# Get units borders
nuts0.contig.spdf <- getBorders(nuts0.spdf)
# Random colors
nuts0.contig.spdf$col <- sample(x = rainbow(length(nuts0.contig.spdf)))
# Plot Countries
plot(nuts0.spdf, border = NA, col = "grey60")
# Plot borders
plot(nuts0.contig.spdf, col = nuts0.contig.spdf$col, lwd = 3, add = TRUE)

Run the code above in your browser using DataLab