Skip to content

Commit

Permalink
Merge branch 'union'
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Nov 10, 2023
2 parents 260bde4 + 13f4ce9 commit 41a3c2c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
15 changes: 10 additions & 5 deletions R/geom-transformers.R
Original file line number Diff line number Diff line change
Expand Up @@ -967,14 +967,14 @@ st_snap.sf = function(x, y, tolerance)

#' @name geos_combine
#' @export
#' @param by_feature logical; if TRUE, union each feature, if FALSE return a single feature that is the geometric union of the set of features
#' @param by_feature logical; if TRUE, union each feature if \code{y} is missing or else each pair of features; if FALSE return a single feature that is the geometric union of the set of features in \code{x} if \code{y} is missing, or else the unions of each of the elements of the Cartesian product of both sets
#' @param is_coverage logical; if TRUE, use an optimized algorithm for features that form a polygonal coverage (have no overlaps)
#' @param y object of class \code{sf}, \code{sfc} or \code{sfg} (optional)
#' @param ... ignored
#' @seealso \link{st_intersection}, \link{st_difference}, \link{st_sym_difference}
#' @return If \code{y} is missing, \code{st_union(x)} returns a single geometry with resolved boundaries, else the geometries for all unioned pairs of x[i] and y[j].
#' @details
#' If \code{st_union} is called with a single argument, \code{x}, (with \code{y} missing) and \code{by_feature} is \code{FALSE} all geometries are unioned together and an \code{sfg} or single-geometry \code{sfc} object is returned. If \code{by_feature} is \code{TRUE} each feature geometry is unioned. This can for instance be used to resolve internal boundaries after polygons were combined using \code{st_combine}. If \code{y} is provided, all elements of \code{x} and \code{y} are unioned, pairwise (and \code{by_feature} is ignored). The former corresponds to \code{rgeos::gUnaryUnion}, the latter to \code{rgeos::gUnion}.
#' If \code{st_union} is called with a single argument, \code{x}, (with \code{y} missing) and \code{by_feature} is \code{FALSE} all geometries are unioned together and an \code{sfg} or single-geometry \code{sfc} object is returned. If \code{by_feature} is \code{TRUE} each feature geometry is unioned individually. This can for instance be used to resolve internal boundaries after polygons were combined using \code{st_combine}. If \code{y} is provided, all elements of \code{x} and \code{y} are unioned, pairwise if \code{by_feature} is TRUE, or else as the Cartesian product of both sets.
#'
#' Unioning a set of overlapping polygons has the effect of merging the areas (i.e. the same effect as iteratively unioning all individual polygons together). Unioning a set of LineStrings has the effect of fully noding and dissolving the input linework. In this context "fully noded" means that there will be a node or endpoint in the output for every endpoint or line segment crossing in the input. "Dissolved" means that any duplicate (e.g. coincident) line segments or portions of line segments will be reduced to a single line segment in the output. Unioning a set of Points has the effect of merging all identical points (producing a set with no duplicates).
#' @examples
Expand Down Expand Up @@ -1005,7 +1005,7 @@ st_union.sfc = function(x, y, ..., by_feature = FALSE, is_coverage = FALSE) {
} else {
if (ll)
message_longlat("st_union")
st_sfc(CPL_geos_union(st_geometry(x), by_feature, is_coverage))
st_sfc(CPL_geos_union(x, by_feature, is_coverage))
}
} else {
stopifnot(st_crs(x) == st_crs(y))
Expand All @@ -1027,8 +1027,13 @@ st_union.sf = function(x, y, ..., by_feature = FALSE, is_coverage = FALSE) {
st_set_geometry(x, geom)
else
geom
} else
geos_op2_df(x, y, geos_op2_geom("union", x, y, ...))
} else {
if (by_feature) {
df = cbind(st_drop_geometry(x), st_drop_geometry(y))
st_set_geometry(df, st_union(st_geometry(x), st_geometry(y), is_coverage = is_coverage))
} else
geos_op2_df(x, y, geos_op2_geom("union", x, y, ...))
}
}

#' Sample points on a linear geometry
Expand Down
20 changes: 9 additions & 11 deletions man/dbWriteTable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/geos_combine.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 41a3c2c

Please sign in to comment.