raster-package
.raster(x, ...)
raster(x, band=1, ...)
x
character. Name of raster file
band
integer. Band number in case of a file of multiple bands, default = 1
...
additional arguments.
}
Additional arguments:
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.
offset
Integer. To indicated the number of header rows on non-standard ascii files (rarely useful; use with caution)
}
For netCDF files (CF convention):
varname
character. The variable name (e.g. 'altitude' or 'precipitation'. If not supplied and the file has multiple variables are a guess will be made (and reported))
band
integer > 0. The 'band' (layer) number of the file. E.g., the 'time' variable (if there are any) (default=NA)
}
To read netCDF files, the ncdf
package needs to be available.
If x
is a character value, it should be a filename of a file that the raster package can read. Supported file types are the 'native' raster package format and those that can be read via rgdal. See readGDAL
help for supported file types.
2) Create a RasterLayer object from scratch
raster(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, crs, ext)
nrows
number of rows
ncols
number of columns
xmn
minimum x coordinate (left border)
xmx
maximum x coordinate (right border)
ymn
minimum y coordinate (bottom border)
ymx
maximum y coordinate (top border)
crs
Character or object of class CRS. PROJ4 type description of a Coordinate Reference System (map projection). If this argument is missing, and the x coordinates are withing -360 .. 360 and the y coordinates are within -90 .. 90, "+proj=longlat +datum=WGS84" is used.
ext
object of class Extent. If present, the arguments xmn, xmx, ymn and ynx are ignored
}
(item x
is 'missing' in this case)
3) Create a RasterLayer object from an Extent-class
object
raster(x, nrows=10, ncols=10, crs=NA)
x
Extent object
nrows
number of rows
ncols
number of columns
crs
PROJ4 type description of a map projection
}
4) Create a RasterLayer object from a Raster* object.
This copies the parameters of a Raster* object to a new RasterLayer,
but does not copy the filename nor the cell values associated with the original Raster* object.
raster(x)
x
a Raster* object
}
5) Create a RasterLayer object from a RasterStack or RasterBrick object.
raster(x, layer=0)
x
a RasterStack, SpatialPixels* or SpatialGrid* object
layer
Integer. The layer from which to copy values to the new RasterLayer, if layer>0.
}
6) Create a RasterLayer object from a RasterStack, RasterBrick, SpatialPixels* or SpatialGrid* object.
raster(x, layer=0)
x
RasterStack, RasterBrick, SpatialPixels* or SpatialGrid* object
layer
Integer. the layer from which to copy values to the new RasterLayer, if layer>0
}
7) Create a RasterLayer object from a matrix.
The default extent is set to be between 0 and 1 in the x and y direction but can be changed at creation of the RasterLayer object or later. You can also provide a projection.
function(x, xmn=0, xmx=1, ymn=0, ymx=1, crs=NA)
x
matrix
xmn
minimum x coordinate (left border)
xmx
maximum x coordinate (right border)
ymn
minimum y coordinate (bottom border)
ymx
maximum y coordinate (top border)
crs
PROJ4 type description of a map projection (optional)
}
8) Create a RasterLayer object from an 'image' object (a list with vectors x and y and matrix z), or from an asc, kasc, or kde object
raster(img, crs)
x
RasterStack, SpatialPixels* or SpatialGrid* object
crs
PROJ4 type description of a map projection (optional)
}getValues, extract
and related functions.
You can assign new values with setValues
and with replacement
.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