Skip to contents

Merges polygons sharing the same value in a grouping column and recalculates area_km2.

Usage

pk_union(x, by)

Arguments

x

An sf object.

by

Character. Column name to group by.

Value

Returns a dissolved sf object (class "sf" and "data.frame") with:

geometry

MULTIPOLYGON geometries created by merging adjacent polygons

by_column

The unique grouping values (one row per group)

area_km2

Recalculated area in square kilometres for each dissolved polygon

Polygons that are not spatially adjacent but share the same group value will become MULTIPOLYGON objects. Invalid geometries are repaired automatically using sf::st_make_valid().

Examples

tehsils <- get_tehsils()
by_district <- pk_union(tehsils, by = "district_name")