Learn R Programming

clc (version 1.0.0)

copy_to: Copy a Style to a GeoPackage or PostGIS Database

Description

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 clc copy_to(clo, to, database = NULL, schema = "public", layers = NULL)

Value

clo A `clc` object.

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

Run this code
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)

# ex1
clo <- clo |>
  copy_to(out_gpkg, layers = 'clc')

if (FALSE) {
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')
}

Run the code above in your browser using DataLab