Skip to contents

Transfers vector layers with valid geometries from a GeoPackage file to a specified PostGIS database schema. Optionally allows setting a custom geometry column name, adding prefixes or postfixes to the table names, and renaming the layer fields to follow the Snake Case convention.

Usage

store_layers(
  gpkg,
  conn,
  schema = "public",
  prefix = NULL,
  postfix = NULL,
  layers = NULL,
  geom_colum = "geom",
  snake_case_fields = TRUE
)

Arguments

gpkg

A string, the path to the GeoPackage file.

conn

A PostGIS database connection object created with [RPostgres::dbConnect()].

schema

A string, the schema in PostGIS where layers will be stored. Default is `"public"`.

prefix

A string, an optional prefix to add to the table names in PostGIS. Default is `NULL`.

postfix

A string, an optional postfix to add to the table names in PostGIS. Default is `NULL`.

layers

A string vector, the name of the layers to transfer. If NULL, all vector layers are transferred.

geom_colum

A string, the name of the geometry column to set. Default is `"geom"`.

snake_case_fields

A logical, whether to convert field names to Snake Case. Default is `TRUE`.

Value

Invisibly returns a character vector of the names of the tables written to PostGIS.

See also

Other write to PostGIS: store_bands(), store_raster()

Examples

if (FALSE) { # \dontrun{
source_gpkg <- system.file("extdata", "sigugr.gpkg", package = "sigugr")

conn <- DBI::dbConnect(
  RPostgres::Postgres(),
  dbname = "mydb",
  host = "localhost",
  user = "user",
  password = "password"
)

store_layers(
  source_gpkg, conn, prefix = "pre_", postfix = "_post"
)

DBI::dbDisconnect(conn)
} # }