Learn R Programming

RCzechia (version 1.4.3)

union_sf: Aggregate Polygons in a sf Object

Description

The function aggregates polygons of geometry column of a sf data frame according to values of a single data column. It has outcome comparable to unionSpatialPolygons from maptools package, except that it works on sf and not sp objects.

Usage

union_sf(data, key, tolerance = 1, planarCRS = 5514)

Arguments

data

sf data frame to be aggregated

key

name of column to define the output objects

tolerance

buffer size for avoiding artefacts (slivers); default is one meter

planarCRS

planar CRS for avoiding artefacts (slivers); default is EPSG:5514 = ing. K<U+0159>ov<U+00E1>k

Details

The function has data frame as the first argument, so it is pipe friendly. It retains only geometry and key value, dropping all other columns (they are easy to re-attach using tidyverse/dplyr workflow if required).

During processing the sf data frame is temporarily transformed to planar coordinates and - to avoid artefacts (slivers) at the place of former boundaries - buffered; the default values of planarCRS and tolerance should cover most situations in the Czech Republic and near abroad.

Examples

Run this code
# NOT RUN {
NUTS3 <- union_sf(okresy(), "KOD_CZNUTS3")
  # assembles NUTS3 regions from LAU1 regions of Czech Republic = equivalent to kraje() in geometry

plot(NUTS3)

# }

Run the code above in your browser using DataLab