-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlidr_mosaic.r
37 lines (31 loc) · 1.11 KB
/
lidr_mosaic.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
# conda create -n lidr -c conda-forge r-lidr r-future r-rgdal r-codetools r-optparse
library(lidR)
library(terra)
library(optparse)
library(future)
option_list = list(
make_option(c("-i", "--inDir"), type="character", default=NULL,
help="Directory with input las files"),
make_option(c("-o", "--outFile"), type="character", default=NULL,
help="Output mosaic TIF file"),
make_option(c("-p", "--pixelSize"), type="numeric", default=0.1,
help="Pixel size (m) for output TIF file"))
opt_parser <- OptionParser(option_list=option_list)
opt <- parse_args(opt_parser)
if (is.null(opt$inDir)){
print_help(opt_parser)
stop("Must supply inDir")}
if (is.null(opt$outFile)){
print_help(opt_parser)
stop("Must supply outFile")}
inDir <- opt$inDir
outFile <- opt$outFile
pixelSize <- opt$pixelSize
RGBZ <- function(r, g, b, z) {
maxZ <- which.max(z)
bands = list(R = r[maxZ], G = g[maxZ], B = b[maxZ])
return(bands)}
points <- readLAScatalog(inDir)
plan(multisession, workers=8L) # 8 cores
RGB <- grid_metrics(points, ~RGBZ(R, G, B, Z), res=pixelSize)
writeRaster(RGB, outFile)