save_to: Save a Layer and its Style to a GeoPackage or PostGIS...

View source: R/clc.R

save_toR Documentation

Save a Layer and its Style to a GeoPackage or PostGIS Database

Description

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.

Details

The function overwrites the table if it already exists.

Value

clo A 'clc' object.

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()

## Not run: 
# ex2
conn <- RPostgres::dbConnect(
  RPostgres::Postgres(),
  dbname = 'exampledb',
  host = 'localhost',
  port = '5432',
  user = 'user',
  password = 'password'
)
clo <- clo |>
  save_to(conn, 'exampledb')

## End(Not run)

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