-
Notifications
You must be signed in to change notification settings - Fork 1
/
segments_to_trees.R
53 lines (37 loc) · 1.49 KB
/
segments_to_trees.R
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
# # # Locate Trees
#----------------------------
#
# creates tree points out of the tree segmentation
# adds information to the trees from the ufcWaldorte Shapefile
library(rgdal)
library(mapview)
library(rgeos)
library(raster)
library(caret)
source("~/repositories/envimaR/R/getEnvi.R")
p <- getEnvi("~/natur40/cartography/")
# tree segmentation from stephan
seg <- sapply(list.files(p$uniwald_segmentierung_2018_09_10$here,
pattern = ".gpkg$", full.names = TRUE), readOGR)
seg <- do.call(rbind, seg)
# convert to centroid point
trees <- gCentroid(seg, byid = TRUE)
trees <- SpatialPointsDataFrame(trees, seg@data)
# forest parts data
forest <- readOGR(paste0(p$shapes$here, "uwcWaldorte.shp"))
forest_at_trees <- over(trees, forest)
trees@data <- cbind(trees@data, forest_at_trees)
# additional environmental information
aspect <- raster(paste0(p$raster$here, "lidar_aspect_01m.tif"))
trees@data$aspect <- extract(aspect, trees)
# # # INCLUDE HERE:
# tree species from lcc!
#----------------------------
# remove trees outside the forest
trees <- trees[!is.na(trees@data$FO_BASISTY),]
# thin out attribute table
trees <- trees[,c(1:13, 53, 133,183)]
colnames(trees@data) <- c("heightR", "chmHeight", "elev", "chmStd", "chmRatio", "slope",
"prCAN", "LAI", "FHD", "AGB", "area", "circularity", "calliper", "species", "age", "aspect")
# save as geoJSON
writeOGR(trees, paste0(p$sample_trees$here, "mof_trees.shp"), driver = "ESRI Shapefile", layer = "trees")