Commit 696c95b5 authored by Monnet Jean-Matthieu's avatar Monnet Jean-Matthieu
Browse files

Added rgl view in tree.detection

parent 5d7acaed
This diff is collapsed.
......@@ -12,11 +12,11 @@ bibliography: "./bib/bibliography.bib"
knitr::opts_chunk$set(echo = TRUE)
# Set so that long lines in R will be wrapped:
knitr::opts_chunk$set(tidy.opts=list(width.cutoff=80),tidy=TRUE)
knitr::opts_chunk$set(fig.align = "center")
# library(rgl)
# knit_hooks$set(webgl = hook_webgl)
# rgl::setupKnitr()
library(lidR)
knitr::opts_chunk$set(fig.align = "center")
# for display of rgl in html
knitr::knit_hooks$set(webgl = rgl::hook_webgl)
# output to html
html <- TRUE
```
---
......@@ -73,6 +73,20 @@ lidaRtRee::plotTreeInventory(
species = as.character(treeinventorychablais3$s)
)
```
The `ggplot2` package also provides nice outputs.
```{r ggplot2, include = TRUE, out.width = '50%', fig.dim=c(5.5, 5.5)}
# use table of species of package lidaRtRee to always use the same color for a given species
plot.species <- lidaRtRee::speciesColor()[levels(treeinventorychablais3$s), "col"]
library(ggplot2)
ggplot(treeinventorychablais3, aes(x = x, y = y, group = s)) +
geom_point(aes(color = s, size = d)) +
coord_sf(datum = 2154) +
scale_color_manual(values = plot.species) +
scale_radius(name="Diameter") +
geom_text(aes(label=n, size=20), hjust=0, vjust=1) +
labs(color = "Species") # titre de la légende
```
We define the region of interest (ROI) to crop ALS data to corresponding extent before further processing. ROI is set on the extent of tree inventory, plus a 10 meter buffer.
......@@ -85,14 +99,17 @@ ROI.range <- data.frame(round(apply(treeinventorychablais3[,c("x","y")],2,range)
### Airborne Laser Scanning data
ALS data is loaded with functions of package `lidR`. First a catalog of files containing ALS data is built. Then points located inside our ROI are loaded.
In this tutorial, ALS data available in the `lidaRtRee`` package is used.
```{r loadALS, include = FALSE}
```{r loadALS, include = TRUE, message = FALSE}
# load data in package lidaRtRee (default)
data(laschablais3, package="lidaRtRee")
laschablais3
```
```{r prepareALS, eval=FALSE}
Otherwise, ALS data is loaded with functions of package `lidR`. First a catalog of files containing ALS data is built. Then points located inside our ROI are loaded.
```{r prepareALS, eval=FALSE, message = FALSE}
# directory for laz files
lazdir <- "/directory_of_las_files/"
# build catalog of files
......@@ -111,10 +128,6 @@ laschablais3 <- lidR::clip_rectangle(cata,
# save(laschablais3, file="laschablais3.rda", compress = "bzip2")
```
```{r displayALS, echo=FALSE}
laschablais3
```
## Data preparation
### Digital Elevation Models
......@@ -163,7 +176,7 @@ v.plotMask <- raster::rasterToPolygons(plotMask,function(x)(x==1),dissolve=T)
```
Displaying inventoried trees on the CHM shows a pretty good correspondance of crowns visible in the CHM with trunk locations and sizes.
```{r plotPlot, include = TRUE, out.width = '60%', fig.dim=c(6.5, 4.5), warnings=FALSE}
```{r plotPlot, include = TRUE, out.width = '70%', fig.dim=c(6.5, 4.5), warnings=FALSE}
# display CHM
raster::plot(chm, col=gray(seq(0,1,1/255)),
main ="Canopy Height Model and tree positions")
......@@ -293,7 +306,10 @@ lasn@data$seg.id <- raster::extract(segms[["segments.id"]], lasn@data[,1:2])
# split las object by segment id
lasl <- split(lasn@data,lasn@data$seg.id)
# convert list of data.frames to list of las objects
lasl <- lapply(lasl, function(x){LAS(x,lasn@header)})
lasl <- lapply(lasl, function(x){lidR::LAS(x,lasn@header)})
# set coordinate system
dummy <- sp::CRS(SRS_string = "EPSG:2154")
for (i in 1:length(lasl)) {sp::proj4string(lasl[[i]]) <- dummy}
```
### Metrics computation
......@@ -382,7 +398,8 @@ plot(afd)
The point cloud can be displayed colored by segment, with poles at the location of inventoried trees.
```{r displayPointCloud, eval=FALSE, rgl=TRUE, dev='png'}
```{r displayPointCloud, include=TRUE, eval=html, webgl=TRUE, fig.width=6, fig.height=6, warning=FALSE}
rgl::par3d(mouseMode = "trackball") # parameters for interaction with mouse
# select segment points and offset them to avoid truncated coordinates in 3d plot
points.seg <- lasn@data[which(lasn@data$seg.id!=0), c("X", "Y", "Z", "seg.id")]
points.seg$X <- points.seg$X - 974300
......@@ -680,7 +697,7 @@ raster::plot(chm.all,
# display segments border
sp::plot(v.trees, border = "white", add = T)
# add trees
plot(trees, cex = trees$h/40, add = TRUE)
sp::plot(trees, cex = trees$h/40, add = TRUE)
```
The following lines save outputs to files.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment