1

I use lidR package. I have a catalog and I want to save as a shapefile the centroid of each chunk make with opt_chunk_size of a catalog ?

1 Answer 1

1

There may be a better way to do this, but a combination of lidR functions and the sf package should work. Try the following:

ctg <- readLAScatalog("~/Documents/data/lidar/example_catalog/")
opt_chunk_size(ctg) <- 1000
plot(ctg, chunk=TRUE)
chunks <- catalog_makechunks(ctg)
library(sf)
centroids <- lapply(chunks, function(chunk) {
  return(st_point(x=c(chunk@center$x, chunk@center$y)))
})
centroids_shape <- st_as_sfc(centroids)
plot(centroids_shape)
st_write(centroids_shape, "/tmp/test.shp")

Plot of catalog:

enter image description here

Plot of un-chunked centroids:

enter image description here

Plot of chunked catalog:

enter image description here

Plot of chunked centroids:

enter image description here

Overlay of chunks, and their centroids:

enter image description here

** UPDATE ** - As mentioned by @JRR, you will need version 3.0.0 of the lidR package to use catalog_makechunks() which I believe is currently in development. In older versions you must use the internal function lidR:::catalog_makeclusters(). To get version 3.0.0 of lidR you can run:

library(devtools)
install_github("Jean-Romain/lidR", ref = "devel")
1
  • 1
    This is a good answer. However catalog_makechunks exists only from v3.0.0 and is not "internal". It is exposed to users. Before v3.0.0 one must use lidR:::catalog_makeclusters() that is actually internal.
    – JRR
    Commented Apr 1, 2020 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.