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

Added rgl view in tree.detection

No related merge requests found
Showing with 98 additions and 41 deletions
+98 -41
This source diff could not be displayed because it is too large. You can view the blob instead.
No preview for this file type
...@@ -12,11 +12,11 @@ bibliography: "./bib/bibliography.bib" ...@@ -12,11 +12,11 @@ bibliography: "./bib/bibliography.bib"
knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(echo = TRUE)
# Set so that long lines in R will be wrapped: # 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(tidy.opts=list(width.cutoff=80),tidy=TRUE)
knitr::opts_chunk$set(fig.align = "center") knitr::opts_chunk$set(fig.align = "center")
# library(rgl) # for display of rgl in html
# knit_hooks$set(webgl = hook_webgl) knitr::knit_hooks$set(webgl = rgl::hook_webgl)
# rgl::setupKnitr() # output to html
library(lidR) html <- TRUE
``` ```
--- ---
...@@ -73,6 +73,20 @@ lidaRtRee::plotTreeInventory( ...@@ -73,6 +73,20 @@ lidaRtRee::plotTreeInventory(
species = as.character(treeinventorychablais3$s) 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. 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) ...@@ -85,14 +99,17 @@ ROI.range <- data.frame(round(apply(treeinventorychablais3[,c("x","y")],2,range)
### Airborne Laser Scanning data ### 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) # load data in package lidaRtRee (default)
data(laschablais3, package="lidaRtRee") 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 # directory for laz files
lazdir <- "/directory_of_las_files/" lazdir <- "/directory_of_las_files/"
# build catalog of files # build catalog of files
...@@ -111,10 +128,6 @@ laschablais3 <- lidR::clip_rectangle(cata, ...@@ -111,10 +128,6 @@ laschablais3 <- lidR::clip_rectangle(cata,
# save(laschablais3, file="laschablais3.rda", compress = "bzip2") # save(laschablais3, file="laschablais3.rda", compress = "bzip2")
``` ```
```{r displayALS, echo=FALSE}
laschablais3
```
## Data preparation ## Data preparation
### Digital Elevation Models ### Digital Elevation Models
...@@ -163,7 +176,7 @@ v.plotMask <- raster::rasterToPolygons(plotMask,function(x)(x==1),dissolve=T) ...@@ -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. 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 # display CHM
raster::plot(chm, col=gray(seq(0,1,1/255)), raster::plot(chm, col=gray(seq(0,1,1/255)),
main ="Canopy Height Model and tree positions") main ="Canopy Height Model and tree positions")
...@@ -293,7 +306,10 @@ lasn@data$seg.id <- raster::extract(segms[["segments.id"]], lasn@data[,1:2]) ...@@ -293,7 +306,10 @@ lasn@data$seg.id <- raster::extract(segms[["segments.id"]], lasn@data[,1:2])
# split las object by segment id # split las object by segment id
lasl <- split(lasn@data,lasn@data$seg.id) lasl <- split(lasn@data,lasn@data$seg.id)
# convert list of data.frames to list of las objects # 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 ### Metrics computation
...@@ -382,7 +398,8 @@ plot(afd) ...@@ -382,7 +398,8 @@ plot(afd)
The point cloud can be displayed colored by segment, with poles at the location of inventoried trees. 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 # 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 <- lasn@data[which(lasn@data$seg.id!=0), c("X", "Y", "Z", "seg.id")]
points.seg$X <- points.seg$X - 974300 points.seg$X <- points.seg$X - 974300
...@@ -680,7 +697,7 @@ raster::plot(chm.all, ...@@ -680,7 +697,7 @@ raster::plot(chm.all,
# display segments border # display segments border
sp::plot(v.trees, border = "white", add = T) sp::plot(v.trees, border = "white", add = T)
# add trees # 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. The following lines save outputs to files.
......
Supports Markdown
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