R/utils_geometry.R

Defines functions point_in_polygons

point_in_polygons <- function(las, sfc)
{
  if (!all(sf::st_geometry_type(sfc) %in% c("POLYGON", "MULTIPOLYGON")))
    stop("Only spatial polygons are supported", call. = FALSE)

  bbox <- sf::st_as_sfc(st_bbox(las))
  id  <- unlist(sf::st_intersects(bbox, sfc))
  id  <- as.integer(id)
  sfc2 <- sfc[id]

  wkt <- sf::st_as_text(sfc2, digit = 10)
  res <- C_in_polygon(las, wkt)
  idx <- id[res+1L]
  return(idx)
}

Try the lidR package in your browser

Any scripts or data that you put into this service are public.

lidR documentation built on Sept. 8, 2023, 5:10 p.m.