From f7e31576a9d1ae72cb462fbd5c01bdd34140aa20 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 10 Nov 2023 16:04:17 +0100 Subject: [PATCH 1/2] try using by_feature --- R/geom-transformers.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/R/geom-transformers.R b/R/geom-transformers.R index efe20c5a1..e4e9d34ca 100644 --- a/R/geom-transformers.R +++ b/R/geom-transformers.R @@ -967,7 +967,7 @@ 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 @@ -1005,16 +1005,20 @@ 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)) - if (ll && sf_use_s2()) - st_as_sfc(s2::s2_union(x, y, ...), crs = st_crs(x)) + if (by_feature) + st_as_sfc(mapply(st_union, x, y, MoreArgs = list(is_coverage = is_coverage), SIMPLIFY = FALSE), crs = st_crs(x)) else { - if (ll) - message_longlat("st_union") - geos_op2_geom("union", x, y, ...) + if (ll && sf_use_s2()) + st_as_sfc(s2::s2_union(x, y, ...), crs = st_crs(x)) + else { + if (ll) + message_longlat("st_union") + geos_op2_geom("union", x, y, ...) + } } } } From 13f4ce9a16987a4177a5c3de2718093ba0511c3a Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 10 Nov 2023 16:44:19 +0100 Subject: [PATCH 2/2] fixes #2259 --- R/geom-transformers.R | 25 +++++++++++++------------ man/dbWriteTable.Rd | 20 +++++++++----------- man/geos_combine.Rd | 4 ++-- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/R/geom-transformers.R b/R/geom-transformers.R index e4e9d34ca..c2fdce7ab 100644 --- a/R/geom-transformers.R +++ b/R/geom-transformers.R @@ -974,7 +974,7 @@ st_snap.sf = function(x, y, tolerance) #' @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 @@ -1009,16 +1009,12 @@ st_union.sfc = function(x, y, ..., by_feature = FALSE, is_coverage = FALSE) { } } else { stopifnot(st_crs(x) == st_crs(y)) - if (by_feature) - st_as_sfc(mapply(st_union, x, y, MoreArgs = list(is_coverage = is_coverage), SIMPLIFY = FALSE), crs = st_crs(x)) + if (ll && sf_use_s2()) + st_as_sfc(s2::s2_union(x, y, ...), crs = st_crs(x)) else { - if (ll && sf_use_s2()) - st_as_sfc(s2::s2_union(x, y, ...), crs = st_crs(x)) - else { - if (ll) - message_longlat("st_union") - geos_op2_geom("union", x, y, ...) - } + if (ll) + message_longlat("st_union") + geos_op2_geom("union", x, y, ...) } } } @@ -1031,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 diff --git a/man/dbWriteTable.Rd b/man/dbWriteTable.Rd index d7a4428fa..f232618b6 100644 --- a/man/dbWriteTable.Rd +++ b/man/dbWriteTable.Rd @@ -32,19 +32,17 @@ \arguments{ \item{conn}{DBIObject} -\item{name}{The table name, passed on to \code{\link[DBI:dbQuoteIdentifier]{dbQuoteIdentifier()}}. Options are: -\itemize{ -\item a character string with the unquoted DBMS table name, -e.g. \code{"table_name"}, -\item a call to \code{\link[DBI:Id]{Id()}} with components to the fully qualified table name, -e.g. \code{Id(schema = "my_schema", table = "table_name")} -\item a call to \code{\link[DBI:SQL]{SQL()}} with the quoted and fully qualified table name -given verbatim, e.g. \code{SQL('"my_schema"."table_name"')} -}} +\item{name}{ + character vector of names (table names, fields, keywords). +} -\item{value}{a \link{data.frame} (or coercible to data.frame).} +\item{value}{ + a data.frame. +} -\item{...}{Other parameters passed on to methods.} +\item{...}{ + placeholder for future use. +} \item{row.names}{Add a \code{row.name} column, or a vector of length \code{nrow(obj)} containing row.names; default \code{FALSE}.} diff --git a/man/geos_combine.Rd b/man/geos_combine.Rd index 921354760..7a30b9217 100644 --- a/man/geos_combine.Rd +++ b/man/geos_combine.Rd @@ -17,7 +17,7 @@ st_union(x, y, ..., by_feature = FALSE, is_coverage = FALSE) \item{...}{ignored} -\item{by_feature}{logical; if TRUE, union each feature, if FALSE return a single feature that is the geometric union of the set of features} +\item{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} \item{is_coverage}{logical; if TRUE, use an optimized algorithm for features that form a polygonal coverage (have no overlaps)} } @@ -32,7 +32,7 @@ Combine several feature geometries into one, without unioning or resolving inter \details{ \code{st_combine} combines geometries without resolving borders, using \link{c.sfg} (analogous to \link[base]{c} for ordinary vectors). -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). }