stemMappingExtension: Extend stem mapping to a target area and shape.

View source: R/stemMappingExtension.R

stemMappingExtensionR Documentation

Extend stem mapping to a target area and shape.

Description

The function cuts a circle stem map into a largest hexagon in circle and extends this hexagon to a target area and shape. This is a generic function.

Usage

stemMappingExtension(
  objectID,
  bearing,
  distance,
  plotRadius = 11.28,
  targetArea = 1,
  targetShape = "square",
  randomRotate = FALSE,
  randomSeed = as.numeric(NA)
)

Arguments

objectID

character, A object's ID, e.g., a tree's ID.

bearing

numeric, Azimuth of a object from the north. It should be between 0 to 360.

distance

numeric, Distance between a object and the centre of the circle.

plotRadius

numeric, Radius of the plot circle. If missing, 11.28 will be used, as it presents the radius of a circle for big trees (i.e., trees DBH >= 9).

targetArea

numeric, Defines the area you may want to extend. The unit of this input is ha. Default is 1 ha.

targetShape

character, Defines the shape of the target area. It currently supports circle and square. The default is square.

randomRotate

logical, Defines whether need to random rotate the hexagon when merge into a targetArea. The default is FALSE.

randomSeed

numeric, Defines random seed for the random number generator. This arguement is called when randomRotate is TRUE. If missing, NA is used, suggesting no random seed is set.

Value

A table contains the x and y for all the objects in the extended area.

Author(s)

Yong Luo

Examples

## Not run: 
## randomly generate some trees
library(data.table)
smallplottrees <- data.table(expand.grid(angle = seq(0, 360, 1),
                              distance = seq(0.1, 5.6, 0.1)))
smallplottrees[, tree_id := 1:nrow(smallplottrees)]
## extend it to 1 ha
treelist_smallplot <- stemMappingExtension(objectID = smallplottrees$tree_id,
                                           bearing = smallplottrees$angle,
                                           distance = smallplottrees$distance,
                                           plotRadius = 5.64,
                                           randomRotate = TRUE)
smallplottrees[tree_id %in% treelist_smallplot$objectID,
              inHexigon := "Yes"]
smallplottrees[is.na(inHexigon),
              inHexigon := "No"]
smallplottrees[,':='(x = sin(angle*pi/180)*distance,
                     y = cos(angle*pi/180)*distance)]
library(ggplot2)
trees_inplot <- ggplot(data = smallplottrees, aes(x = x, y = y))+
 geom_point(aes(col = inHexigon))
trees_all <- ggplot(data = treelist_smallplot, aes(x = x, y = y))+
 geom_point(aes(col = hexagonID))



bigplottrees <- data.table(tree_id = 1:20,
                           angle = runif(20, min = 0, max = 360),
                           distance = runif(20, min = 0, max = 11.28))
## extend it to 1 ha
treelist_bigplot <- stemMappingExtension(objectID = bigplottrees$tree_id,
                                         bearing = bigplottrees$angle,
                                         distance = bigplottrees$distance,
                                         plotRadius = 11.28)
treelist_smallplot[, source := "smallplot"]
treelist_bigplot[, source := "bigplot"]


alltreelist <- rbind(treelist_bigplot, treelist_smallplot)


alltreeplot <- ggplot(data = alltreelist, aes(x, y))+
 geom_point(aes(col = factor(source)))+
 geom_point(data = alltreelist[hexagonID == 0,],
 aes(x, y), col = "red")


## End(Not run)


bcgov/FAIBBase documentation built on June 19, 2024, 11:57 p.m.