Handle hyperspectral cubes using raster package

Share:

Description

Methods to create and handle objects of class HyperSpecRaster

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## S4 method for signature 'character,numeric'
HyperSpecRaster(x, wavelength, fwhm = NULL, attributes = NULL, ...)

## S4 method for signature 'RasterLayer,numeric'
HyperSpecRaster(x, wavelength, fwhm = NULL, attributes = NULL)

## S4 method for signature 'RasterBrick,numeric'
HyperSpecRaster(x, wavelength, fwhm = NULL, attributes = NULL)

## S4 method for signature 'HyperSpecRaster'
HyperSpecRaster(x, wavelength)

## S4 method for signature 'Speclib,ANY'
brick(x, nrow, ncol, xmn, xmx, ymn, ymx, crs)

## S4 method for signature 'Speclib,ANY'
HyperSpecRaster(x, nrow, ncol, xmn, xmx, ymn, ymx, crs)

## S4 method for signature 'HyperSpecRaster,character'
writeStart(x, filename, ...)

## S4 method for signature 'HyperSpecRaster'
getValuesBlock(x, ...) 

## S4 method for signature 'RasterLayer,Speclib'
writeValues(x, v, start) 

## S4 method for signature 'RasterBrick,Speclib'
writeValues(x, v, start)

## S4 method for signature 'HyperSpecRaster,Speclib'
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

Author(s)

Lukas Lehnert

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
## 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)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.