raster-package
.raster(x, ...)
raster(x, values=FALSE, band=1, ...)
x
character. Name of raster file
values
logical. If TRUE
, RasterLayer values are read into memory with readAll
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, and ArcAscii files is done with native (raster package) drivers, rather then via rgdal. 'raster', RSAGA, and netcdf format files are always read with native drivers.
}
More additional arguments, that are only meaningful with netCDF files (CF convention):
xvar
character. The x variable (e.g. 'longitude' or 'x')
yvar
character. The y variable (e.g. 'latitude' or 'y')
varname
character. The variable name (e.g. 'altitide' or 'precipitation')
band
integer > 0. The 'band' (layer) number of the file. E.g., the 'time' variable (if there are any) (default=NA)
}
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.
To read netCDF files, the RNetCDF package needs to have been installed. For netCDF files, the function will try to guess values for xar
and yvar
if they are not supplied. netCDF data can only be read if the data are stored in 2 (x and y) or 3 (x, y, and time) dimensions.
2) Create a RasterLayer object from scratch
raster(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, crs="+proj=longlat +datum=WGS84")
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)
}
(item x
is 'missing' in this case)
3) Create a RasterLayer object from an Extent 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 RasterLayer object. This copies the parameters of a RasterLayer object to a new RasterLayer,
but does not copy the filename nor the data associated with the original Raster object.
raster(x, filename="", values=NULL)
x
a Raster* object
filename
new filename for new RasterLayer
values
If not NULL
it is used to set values to new object. Either pass a vector of length == ncells(x), or a single number
}
5) Create a RasterLayer object from a RasterStack or RasterBrick object.
raster(x, index=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 SpatialPixels* or SpatialGrid* object.
raster(x, index=0)
x
a RasterStack, 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
a 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
}getValues), xyValues
and related functions.
You can assign new values with setValues
and with replacement
.stack, getValues
#from file
r <- raster(system.file("external/test.grd", package="raster"))
logo <- raster(system.file("external/rlogo.grd", package="raster"), values=TRUE)
#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)
r3 <- raster(s)
Run the code above in your browser using DataLab