Skip to contents

Stores each band of a raster to a specified schema in a PostGIS database. Each band is written as a separate table in the database.

Usage

store_bands(
  raster,
  conn,
  schema = "public",
  prefix = NULL,
  postfix = NULL,
  bands = NULL
)

Arguments

raster

A character string specifying the file path to the GeoTIFF file containing the raster bands to be stored.

conn

A database connection object to a PostGIS database (e.g., from `RPostgres::dbConnect`).

schema

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

prefix

A string to prepend to each layer name. Default is `NULL`.

postfix

A string to append to each layer name. Default is `NULL`.

bands

A named integer vector, index of the bands to store with layer names. If it is `NULL`, which is the default value, all bands are stored using the band name as the layer name. If unnamed indices are provided, the band name is also used as the layer name.

Value

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

Details

Transforms the table name according to the Snake Case convention.

See also

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

Examples

if (FALSE) { # \dontrun{
conn <- DBI::dbConnect(
  RPostgres::Postgres(),
  dbname = "mydb",
  host = "localhost",
  user = "user",
  password = "password"
)

sr <- terra::rast(nrows = 10, ncols = 10, nlyrs = 3, vals = runif(300))
sr_file <- tempfile(fileext = ".tif")
terra::writeRaster(sr, sr_file, filetype = "GTiff", overwrite = TRUE)

tables <- store_bands(sr_file, conn, schema = "geodata", prefix = "example_", postfix = "_raster")

DBI::dbDisconnect(conn)
} # }