getValues, extract and related functions. You can assign new values with setValues and with replacement.
For an overview of the functions in the raster package have a look here: raster-package.## S3 method for class 'character':
raster(x, band=1, ...)
## S3 method for class 'RasterLayer':
raster(x)
## S3 method for class 'RasterStack':
raster(x, layer=0)
## S3 method for class 'RasterBrick':
raster(x, layer=0)
## S3 method for class 'missing':
raster(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, crs, ext)
## S3 method for class 'Extent':
raster(x, nrows=10, ncols=10, crs=NA)
## S3 method for class 'matrix':
raster(x, xmn=0, xmx=1, ymn=0, ymx=1, crs=NA, template=NULL)
## S3 method for class 'big.matrix':
raster(x, xmn=0, xmx=1, ymn=0, ymx=1, crs=NA, template=NULL)
## S3 method for class 'SpatialGrid':
raster(x, layer=1, values=TRUE)
## S3 method for class 'SpatialPixels':
raster(x, layer=1, values=TRUE)rgdal (see layer=0TRUE, the cell values of 'x' are copied to the RasterLayer object that is returnedNULL, arguments xmn, xmx, ymn, ymx and crs (unless template is an Extex represents a filename, the following additional variables are recognized:
sub: positive integer. Subdataset number for a file with subdatasets
native: logical. Default is FALSE except when package rgdal is missing. If TRUE, reading and writing of IDRISI, BIL, BSQ, BIP, SAGA, and Arc ASCII files is done with native (raster package) drivers, rather then via rgdal. 'raster' and netcdf format files are always read with native drivers.
RAT: logical. The default is TRUE, in which case a raster attribute table is created for files that have one
offset: integer. To indicate the number of header rows on non-standard ascii files (rarely useful; use with caution)
If x represents a NetCDF file, the following additional variable is recognized:
varname: character. The variable name, such as 'tasmax' or 'pr'. If not supplied and the file has multiple variables are a guess will be made (and reported)
lvar: integer > 0 (default=3). To select the 'level variable' (3rd dimension variable) to use, if the file has 4 dimensions (e.g. depth instead of time)
level: integer > 0 (default=1). To select the 'level' (4th dimension variable) to use, if the file has 4 dimensions, e.g. to create a RasterBrick of weather over time at a certain height.
To use NetCDF files the ncdf or the ncdf4 package needs to be available. If both are available, ncdf4 is used. Only the ncdf4 package can read the most recent version (4) of the netCDF format (as well as older versions), for windows it not available on CRAN but can be downloaded stack, brick# Create a RasterLayer object from a file
# N.B.: For your own files, omit the 'system.file' and 'package="raster"' bits
# these are just to get the path to files installed with the package
f <- system.file("external/test.grd", package="raster")
f
r <- raster(f)
logo <- raster(system.file("external/rlogo.grd", package="raster"))
#from scratch
r1 <- raster(nrows=108, ncols=21, xmn=0, xmx=10)
#from an Extent object
e <- extent(r)
r2 <- raster(e)
#from another Raster* object
r3 <- raster(r)
s <- stack(r, r, r)
r4 <- raster(s)
r5 <- raster(s, 3)Run the code above in your browser using DataLab