Learn R Programming

hsdar (version 0.5.1)

HyperSpecRaster: Handle hyperspectral cubes using raster package

Description

Methods to create and handle objects of class HyperSpecRaster

Usage

"HyperSpecRaster"(x, wavelength, fwhm = NULL, attributes = NULL, ...)
"HyperSpecRaster"(x, wavelength, fwhm = NULL, attributes = NULL)
"HyperSpecRaster"(x, wavelength, fwhm = NULL, attributes = NULL)
"HyperSpecRaster"(x, wavelength)
"brick"(x, nrow, ncol, xmn, xmx, ymn, ymx, crs)
"HyperSpecRaster"(x, nrow, ncol, xmn, xmx, ymn, ymx, crs)
"writeStart"(x, filename, ...)
"getValuesBlock"(x, ...)
"writeValues"(x, v, start)
"writeValues"(x, v, start)
"writeValues"(x, v, start)

Arguments

x
Raster* object
wavelength
Vector containing wavelength for each band
fwhm
Optional vector containing full-width-half-max values. If length == 1 the same value is assumed for each band. Note that function does not check the integrity of the values
attributes
Optional data.frame containing attributes data
nrow
Optional. Number of rows in HyperspecRaster. If omitted, function will try to get the information from the attributes in Speclib (attr(x, "rastermeta"))
ncol
Optional. Number of colums in HyperspecRaster. See nrow above.
xmn
Optional. Minimum coordiante in x-dimension. See nrow above.
xmx
Optional. Maximum coordiante in x-dimension. See nrow above.
ymn
Optional. Minimum coordiante in y-dimension. See nrow above.
ymx
Optional. Maximum coordiante in y-dimension. See nrow above.
crs
Optional. Object of class 'CRS' giving the coordinate system for HyperspecRaster. See nrow above.
...
Additional arguments as for brick
filename
Name of file to create
v
Speclib or matrix of values
start
Integer. Row number (counting starts at 1) from where to start writing v

Value

HyperSpecRaster or RasterBrick

Examples

Run this code
## Not run: 
# ## Create raster file using PROSAIL
# ## Run PROSAIL
# parameter <- data.frame(N = c(rep.int(seq(0.5, 1.4, 0.1), 6)),
#                         LAI = c(rep.int(0.5, 10), rep.int(1, 10), 
#                                 rep.int(1.5, 10), rep.int(2, 10), 
#                                 rep.int(2.5, 10), rep.int(3, 10)))
# spectra <- PROSAIL(parameterList = parameter)
# 
# ## Create SpatialPixelsDataFrame and fill data with spectra from PROSAIL
# rows <- round(nspectra(spectra)/10, 0)
# cols <- ceiling(nspectra(spectra)/rows)
# grd <- SpatialGrid(GridTopology(cellcentre.offset = c(1,1,1), 
#                                 cellsize = c(1,1,1), 
#                                 cells.dim = c(cols, rows, 1)))
# x <- SpatialPixelsDataFrame(grd, data = as.data.frame(spectra(spectra)))
# 
# ## Write data to example file (example_in.tif) in workingdirectory
# writeGDAL(x, fname = "example_in.tif", drivername = "GTiff")
# 
# ## Examples for HyperSpecRaster using file example_in.tif
# ## Example 1:
# ## smoothing spectra
# infile <- "example_in.tif"
# outfile <- "example_result_1.tif"
# wavelength <- spectra$wavelength
# 
# ra <- HyperSpecRaster(infile, wavelength)
# tr <- blockSize(ra)
# 
# res <- writeStart(ra, outfile, overwrite = TRUE)
# for (i in 1:tr$n) 
# {
#   v <- getValuesBlock(ra, row=tr$row[i], nrows=tr$nrows[i])
#   v <- smoothSpeclib(v, method="sgolay", n=25)
#   res <- writeValues(res, v, tr$row[i])
# }
# res <- writeStop(res)
# 
# ## Example 2:
# ## masking spectra and calculating vegetation indices
# outfile <- "example_result_2.tif" 
# n_veg <- as.numeric(length(vegindex()))
# res <- writeStart(ra, outfile, overwrite = TRUE, nl = n_veg)
# for (i in 1:tr$n) 
# {
#   v <- getValuesBlock(ra, row=tr$row[i], nrows=tr$nrows[i])
#   mask(v) <- c(1350, 1450)
#   v <- as.matrix(vegindex(v, index=vegindex()))
#   res <- writeValues(res, v, tr$row[i])
# }
# res <- writeStop(res)
# ## End(Not run)

Run the code above in your browser using DataLab