copy_to: Copy a Style to a GeoPackage or PostGIS Database

View source: R/clc.R

copy_toR Documentation

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 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.

Value

clo A 'clc' object.

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)

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

## Not run: 
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')

## End(Not run)

clc documentation built on April 4, 2025, 5:17 a.m.