These functions provide simple interfaces for reading and writing grids from/to ASCII grids and Rd files. Grids are stored as matrices, their headers in lists.
read.ascii.grid(file, return.header = TRUE, print = 0,
nodata.values = c(), at.once = TRUE, na.strings = "NA")read.ascii.grid.header(file, ...)
read.sgrd(fname, return.header = TRUE, print = 0, nodata.values = c(),
at.once = TRUE, prec = 7, ...)
read.Rd.grid(fname, return.header = TRUE)
write.ascii.grid(data, file, header = NULL, write.header = TRUE, digits,
hdr.digits = 10, dec = ".", georef = "corner")
write.ascii.grid.header(file, header, georef, dec = ".", hdr.digits = 10)
write.sgrd(data, file, header = NULL, prec = 7, hdr.prec = 10,
georef = "corner", ...)
write.Rd.grid(data, file, header = NULL, write.header = TRUE,
compress = TRUE)
file name of an ASCII grid (extension defaults to .asc
if not specified), or a connection open for reading or writing, as required
logical: should the grid header be returned (default), or just the grid data matrix? In the former case, read.ascii.grid
returns a list with two components named data
and header
.
numeric, specifying how detailed the output reporting the progress should be (currently 0 to 2, 0 being minimum output).
optional numeric vector specifying nodata values to be used in addition to the nodata value specified in the grid header; nodata values are converted to NA
.
logical: if TRUE
, read the whole grid with one scan
command; if FALSE
, read it row by row using scan
with option nlines=1
.
passed on to scan()
.
read.sgrd
, write.sgrd
: additional arguments to be passed to rsaga.geoprocessor
file name of a grid stored as an R (.Rd
) file; extension defaults to .Rd
integer: number of digits of temporary ASCII grid used for importing or exporting a SAGA grid
grid data: a data matrix, or a list with components data
(the grid data matrix) and header
(the grid header information).
optional list argument specifying the grid header information as returned by the read.ascii.grid
or read.ascii.grid.header
function; see Details
logical: should the header be written with the grid data? (default: TRUE
)
numeric: if not missing, write data rounded to this many decimal places
numeric: see hdr.prec
character (default: "."
): decimal mark used in input or output file
character: specifies whether the output grid should be georeferenced by the "center"
or "corner"
of its lower left grid cell; defaults to "corner"
.
numeric: write (non-integer) header data with this many decimal places; a value of 9 or higher is recommended for compatibility with SAGA GIS (default: 10)
logical: should the .Rd
file written by write.Rd.file
be compressed? (default: TRUE
)
The read.*
functions return either a list with components data
(the grid data matrix) and header
(the grid header information, see below), if return.header=TRUE
, or otherwise just the grid data matrix return.header=FALSE
.
The grid data matrix is a numeric matrix whose first column corrensponds to the first (i.e. northernmost) row of the grid. Columns run from left = West to right = East.
The header information returned by the read.ascii.grid[.header]
functions (if return.header=TRUE
) is a list with the following components:
Number of grid columns.
Number of grid rows.
x coordinate of the corner of the lower left grid cell.
y coordinate of the corner of the lower left grid cell.
Single numeric value specifying the size of a grid cell or pixel in both x and y direction.
Single numeric value being interpreted as NA
(typically -9999
.
x coordinate of the center of the lower left grid cell
y coordinate of the center of the lower left grid cell
readGDAL
and rgdal::writeGDAL()
in package rgdal
, and readAsciiGrid
and maptools::writeAsciiGrid()
in package maptools