This R-script is used to create an “extractPlots.bat”-file that can be run in a command window. The script creates one row per plot in the bat-file and uses the command las2las from LasTools. You are required to provide a txt-file with the fields id, x, y.
[code lang=”r” wraplines=”TRUE”]
rm(list=ls())
#Example:
#Load your sample plots in this format with the three columns: id, x, y.
#samplePlots <- data.frame("id"=c(1001, 1002), "x"=c(520, 550), "y"=c(520, 580))
setwd("F:\\ALS")
samplePlots <- read.table("plots.txt", header=T, sep="\t")
names(samplePlots) <- c("id", "x", "y")
outpath <- "extractedPlotsLas"
# Radius of sample plots
radius <- 10
sink("extractPlots.bat")
# Create code to clip with exact coordinate, -inside_circle.
writeLines(paste0("las2las -i *.las -inside_circle ", samplePlots$x, " ", samplePlots$y, " ", radius, " -o ", outpath, "/", samplePlots$id, ".las -merged -v"))
sink()
[/code]