Crop VoxelSpace
object based on voxel i, j,
k, index. If cropping index are missing, the function will automatically crop
the voxel space by discarding outermost unsampled slices of voxels. A slice
designates a layer with constant i (i-slice), j (j-slice) or k (k-slice).
unsampled means that no pulse went through.
One may want to crop the voxel space on coordinates rather than grid index.
To do so the voxel space must be first converted to an sf::sf
object and use the sf::st_crop()
function.
vxsp <- readVoxelSpace(system.file("extdata", "tls_sample.vox", package = "AMAPVox"))
vxsp@data[, c("x", "y"):=getPosition(vxsp)[, .(x, y)]]
library(sf)
vx.sf <- sf::st_as_sf(vxsp@data, coords=c("x", "y"))
vx.sf <- sf::st_crop(vx.sf, c(xmin = 4, ymin = 1, xmax = 5, ymax = 4))
sf::st_bbox(vx.sf)
vxsp@data <- sf::st_drop_geometry(vx.sf)