Skip to contents

This function saves a layer and its style to a GeoPackage file or a PostGIS database. The destination is determined by the `to` argument.

Usage

save_to(clo, to, database, schema, layer_name)

# S3 method for class 'clc'
save_to(clo, to, database = NULL, schema = "public", layer_name = 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'`.

layer_name

A character string specifying the name of the layer in the output. If `NULL`, the name of the input `layer` is used.

Value

clo A `clc` object.

Details

The function overwrites the table if it already exists.

See also

Other CLC class functions: as_raster(), clc(), copy_to(), cut_to_extent(), get_colors.clc(), get_levels.clc(), get_raster(), plot_clc(), prepare_plot()

Examples

source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc")
clo <- clc(source = source_gpkg, layer_name = "clc")

# ex1
out_gpkg <- tempfile(fileext = ".gpkg")

sink(tempfile())
clo <- clo |>
  save_to(out_gpkg)
sink()

if (FALSE) { # \dontrun{
# ex2
conn <- RPostgres::dbConnect(
  RPostgres::Postgres(),
  dbname = 'exampledb',
  host = 'localhost',
  port = '5432',
  user = 'user',
  password = 'password'
)
clo <- clo |>
  save_to(conn, 'exampledb')
} # }