
Dissolve geometry preserving existing or supplied grouping variables
Source:R/st_dissolve.R
st_dissolve.Rdst_dissolve() dissolves sf and sfc objects. If the input object is an sf
object, any existing grouping variables or added grouping variables passed to
the .by parameter are included in the output sf data frame.
Usage
st_dissolve(
x,
...,
.by = NULL,
.keep = "nest",
do_union = TRUE,
.data_key = "data",
.dissolve_key = "group.comp.id",
call = caller_env
)Arguments
- x
A sf or sfc object. If sf object, a grouped data frame is allowed.
- ...
Arguments passed on to
spdep::poly2nbpllist of polygons of class extending
SpatialPolygons, or ansforsfcobject containing non-empty (multi-)polygon objectsrow.namescharacter vector of region ids to be added to the neighbours list as attribute
region.id, defaultseq(1, nrow(x)); ifplhasrow.names, they are used instead of the default sequence.snapboundary points less than
snapdistance apart are considered to indicate contiguity; used both to find candidate and actual neighbours for planar geometries, but only actual neighbours for spherical geometries, as spherical spatial indexing itself injects some fuzzyness. If not set, for allSpatialPolygonsobjects, the default is as beforesqrt(.Machine$double.eps), with this value also used forsfobjects with no coordinate reference system. Forsfobjects with a defined coordinate reference system, the default value is1e-7for geographical coordinates (approximately 10mm), is 10mm where projected coordinates are in metre units, and is converted from 10mm to the same distance in the units of the coordinates. Should the conversion fail,snapreverts tosqrt(.Machine$double.eps).queenif TRUE, a single shared boundary point meets the contiguity condition, if FALSE, more than one shared point is required; note that more than one shared boundary point does not necessarily mean a shared boundary line
useCdefault TRUE, doing the work loop in C, may be set to false to revert to R code calling two C functions in an
n*kwork loop, wherekis the average number of candidate neighboursfoundInBoxdefault NULL using R code or
st_intersects()to generate candidate neighbours (usingsnap=if the geometries are not spherical); if not NULL (for legacy purposes) a list of length(n-1)with integer vectors of candidate neighbours(j > i)(as created by thepoly_findInBoxGEOSfunction in rgeos for clean polygons)
- .by
-
<
tidy-select> Optionally, a selection of columns to group by for just this operation, functioning as an alternative togroup_by(). For details and examples, see ?dplyr_by. - .keep
Method for handling attributes for input data. By default ("nest"), input data is converted to a nested list column with the name from
.data_key. Any other values- do_union
Use
sf::st_union()to dissolve geometry ifTRUE(default). Usesf::st_combine()ifFALSE.- .data_key
Passed to
.dataargument oftidyr::nest()- .dissolve_key
Used as the column name for the dissolve grouping variable. x can't have any existing columns with this name.
- call
The execution environment of a currently running function, e.g.
caller_env(). The function will be mentioned in error messages as the source of the error. See thecallargument ofabort()for more information.