PC2Products API Reference
Tools API
rpy_las_info
rpy_las_info(in_las_folder, processes=0, **kwargs)
Report information about the LAS files of a folder.
It reports
LAS version CRS EPSG Units Extent Area Point count Point density Number of files Normalized / not normalized Ground elevation statistics
It reads only the files' headers and one file, so it starts no R workers and processes is unused; it is kept as every tool takes it.
rpy_find_cellsize
rpy_find_cellsize(in_las_folder, processes=0, **kwargs)
Print the raster cell size suited to the LiDAR data's point density. It reads only the files' headers, so it starts no R workers and processes is unused; it is kept as every tool takes it.
rpy_gnd_csf
rpy_gnd_csf(in_las_folder, out_folder, slope: bool = False, class_threshold=0.3, cloth_resolution=1.0, rigidness=1, processes=1, tiling='auto', skip_existing: bool = False, **kwargs)
Classify the ground points of LiDAR data with the Cloth Simulation Filter (CSF).
INPUT: LiDAR folder, output folder, slope (steep terrain), class threshold, cloth resolution, rigidness, tiling, skip existing outputs returnValue: none; the ground-classified LiDAR files are written to out_folder
rpy_hh2raster
rpy_hh2raster(in_las_folder, out_folder, Smooth_by, Min_ws=3.0, lawn_range=0.3, cell_size=0.0, processes=0, tiling='auto', skip_existing: bool = False, **kwargs)
Generate a raster of hummock hollows from LiDAR data.
INPUT: LiDAR folder, output folder, smoothing method, minimum watershed size, lawn range, cell size returnValue: raster of hummock hollows
surface_water_processes
surface_water_processes(processes, in_ortho, tile_size, min_patch_area)
R workers for surface_water_map on this machine: one per CPU core and tile, as far as the free memory holds one buffered tile per worker. processes > 0 caps the count.
rpy_surface_water
rpy_surface_water(in_ortho, in_training, out_folder, in_chm='', max_canopy_height=0.2, min_patch_area=0.04, points_per_polygon=2, seed=1, tile_size=2000, processes=0, **kwargs)
Map surface water from a true-colour orthomosaic with a decision tree.
Follows Chan, Dabros & McDermid (2026), Forests 17, 489, section 2.4.
INPUT: orthomosaic (bands 1-3 red, green, blue), training polygons with a 'class' field
('water' plus other classes such as 'ground' and 'shadow'), output folder,
optional CHM, canopy height mask threshold, minimum water patch area,
training points per polygon, random seed, tile size (cells per side; tiles are
classified in parallel by processes R workers)
returnValue: surface_water.tif (1 water, 0 not water) and cross-validation tables in out_folder
dtw_processes
dtw_processes(processes, in_dtm, kriging_cell_size, tile_size)
R workers for kriging the water table on this machine: one per CPU core and tile of the kriging grid, as far as the free memory holds one tile per worker. processes > 0 caps the count.
rpy_dtw
rpy_dtw(in_dtm, in_water, out_folder, in_mask='', grid_size=10.0, nmax=10, variogram_model='Ste', kriging_cell_size=0.01, tile_size=1000, processes=0, **kwargs)
Krige a water table from surface water elevations and compute depth-to-water.
Follows Chan, Dabros & McDermid (2026), Forests 17, 489, section 2.4.
INPUT: DTM, surface water raster (1 water, e.g. from Surface Water Mapping), output folder,
optional exclusion polygons, grid size, nearest observations, variogram model,
kriging cell size (0 = DTM cell size), tile size (kriging grid cells per side; tiles
are kriged in parallel by processes R workers)
returnValue: water_table.tif and dtw.tif (0 on surface water) in out_folder
rpy_seismic_line_analysis
rpy_seismic_line_analysis(in_segments, in_dtm, in_microform, out_folder, in_dtw='', significance=0.05, processes=0, **kwargs)
Compare seismic line segments with the adjacent matrix, by disturbance class.
Adapted from Chan, Dabros & McDermid (2026), Forests 17, 489. INPUT: segment polygons (fields new_id, note, Class), DTM raster, microform raster (1 hummock, 0 lawn, -1 hollow), optional depth-to-water raster (0 = surface water), output folder, significance level returnValue: CSV tables and PNG plots in out_folder/tables and out_folder/plots
R Interface
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Maverick Fong
Description
This script is helper tools for execute the R scripts.
Webpage: https://github.com/BERATool/beratools
configure_r_environment
configure_r_environment()
Locate and configure R before importing rpy2.
isolate_env_r_library
isolate_env_r_library(r_home)
Keep the environment's R from using the user's personal R library.
R adds the personal library (R_LIBS_USER, e.g. %LOCALAPPDATA%/R/win-library/4.5 on Windows) ahead of its own library. For an R installed in the conda/pixi environment, that would load packages installed for a separate R and stop the tools from installing into the environment. A non-existent R_LIBS_USER is dropped from .libPaths(), leaving only the environment's library. A standalone R (outside the environment) is left alone.
Copyright (C) 2025 Applied Geospatial Research Group.
This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.
Author: Maverick Fong
Description
This script is helper tools for execute the R scripts.
Webpage: https://github.com/BERATool/beratools
r_graphics_enabled
r_graphics_enabled()
Whether R runs interactively, so lidR draws its map of the tiles in an R Graphics window while it processes them: set environment variable BERATOOLS_R_GRAPHICS to 1, true or yes.
limit_memory
limit_memory(fraction=0.8)
Limit the memory of this process, and of the R workers it starts, to fraction of the
memory free now, so a tool that needs more fails with R's "cannot allocate" error instead of
running the computer out of memory (on one machine a by_file run left it 0.42 GB free, and the
run then took minutes to release its memory when stopped).
Windows only: the process joins a Job Object whose processes share a memory commit limit; the R workers, started by this process, join it too, and any left over end with it. A failure to set the limit, or another system, leaves memory unlimited.
decode_r_code_points
decode_r_code_points(text)
R's output with its "" code points turned back into the characters, such as ⚠.
r_processes_by_memory
r_processes_by_memory(processes, worker_bytes, tasks)
Workers for an R job whose memory per worker is known: as many as requested (all CPU cores if processes <= 0), limited by the CPU cores, the number of tasks and the free memory. 60% of the free memory is shared out, leaving room for the system and other programs.
r_max_workers
r_max_workers(processes)
Most R workers for the tiled LiDAR tools: as many as requested (all CPU cores if processes <= 0), at most the CPU cores. apply_tiling in R then uses as many of them as the free memory allows for the tiles.
free_memory
free_memory()
Free memory in bytes, which R shares out to size the LiDAR tiles.
check_r_packages_installation
check_r_packages_installation(packages, optional=())
Install the R packages in packages that are missing, stopping if one can't be installed. The packages in optional are installed too when missing, but a tool runs without them, so if they can't be installed (no internet, say) it only warns.