## 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