| ddbs_union_funs | R Documentation |
Perform union and combine operations on spatial geometries in DuckDB.
ddbs_union() - Union all geometries into one, or perform pairwise union between two datasets
ddbs_union_agg() - Union geometries grouped by one or more columns
ddbs_combine() - Combine geometries into a MULTI-geometry without dissolving boundaries
ddbs_union(
x,
y = NULL,
by_feature = FALSE,
conn = NULL,
conn_x = NULL,
conn_y = NULL,
name = NULL,
mode = NULL,
overwrite = FALSE,
quiet = FALSE
)
ddbs_combine(
x,
conn = NULL,
name = NULL,
mode = NULL,
overwrite = FALSE,
quiet = FALSE
)
ddbs_union_agg(
x,
by,
mem = FALSE,
conn = NULL,
name = NULL,
mode = NULL,
overwrite = FALSE,
quiet = FALSE
)
x |
Input spatial data. Can be:
Data is returned from this object. |
y |
Input spatial data. Can be:
|
by_feature |
Logical. When
|
conn |
A connection object to a DuckDB database. If |
conn_x |
A |
conn_y |
A |
name |
A character string of length one specifying the name of the table,
or a character string of length two specifying the schema and table
names. If |
mode |
Character. Controls the return type. Options:
Can be set globally via |
overwrite |
Boolean. whether to overwrite the existing table if it exists. Defaults
to |
quiet |
A logical value. If |
by |
Character vector specifying one or more column names to
group by when computing unions. Geometries will be unioned within each group.
Default is |
mem |
Logical. If |
Performs geometric union operations that dissolve internal boundaries:
When y = NULL: Unions all geometries in x into a single geometry
When y != NULL and by_feature = FALSE: Unions all geometries from both x and y into a single geometry
When y != NULL and by_feature = TRUE: Performs row-wise union, pairing the first geometry from x with the first from y, second with second, etc.
Groups geometries by one or more columns, then unions geometries within each group.
Useful for dissolving boundaries between features that share common attributes.
Set mem = TRUE to use ST_MemUnion_Agg() when memory is a constraint.
Combines all geometries into a single MULTI-geometry (e.g., MULTIPOLYGON, MULTILINESTRING) without dissolving shared boundaries. This is faster than union but preserves all original geometry boundaries.
Depends on the mode argument (or global preference set by ddbs_options):
duckspatial (default): A duckspatial_df (lazy spatial data frame) backed by dbplyr/DuckDB.
sf: An eagerly collected object in R memory, that will return the same data type as the
sf equivalent (e.g. sf or units vector).
When name is provided, the result is also written as a table or view in DuckDB and the function returns TRUE (invisibly).
## Not run:
## load packages
library(dplyr)
library(duckspatial)
## create a duckdb database in memory (with spatial extension)
conn <- ddbs_create_conn(dbdir = "memory")
## read data
countries_ddbs <- ddbs_open_dataset(
system.file("spatial/countries.geojson",
package = "duckspatial")
) |>
filter(ISO3_CODE != "ATA")
rivers_ddbs <- ddbs_open_dataset(
system.file("spatial/rivers.geojson",
package = "duckspatial")
) |>
ddbs_transform("EPSG:4326")
## combine countries into a single MULTI-geometry
## (without solving boundaries)
combined_countries_ddbs <- ddbs_combine(countries_ddbs)
## combine countries into a single MULTI-geometry
## (solving boundaries)
union_countries_ddbs <- ddbs_union(countries_ddbs)
## union of geometries of two objects, into 1 geometry
union_countries_rivers_ddbs <- ddbs_union(countries_ddbs, rivers_ddbs)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.