### 4.3.1 Point shapefile with values as an attribute. These shapefiles must have at least one field that identifies the continuous values (in the code below, the field is called "amount"). ### Create objects to receive the training and validation data. train.full <- NULL valid.full <- NULL ### Read in the raster image. Replace image with the name of the image. img <- stack("image") ### This process extracts the training data within the shapefile. ### Read in the shapefile. Replace the shapefile argument with the full name of the training shapefile. train.locations <- readShapePoints("shapefile") ### Extract values from the image for the shapefile area. preidctors.train <- extract(img, train.locations, df=TRUE) ### Add continuous amount to the "amount" column in the data frame directly from the shapefile. train.full <- cbind(train.predictors, "amount" = train.locations$amount) ### Omit the following steps if validation data will be randomly extracted from the full training dataset. ### Read in the shapefile. Replace the shapefile argument with the full name of the validation shapefile. valid.locations <- readShapePoints("shapefile") valid.predictors <- extract(img, valid.locations, df=TRUE) valid.full <- cbind(valid.predictors, "amount" = valid.locations$amount) ### 4.3.2 Csv files with location and value data. The csv file should contain three columns. The following code assumes these are labeled x, y, and amount, and that the files are named "train.csv" and "valid.csv", respectively. ### Read in training text file. train.locations <- read.csv("train.csv") ### Read in validation text file. valid.locations <- read.csv("valid.csv") ### Read in the raster image. Replace image with the name of the image. img <- stack ("image") ### Identify the locational information. coordinates(train.locations) <- c("x", "y") ### Extract predictor data from the image. train.predictors <- raster::extract(img, train.locations) ### Extract the training values. amount <- train.locations$amount ### Combine the response and predictor data. train.full <- cbind(amount, train.predictors) ### Repeat the steps for the validation data. coordinates(valid.locations) <- c("x", "y") valid.predictors <- raster::extract(img, valid.locations) amount <- valid.locations$amount valid.full <- as.data.frame(cbind(amount, valid.predictors)) ### 4.3.3 Csv files with data already extracted and assembled. Follow the instructions for importing classification data in this format. The response variable should be named "amount". ### 4.3.4 Random extraction of validation data from imported training data. Follow the instructions for random extraction of accuracy assessment data from imported classification training data.