rpostgis (version 1.4.3)

pgWriteRast: Write raster to PostGIS database table.

Description

Sends R raster to a new PostGIS database table.

Usage

pgWriteRast(
  conn,
  name,
  raster,
  bit.depth = NULL,
  blocks = NULL,
  constraints = TRUE,
  overwrite = FALSE,
  append = FALSE
)

Value

TRUE for successful import.

Arguments

conn

A connection object to a PostgreSQL database

name

A character string specifying a PostgreSQL schema (if necessary) and table name to hold the raster (e.g., name = c("schema","table"))

raster

An R RasterLayer, RasterBrick, or RasterStack from raster package; a SpatialGrid* or SpatialPixels* 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.

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

Author

David Bucklin david.bucklin@gmail.com

Details

RasterLayer 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 package are converted to raster package objects prior to insert.

If blocks = NULL the attempted block size will be around 10,000 pixels in size (100 x 100 cells), so number of blocks will vary by raster size. 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

Examples

Run this code
if (FALSE) {
pgWriteRast(conn, c("schema", "tablename"), raster_name)

# basic test
r <- raster::raster(nrows=180, ncols=360, xmn=-180, xmx=180,
    ymn=-90, ymx=90, vals=1)
pgWriteRast(conn, c("schema", "test"), raster = r,
    bit.depth = "2BUI", overwrite = TRUE)
}

Run the code above in your browser using DataLab