copc4R

March 14, 2026 · View on GitHub

licence

R package for reading and writing Cloud Optimized Point Cloud (COPC) files from local disk or HTTP(S) endpoints using range reads. Supports spatial queries, multi-resolution sampling, streaming iteration, deterministic tiling, and lidR catalog integration.

It enables R users to read .copc.laz binary files — a single-file, spatially indexed variant of LAZ commonly used for streaming LiDAR data from the cloud.

Installation

# Install the development version from GitHub:
# install.packages("remotes")
remotes::install_github("bi0m3trics/copc4R")

Quick example

library(sf)
library(copc4R)

# ── Define a point location and buffer to a 100 m circular AOI ───────────────
sf_use_s2(TRUE)   # st_buffer unit is meters for geographic CRS

aoi <- st_sf(
  id       = 1,
  geometry = st_sfc(st_point(c(-111.72671, 35.10700)), crs = 4326)
)
aoi <- st_buffer(aoi, dist = 100)

# ── Stream points from USGS 3DEP via Planetary Computer STAC ─────────────────
# read_copc() detects the STAC endpoint, discovers intersecting tiles,
# fetches only the octree nodes overlapping the AOI via HTTP range reads,
# clips to the circle boundary, and merges results across tile boundaries.
# The "3dep-lidar-copc" collection is selected automatically for this host.

result <- read_copc(
  "https://planetarycomputer.microsoft.com/api/stac/v1/search",
  aoi    = aoi,
  select = "xyzicrnap",    # X Y Z Intensity Classification ReturnNumber
                           # NumberOfReturns ScanAngle PointSourceID
  filter = paste(
    "-drop_withheld",      # remove withheld flag points
    "-keep_voxel 1.0",     # 3-D voxel thinning at ~1 m spacing
    "-keep_first",         # first returns only
    "-drop_noise"          # drop ASPRS noise classes (7, 18)
  ),
  progress = TRUE
)

# result$data   -- data.table of point attributes
# result$header -- named list of LAS header fields

# ── Convert to a lidR LAS object and visualise ───────────────────────────────
las <- as_las(result)
lidR::plot(las)

Features

  • Reads .copc.laz files from local paths or HTTP(S) URLs via range reads — only the bytes you need are fetched.
  • Spatial filtering: bounding box, polygon AOI, corridor, and Z-range queries through the COPC octree hierarchy.
  • Attribute filters: pass lidR/LAStools-style filter strings (e.g. -keep_first, -drop_noise, -keep_voxel).
  • Multi-resolution LOD sampling for fast previews without reading the full point cloud.
  • Deterministic tiling for reproducible, grid-based point cloud partitioning.
  • Streaming iterators for memory-efficient processing of large files.
  • lidR catalog integration via read_copc_catalog() and copc_apply().
  • STAC / Planetary Computer support — auto-discovers intersecting COPC tiles from a STAC endpoint.
  • Writes .copc.laz files via write_copc().
  • Returns data.table output with rlas-compatible header conventions.
  • Column selection via a lidR-style select string ("xyz", "xyzirc", "*", etc.).
  • Optional conversion to lidR::LAS objects via as_las().
  • Bundled LASzip for LAZ decompression — no external system dependencies required.

copc4R contains code written by Andrew Sánchez Meador as well as third-party code included for technical reasons. Details below.