lasR Etc.
Jacob Strunk
April 11, 2017
Why NOT Lidar In R?
• Slow
• Inefficient (memory footprint etc.)
• Annoying / casual syntax
• Weird OOP support (3+ versions)
• Python, Java, C# have more capabilities
• You WILL run into barriers if you use it long enough
• You will likely come to hate (and love) R
Why Lidar In R?
• Great for exploratory analyses
• Easy, fun
• Lots of users
• Large user support community – e.g. help forums
• Simple to append to language
• Lots of support for statistics
• Simple programming paradigm (high level)
• Easy to do research and visualization
Presentation
• 2 Sections
1. R, Rstudio, Git, GitHub toolchain
2. lidR and lasR – working with lidar in R
R Packages
“… the fundamental unit of shareable code is the package. A package
bundles together code, data, documentation, and tests, and is easy to
share with others.”
http://r-pkgs.had.co.nz/intro.html
Why build packages?
• Portable
• Testable
• Extensible
• Facilitates collaboration
• Reduces redundancy
• Encourages more work in your topic of interest
• People are freed up to do other cool things (and hopefully create packages)
• Once you start (using RStudio) you will never go back…
Functional programming
• R packages very suited to functional programming:
hello <- function() {
print("Hello, world!")
}
• Some of us may be more used to this style:
…
#print hello world
print("Hello, world!")
…
R Packages
• Rstudio – So easy
• Not in Rstudio – tedious
• Rstudio has a really convenient toolchain that eliminates most of the
frustration of package building
Rstudio, Very Convenient IDE for R
• Package build / test support
• R syntax highlighting, suggesting and code execution
• ROxygen syntax highlighting, suggesting
• R Manual Page previewing
• RCPP support
• Git support
• RShiny support
•…
Step 1
• Get / install all of the tools – default settings are fine
•
•
•
•
•
•
R
Rtools
Rstudio
Miktex
GIT
Sign up for GIT account
Build an R package
4
1
2
3
Build Package
• New package pre-populated with example function – just build it
Git
Git commit (first time)
• Shift-click to select all items
• commit
Git commit (add function)
• Shift-click to select all items
• commit
Git Push (to GitHub)
• Will need to log in first time
Git History
• Awesome
• See old versions of
scripts before you
screwed them up…
Git branch history
• Experiment
• Merge in experiment
Roxygen
• maintain one set of code
• No need to manage help files separately from code…
Roxygen: Auto-populate Help Files (Awesome)
Just paste template into header of code and the appropriate files are auto-created
lidR and lasR
Working with lidar in R
LidR
• Read/write las/laz files
• Read in a dem files
• Process point data -> raster
• Process point data -> sample plots
• Visualize data
• … other stuff
• Iterate across files in a project
lidR limitations
1) Cannot tile on the fly – lidar data become processing tiles
2) Assumes footprints of DEM and LIDAR are the same
3) Cannot easily call external .exe file
lidR
• Lots of functionality
• A few serious limitations
lidR::plot()
• plot(dat1,bg="white")
lidR::lasground()
> lasground(dat1,CellSize = 6,MaxDist = 9,InitDist = 0.1)
> plot(dat1, color = "Classification",bg="white")
lidR::lasground()
• Slow, but seems to work fine
lidR::lasground() – Stereo DSM points
lidR::catalog & lidR::catalog_apply
ct1=catalog(getwd())
f1=function(x){require(lidR);grid_metrics(readLAS(x), .stdmetrics)}
res1=catalog_apply(ct1,f1, mc.cores = 7, combine = "rbind", varlist =
"ct1")
lasR
• Very beta
• Very little functionality
• Re-tile on the fly!!
• Work with fusion exes
lasR
lasR
• Read in las data
• Read in DEM files
• Tile lidar project area on the fly
• Create lidar processing project
• Iterate across processing tiles (not lidar files)
• Clip plot from lidar processing project
lasR::scan_dtm
• Bounding boxes…
lasR::scan_las
• NAIP 2015 DSM tiles
lasR::lasR_project
• Create processing tiles
• Intersect with lidar files
• Intersect with dtm files
• Subset area
lasR::gridmetrics
• Create custom metrics in R
• Send files to FUSION using system calls
lasR::forthcoming
• Clip plots using projects (deals with edges)
• Metrics for plots
• Other lidar & inventory steps
Thank you
© Copyright 2026 Paperzz