Learn R Programming

SDMTools (version 1.1-221)

read.asc: ESRI ASCII Raster File Import And Export

Description

read.asc and read.asc.gz reads ESRI ArcInfo ASCII raster file either uncompressed or compressed using gzip. write.asc and write.asc.gz writes an asc object to a ESRI ArcInfo ASCII raster file. The output can be either compressed or uncompressed. These functions are faster methods based on the adehabitat import.asc and export.asc. write.asc2 and write.asc2.gz are even faster implementations but have less error checking. image.asc and print.asc are generic methods associated with plotting & summarizing data of class 'asc'; they were modified from adehabitat package.

Usage

read.asc(file, gz = FALSE)
read.asc.gz(file)
write.asc(x, file, gz = FALSE)
write.asc.gz(x, file)
write.asc2(x, file, sigdig = 0, gz = FALSE)
write.asc2.gz(x, file, sigdig = 0)
"image"(x, col = gray((240:1)/256), clfac = NULL, ...)
"print"(x, ...)

Arguments

file
a character string representing the filename of the input/output file. The file extension should always be '.asc'.
gz
defines if the object is or should be compressed using gzip
x
an object of class 'asc' as defined in the adehabitat package
sigdig
is the number of significant digits to write when creating the ascii grid file
col
for maps of type "numeric", the colors to be used (see help(par))
clfac
for maps of type "factor", a character vector giving the names of colors for each level of the factor (see help(colasc))
...
additional arguments to be passed to the generic function image or print

Value

Returns a raster matrix of the class 'asc' defined in the adehabitat package with the following attributes:
xll
the x coordinate of the center of the lower left pixel of the map
yll
the y coordinate of the center of the lower left pixel of the map
cellsize
the size of a pixel on the studied map
type
either 'numeric' or 'factor'
levels
if type = 'factor', the levels of the factor.

Details

Implements a faster version of import.asc or export.asc from the adehabitat package. In addition, files can be read in and written to in gzip compressed format. Generic methods of print and image were modified from adehabitat. Further details of them are found there.

Examples

Run this code
#create a simple object of class 'asc'
tasc = as.asc(matrix(rep(x=1:10, times=1000),nr=100)); print(tasc)

#write out the raster grid file
write.asc(tasc,'t.raster.asc')
write.asc.gz(tasc,'t.raster.asc') #actually save file name as t.raster.asc.gz

#read in the raster grid files
tasc2 = read.asc('t.raster.asc')
tasc3 = read.asc.gz('t.raster.asc.gz')

#remove the temporary raster
unlink(c('t.raster.asc','t.raster.asc.gz'))

Run the code above in your browser using DataLab