Loads point locations from a spatial file or sf object, validates them against a DEM, and enriches each point with elevation, projected coordinates, and WGS84 lat/lon. The result is the starting point for all downstream gaplightr workflows.
Arguments
- x
Either a file path to any file that
sf::read_sfcan read, or an sf object containing point geometries. Ifxcontains apoint_idcolumn of unique positive integers, those values are used as-is for all downstream file naming; otherwise sequential IDs are assigned automatically.- dem
Either a file path to a DEM raster file, or a
SpatRasterobject- drop_na_dem
Logical. If
FALSE(default), points falling on NoData cells in the DEM cause an error. IfTRUE, those points are dropped with a warning and processing continues with the remaining points.- ...
Additional arguments passed to
sf::read_sf()whenxis a file path
Details
This function performs strict validation:
Geometry type must be POINT
CRS must be defined and projected (not geographic lat/lon)
Point and DEM CRS must match exactly
All points must fall within DEM spatial extent
Points on NoData cells error by default; set
drop_na_dem = TRUEto drop them with a warning instead
Point IDs
Every point is assigned a point_id, a positive integer used to name all
downstream output files (LAS clips, horizon CSVs, fisheye photos). If x
does not contain a point_id column, sequential IDs are assigned
automatically (1, 2, 3, ...). To use your own IDs (for example to preserve
cached outputs across re-runs, or to match an existing site numbering scheme),
include a point_id column containing unique positive integers before
calling this function.
Examples
# \donttest{
points_path <- system.file("extdata", "points.geojson", package = "gaplightr")
dem_path <- system.file("extdata", "dem.tif", package = "gaplightr")
points <- gla_load_points(points_path, dem_path)
#> Assigning sequential point_id (1 to 3).
# }
# \donttest{
# Supply your own point_id values to keep cached outputs stable across
# re-runs or to match an existing site numbering scheme.
dem_path <- system.file("extdata", "dem.tif", package = "gaplightr")
my_points <- sf::st_read(
system.file("extdata", "points.geojson", package = "gaplightr"),
quiet = TRUE
)
my_points$point_id <- c(101L, 202L, 303L) # user-defined IDs
points <- gla_load_points(my_points, dem_path)
#> Using existing point_id column (3 point(s)).
# }