This function copies a style to the specified layers in a GeoPackage file or a PostGIS database. The destination is determined by the `to` argument.
Usage
copy_to(clo, to, database, schema, layers)
# S3 method for class 'clc'
copy_to(clo, to, database = NULL, schema = "public", layers = NULL)
Arguments
- clo
A `clc` object.
- to
A data destination for the output. This can be: - A string representing the path to a GeoPackage file. - A `DBI` database connection object to a PostGIS database, created using [RPostgres::dbConnect()].
- database
A string, database name, only in case the destination is in PostGIS.
- schema
A string, schema name, only in case the destination is in PostGIS. Defaults to `'public'`.
- layers
An optional character vector specifying the names of layers in the destination to which the styles should be applied. If `NULL` (default), applies the style to all layers.
See also
Other CLC class functions:
as_raster()
,
clc()
,
cut_to_extent()
,
get_colors.clc()
,
get_levels.clc()
,
get_raster()
,
plot_clc()
,
prepare_plot()
,
save_to()
Examples
source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc")
clo <- clc(source = source_gpkg, layer_name = "clc")
out_gpkg <- tempfile(fileext = ".gpkg")
clo <- clo |>
save_to(out_gpkg)
#> Writing layer `clc' to data source
#> `/tmp/Rtmp2vU0nl/file1a1163a2aa32.gpkg' using driver `GPKG'
#> Writing 136 features with 2 fields and geometry type Multi Polygon.
# ex1
clo <- clo |>
copy_to(out_gpkg, layers = 'clc')
if (FALSE) { # \dontrun{
conn <- RPostgres::dbConnect(
RPostgres::Postgres(),
dbname = 'exampledb',
host = 'localhost',
port = '5432',
user = 'user',
password = 'password'
)
clo <- clo |>
save_to(conn, 'exampledb')
# ex2
clo <- clo |>
copy_to(conn, 'exampledb', layers = 'clc')
} # }