read.ascii.grid | R Documentation |
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 |
file name of an ASCII grid (extension defaults to |
return.header |
logical: should the grid header be returned (default), or just the grid data matrix? In the former case, |
print |
numeric, specifying how detailed the output reporting the progress should be (currently 0 to 2, 0 being minimum output). |
nodata.values |
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 |
at.once |
logical: if |
na.strings |
passed on to |
... |
|
fname |
file name of a grid stored as an R ( |
prec |
integer: number of digits of temporary ASCII grid used for importing or exporting a SAGA grid |
data |
grid data: a data matrix, or a list with components |
header |
optional list argument specifying the grid header information as returned by the |
write.header |
logical: should the header be written with the grid data? (default: |
digits |
numeric: if not missing, write data rounded to this many decimal places |
hdr.digits |
numeric: see |
dec |
character (default: |
georef |
character: specifies whether the output grid should be georeferenced by the |
hdr.prec |
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) |
compress |
logical: should the |
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:
ncols |
Number of grid columns. |
nrows |
Number of grid rows. |
xllcorner |
x coordinate of the corner of the lower left grid cell. |
yllcorner |
y coordinate of the corner of the lower left grid cell. |
cellsize |
Single numeric value specifying the size of a grid cell or pixel in both x and y direction. |
nodata_value |
Single numeric value being interpreted as |
xllcenter |
x coordinate of the center of the lower left grid cell |
yllcenter |
y coordinate of the center of the lower left grid cell |
Note: The order of the components, especially of ?llcorner
and ?llcenter
, may change, depending on the order in which they appear in the grid header and on the georeferencing method (center or corner) used for the grid. The ?llcorner
and ?llcenter
attributes differ only by cellsize/2
.
read.sgrd
and write.sgrd
import/export grids indirectly by creating temporary ASCII grid files (this explains why write.sgrd
has prec
and hdr.prec
arguments). Consider using sf::read_sf()
in package sf
instead, which is likely more efficient but may require coercion of your gridded data to/from an object supported by sf
.
The read.Rd.grid
and write.Rd.grid
functions use the load
and save
commands to store a grid. The variable name used is data
, which is either a numeric matrix or a list with components data
(the grid data matrix) and header
(the grid header information).
Alexander Brenning
sf::read_sf()
and sf::write_sf()
in package sf
, and readAsciiGrid
and writeAsciiGrid
in package maptools
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.