-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_center_of_las_files.R
47 lines (35 loc) · 1.35 KB
/
get_center_of_las_files.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
################################################################################
################################################################################
# GET CENTERS OF MULTIPLE LAS FILES
################################################################################
################################################################################
# load packages
library(lidR)
library(terra)
# set paths
in_path <- "C:/Users/Schindler/Downloads/in"
out_path <- "C:/Users/Schindler/Downloads/out.shp"
# get all file paths
files <- list.files(in_path, pattern = "[.]las", full.names = TRUE)
# prepare storage
x_all <- c()
y_all <- c()
name_all <- c()
for (file in files) {
# read las file
las <- readLAS(file)
# get name
name_curr <- strsplit(basename(file), "[.]")[[1]][1]
# get center x and y coordinate
x_curr <- mean(c(ext(las)$xmin, ext(las)$xmax))
y_curr <- mean(c(ext(las)$ymin, ext(las)$ymax))
# save in list
name_all <- c(name_all, name_curr)
x_all <- c(x_all, x_curr)
y_all <- c(y_all, y_curr)
}
# convert to vector
centers <- vect(matrix(c(x_all,y_all), ncol = 2), atts = data.frame("name" = name_all), crs = crs(las)@projargs)
# save vector as shp
writeVector(centers, out_path, overwrite = T)
################################################################################