Tree extraction
tree_extraction.Rdcreates a data.frame with segment id, height and coordinates of maxima, surface and volume, computed from three images:
initial, local maxima and segmented, obtained with tree_segmentation. The 2D polygon associated to each crown
can be added as a WKT field
Arguments
- r_dem_nl
SpatRaster object. Output raster of
tree_segmentation. Otherwise a raster of canopy height model, preferably filtered to avoid effect of holes on volume and surface computation can be provided. In this case arguments `r_maxi`, `r_dem_w` have to be provided- r_maxi
SpatRaster object. raster with positive values at local maxima (in case `r_dem_nl` does not contain it)
- r_dem_w
SpatRaster object. segmented raster (in case `r_dem_nl` does not contain it)
- r_mask
SpatRaster object. only segments which maxima are inside the mask are extracted. Values should be NA outside the mask, 1 inside.
- crown
boolean. Should the 2D crown geometry be added in wkt format to the output data.frame ?
Value
A sf collection of POINTs with 7 fields: tree id, local maximum stats
(height, dominance radius), segment stats (surface and volume), coordinates
(x and y). In case argument `crown` is `TRUE`, a `crown` field
containing the WKT geometry of the 2D crown is also present. Coordinates are
written with one decimal to the right of the order of magnitude of
the SpatRaster resolution (e.g. if resolution is 1/3 then 2 decimals are written).
Examples
data(chm_chablais3)
chm_chablais3 <- terra::rast(chm_chablais3)
# tree segmentation
segments <- tree_segmentation(chm_chablais3)
# tree extraction
trees <- tree_extraction(segments, crown = TRUE)
# create crown polygons from WKT field
trees_crowns <- sf::st_as_sf(sf::st_drop_geometry(trees), wkt = "crown")
# summary of trees without wkt field
summary(trees[, -which(names(trees) == "crown")])
#> id x y h
#> Min. : 1.00 Min. :974331 Min. :6581624 Min. : 6.25
#> 1st Qu.: 37.75 1st Qu.:974346 1st Qu.:6581645 1st Qu.:15.57
#> Median : 74.50 Median :974362 Median :6581662 Median :19.77
#> Mean : 74.85 Mean :974364 Mean :6581662 Mean :19.23
#> 3rd Qu.:112.25 3rd Qu.:974379 3rd Qu.:6581682 3rd Qu.:23.32
#> Max. :150.00 Max. :974403 Max. :6581697 Max. :29.89
#> dom_radius s v geometry
#> Min. :1.000 Min. : 1.50 Min. : 9.158 POINT :136
#> 1st Qu.:2.000 1st Qu.:18.75 1st Qu.: 225.905 epsg:2154 : 0
#> Median :3.000 Median :30.25 Median : 381.076 +proj=lcc ...: 0
#> Mean :3.496 Mean :31.43 Mean : 474.763
#> 3rd Qu.:5.500 3rd Qu.:42.25 3rd Qu.: 660.259
#> Max. :6.000 Max. :95.25 Max. :1869.152
# plot initial image
terra::plot(chm_chablais3, main = "CHM and extracted trees")
# add treetop positions
plot(trees["h"], add = TRUE, cex = trees$h/20, col = "black")
# add crowns
plot(sf::st_geometry(trees_crowns), add = TRUE, border = "black", col = NA)
# plot segments
terra::plot(segments$segments_id, main = "Segments")
# add crowns
plot(sf::st_geometry(trees_crowns), add = TRUE, border = "black", col = NA)