save_to | R Documentation |
This function saves a layer and its style to a GeoPackage file or a PostGIS database. The destination is determined by the 'to' argument.
save_to(clo, to, database, schema, layer_name)
## S3 method for class 'clc'
save_to(clo, to, database = NULL, schema = "public", layer_name = NULL)
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. |
The function overwrites the table if it already exists.
clo A 'clc' object.
Other CLC class functions:
as_raster()
,
clc()
,
copy_to()
,
cut_to_extent()
,
get_colors.clc()
,
get_levels.clc()
,
get_raster()
,
plot_clc()
,
prepare_plot()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.