rotatepolygon: rotatepolygon

Description Usage Arguments Value Examples

View source: R/treefelling.R

Description

Rotate the input polygon with a given angle and around a fix point.

Usage

1
rotatepolygon(p, angle, fixed)

Arguments

p

Polygon (POLYGON or sfc_POLYGON)

angle

Angle in degrees in the clockwise direction (numeric)

fixed

Fix point around which the polygon will be rotated (POINT)

Value

The polygon (sfc_POLYGON) rotated.

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
data(Paracou6_2016)
data(DTMParacou)
data(PlotSlope)
data(SpeciesCriteria)
data(MainTrails)
data(HarvestablePolygons)

inventory <- addtreedim(inventorycheckformat(Paracou6_2016),
volumeparameters = ForestZoneVolumeParametersTable)

inventory <- suppressMessages(treeselection(inventory, objective = 20, scenario ="manual",
 fuel = "2", diversification = TRUE, specieslax = FALSE, maintrails = MainTrails,
 objectivelax = TRUE, topography = DTMParacou, plotslope = PlotSlope,
 speciescriteria = SpeciesCriteria, harvestablepolygons = HarvestablePolygons,
 advancedloggingparameters = loggingparameters())$inventory)

inventory <- inventory %>%
     dplyr::filter(Selected == "1") %>%
     dplyr::select(idTree,DBH,TrunkHeight,TreeHeight,CrownHeight,
     CrownDiameter,Selected, Xutm, Yutm)
dat <- inventory[1,]

library(sf)
library(nngeo)
library(dplyr)
Foot <- st_point(c(dat$Xutm,dat$Yutm)) # tree foot point
Crown <- dat %>%
dplyr::mutate(xCrown = Xutm,
       yCrown = Yutm + TrunkHeight + CrownHeight/2,
       exCrown = CrownDiameter/2,
       eyCrown = CrownHeight/2) %>%
sf::st_as_sf(coords = c("xCrown", "yCrown")) # ellipse centroid coordinates
Crown <- st_ellipse(Crown, Crown$exCrown, Crown$eyCrown) # create the ellipse
Trunk <- with(dat, # and the trunk
              st_polygon(list(matrix(c(Xutm-(DBH/100)/2, Yutm,
                                      Xutm-(DBH/100)/2, Yutm + TrunkHeight,
                                      Xutm+(DBH/100)/2, Yutm + TrunkHeight,
                                      Xutm+(DBH/100)/2, Yutm,
                                      Xutm-(DBH/100)/2, Yutm) # the return
                                    ,ncol=2, byrow=TRUE))))
 RandomAngle <- as.numeric(sample(c(0:359.9), size = 1))

 TreeP <- st_difference(st_union(
 rotatepolygon(Trunk, angle = RandomAngle, fixed = Foot), # turned trunk
 rotatepolygon(Crown, angle = RandomAngle, fixed = Foot) # turned crown
 ))

library(ggplot2)
 ggplot() +
  geom_sf(data = st_union(Trunk, Crown), colour = "red") +
  geom_sf(data = TreeP, colour = "green")

thomasgaquiere/Maria documentation built on Dec. 24, 2021, 1:20 a.m.