-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_aba.qmd
127 lines (90 loc) · 3.88 KB
/
03_aba.qmd
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
---
title: "Area-based metrics"
---
```{r, echo = FALSE, warnings = FALSE}
library(rgl)
r3dDefaults <- rgl::r3dDefaults
m <- structure(c(0.921, -0.146, 0.362, 0, 0.386, 0.482, -0.787, 0,
-0.06, 0.864, 0.5, 0, 0, 0, 0, 1), .Dim = c(4L, 4L))
r3dDefaults$FOV <- 50
r3dDefaults$userMatrix <- m
r3dDefaults$zoom <- 0.75
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
fig.align = "center")
rgl::setupKnitr(autoprint = TRUE)
options(lidR.progress = FALSE)
```
## Relevant Resources
[Code](https://github.com/tgoodbody/lidRtutorial/blob/main/code/tutorials/03_aba.R)
- [lidRbook metrics section](https://r-lidar.github.io/lidRbook/modeling-aba.html)
- [lidRbook modelling section](https://r-lidar.github.io/lidRbook/modeling-aba.html)
## Overview
This code demonstrates an area-based approach for LiDAR data. Basic usage involves computing mean and max height of points within 10x10 m pixels and visualizing the results. The code shows how to compute multiple metrics simultaneously and use predefined metric sets. Advanced usage introduces user-defined metrics for more specialized calculations.
## Environment
```{r clear warnings, warnings = FALSE, message=FALSE}
# Clear environment
rm(list = ls(globalenv()))
# Load packages
library(lidR)
library(sf)
```
## Basic Usage
We'll cover the basic usage of the `lidR` package to compute metrics from LiDAR data.
```{r load_lidar_data}
# Load LiDAR data, excluding withheld flag points
las <- readLAS(files = "data/MixedEucaNat_normalized.laz", select = "*", filter = "-set_withheld_flag 0")
```
```{r mean_height_pixel_metrics}
# Compute the mean height of points within 10x10 m pixels
hmean <- pixel_metrics(las = las, func = ~mean(Z), res = 10)
hmean
plot(hmean, col = height.colors(50))
```
```{r max_height_pixel_metrics}
# Compute the max height of points within 10x10 m pixels
hmax <- pixel_metrics(las = las, func = ~max(Z), res = 10)
hmax
plot(hmax, col = height.colors(50))
```
```{r multiple_metrics_pixel_metrics}
# Compute several metrics at once using a list
metrics <- pixel_metrics(las = las, func = ~list(hmax = max(Z), hmean = mean(Z)), res = 10)
metrics
plot(metrics, col = height.colors(50))
```
```{r predefined_metrics_pixel_metrics}
# Simplify computing metrics with predefined sets of metrics
metrics <- pixel_metrics(las = las, func = .stdmetrics_z, res = 10)
metrics
plot(metrics, col = height.colors(50))
# Plot a specific metric from the predefined set
plot(metrics, "zsd", col = height.colors(50))
```
## Advanced Usage with User-Defined Metrics
::: callout-tip
## 3rd party metric packages
`lidR` provides flexibility for users to define custom metrics. Check out 3rd party packages like [`lidRmetrics`](https://github.com/ptompalski/lidRmetrics) for suites of metrics.
:::
```{r user_defined_metric_pixel_metrics}
# Generate a user-defined function to compute weighted mean
f <- function(x, weight) { sum(x*weight)/sum(weight) }
# Compute grid metrics for the user-defined function
X <- pixel_metrics(las = las, func = ~f(Z, Intensity), res = 10)
# Visualize the output
plot(X, col = height.colors(50))
```
## Exercises and Questions
Using:
``` r
las <- readLAS("data/MixedEucaNat_normalized.laz", select = "*", filter = "-set_withheld_flag 0")
```
#### E1.
Assuming that biomass is estimated using the equation `B = 0.5 * mean Z + 0.9 * 90th percentile of Z` applied on first returns only, map the biomass.
#### E2.
Map the density of ground returns at a 5 m resolution with `pixel_metrics(filter = ~Classification == LASGROUND)`.
#### E3.
Map pixels that are flat (planar) using `stdshapemetrics`. These could indicate potential roads.
## Conclusion
In this tutorial, we covered basic usage of the `lidR` package for computing mean and max heights within grid cells and using predefined sets of metrics. Additionally, we explored the advanced usage with the ability to define user-specific metrics for grid computation.