raster (version 1.0.0-1)

read: Read values from disk

Description

Read values from a raster file associated with a Raster* object into memory. You can either read all the data (memory permitting), or read data for a single or multiple rows, or a block (a rectangular area). read* functions will fail when there is no file associated with the RasterLayer (values may only exist on memory). It is therefore safer to use getValues.

Usage

readAll(object)
readRow(object, rownr)
readRows(object, startrow, nrows)
readBlock(object, startrow, nrows=3, startcol=1, ncolumns=(ncol(object)-startcol+1))

Arguments

object
a Raster* object
rownr
the row number of the row to read (between 1 and nrows(raster))
startrow
the frist row to read (>= 1 &
nrows
the number of the rows to read (>= 1 &
startcol
first column of the block ( (>= 1 &
ncolumns
number of columns to read on this each row ( (>= 1 & <= ncols(raster)="" &=""> firstcol)

See Also

getValues, xyValues, cellValues, writeRaster

Examples

Run this code
rs <- raster(system.file("external/test.grd", package="raster"))

# read a row
  firstrow <- readRow(rs, 1)
  lastrow <- readRow(rs, rs@nrows)

# read a number of rows
  fiverows <- readRows(rs, startrow=50, nrows=5)

# read a block
  block <- readBlock(rs, startrow=50, nrows=5, startcol=30, ncolumns=10)
  
# read a row from a stack
  st <- stack(rs, rs, rs)  
  st <- readRow(st, 50)

Run the code above in your browser using DataLab