| ddbs_force_dim | R Documentation |
Functions to force geometries to have specific coordinate dimensions (X, Y, Z, M)
ddbs_force_2d(
x,
conn = NULL,
name = NULL,
mode = NULL,
overwrite = FALSE,
quiet = FALSE
)
ddbs_force_3d(
x,
var,
dim = "z",
conn = NULL,
name = NULL,
mode = NULL,
overwrite = FALSE,
quiet = FALSE
)
ddbs_force_4d(
x,
var_z,
var_m,
conn = NULL,
name = NULL,
mode = NULL,
overwrite = FALSE,
quiet = FALSE
)
x |
Input spatial data. Can be:
Data is returned from this object. |
conn |
A connection object to a DuckDB database. If |
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 |
var |
A numeric variable in |
dim |
The dimension to add: either |
var_z |
A numeric variable in |
var_m |
A numeric variable in |
These functions modify the dimensionality of geometries:
ddbs_force_2d() removes Z and M coordinates from geometries, returning only
X and Y coordinates. This is useful for simplifying 3D or measured geometries
to 2D.
ddbs_force_3d() forces geometries to have three dimensions. When dim = "z"
(default), adds or retains Z coordinates (X, Y, Z). When dim = "m", adds or
retains M coordinates (X, Y, M). Missing values are typically set to 0. If the
input geometry has a third dimension already, it will be replaced by the new one.
If the input geometry has 4 dimensions, it will drop the dimension that wasn't
specified.
ddbs_force_4d() forces geometries to have all four dimensions (X, Y, Z, M).
Missing Z or M values are typically set to 0.
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)
## load data and add 2 numeric vars
countries_ddbs <- ddbs_open_dataset(
system.file("spatial/countries.geojson",
package = "duckspatial")
) |>
dplyr::filter(ISO3_CODE != "ATA") |>
ddbs_area(new_column = "area") |>
ddbs_perimeter(new_column = "perim")
## add a Z dimension
countries_z_ddbs <- ddbs_force_3d(countries_ddbs, "area")
ddbs_has_z(countries_z_ddbs)
## add a M dimension as 3D (removes current Z)
countries_m_ddbs <- ddbs_force_3d(countries_z_ddbs, "area", "m")
ddbs_has_z(countries_m_ddbs)
ddbs_has_m(countries_m_ddbs)
## add both Z and M
countries_zm_ddbs <- ddbs_force_4d(countries_ddbs, "area", "perim")
ddbs_has_z(countries_zm_ddbs)
ddbs_has_m(countries_zm_ddbs)
## drop both ZM
countries_drop_ddbs <- ddbs_force_2d(countries_zm_ddbs)
ddbs_has_z(countries_drop_ddbs)
ddbs_has_m(countries_drop_ddbs)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.