get_traindata: Extracts training data from a raster stack using vector data...

Description Usage Arguments Value Author(s) Examples

View source: R/rs_classify.R

Description

Extracts training data from a raster stack and returns a dataframe containing for each pixel all values.

Usage

1
get_traindata(rasterStack = NULL, trainPlots = NULL)

Arguments

rasterStack

an object of rasterstack*. containing image data to make prediction on

trainPlots

an object of SpatialPolygonDataFrame*. providing the training areas

Value

data frame with either the raster stack of all trainingn data and/or the data frame containing the training data vlaues of given training areas

Author(s)

Chris Reudenbach

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
## Not run: 
##- required packages
require(uavRst)
setwd(tempdir())

##- get the tutorial data
utils::download.file("https://github.com/gisma/gismaData/raw/master/uavRst/data/tutorial_data.zip",
                     "tutorial_data.zip")
unzip("tutorial_data.zip",exdir =  ".")

##- get the files
imageTrainStack <- list()
geomTrainStack <- list()
imageTrainFiles <- Sys.glob("rgb??.tif")
geomTrainFiles <- Sys.glob("rgb??.shp")

##- create stacks from image and geometry files
imageTrainStack<-lapply(imageTrainFiles, FUN=raster::stack)
geomTrainStack  <- lapply(geomTrainFiles, FUN=raster::shapefile)
names(imageTrainStack[[1]])<-c("red","green","blue")
names(imageTrainStack[[2]])<-c("red","green","blue")
names(imageTrainStack[[3]])<-c("red","green","blue")

##' finally extraxt the training data to a data frame
trainDF <- get_traindata(rasterStack  = imageTrainStack,
                        trainPlots = geomTrainStack)

##- have a look at the training data
head(trainDF)

## End(Not run)

uavRst documentation built on Dec. 30, 2019, 5:06 p.m.