Sends R raster to a PostGIS database table.
Usage
pgWriteRast(
conn,
name,
raster,
bit.depth = NULL,
blocks = NULL,
constraints = TRUE,
overwrite = FALSE,
append = FALSE
)
Arguments
- conn
A connection object to a PostgreSQL database.
- name
A character string specifying a PostgreSQL schema in the database (if necessary) and table name to hold the raster (e.g.,
name = c("schema","table")
).- raster
An terra
SpatRaster
; objects from the raster package (RasterLayer
,RasterBrick
, orRasterStack
); aSpatialGrid*
orSpatialPixels*
from sp package.- bit.depth
The bit depth of the raster. Will be set to 32-bit (unsigned int, signed int, or float, depending on the data) if left null, but can be specified (as character) as one of the PostGIS pixel types (see http://postgis.net/docs/RT_ST_BandPixelType.html).
- blocks
Optional desired number of blocks (tiles) to split the raster into in the resulting PostGIS table. This should be specified as a one or two-length (columns, rows) integer vector. See also 'Details'.
- constraints
Whether to create constraints from raster data. Recommended to leave
TRUE
unless applying constraints manually (see http://postgis.net/docs/RT_AddRasterConstraints.html). Note that constraint notices may print to the console, depending on the PostgreSQL server settings.- overwrite
Whether to overwrite the existing table (
name
).- append
Whether to append to the existing table (
name
).
Details
SpatRaster band names will be stored in an array in the column
"band_names", which will be restored in R when imported with the function
pgGetRast()
.
Rasters from the sp
and raster
packages are converted to
terra
objects prior to insert.
If blocks = NULL
, the number of block will vary by raster size, with
a default value of 100 copies of the data in the memory at any point in time.
If a specified number of blocks is desired, set blocks to a one or two-length
integer vector. Note that fewer, larger blocks generally results in faster
write times.
See also
Function follows process from http://postgis.net/docs/using_raster_dataman.html#RT_Creating_Rasters.
Author
David Bucklin david.bucklin@gmail.com and Adrián Cidre González adrian.cidre@gmail.com