3

Is it possible/allowed to change the extent of a lidR LAS point cloud? And if yes, does it affect the generation of rasters (e.g. with grid_metrics or grid_canopy), so that they cover the full extent?

So far, when creating a raster with lidR, it will (naturally) only be as big as the point cloud. Since I want pixels to align to a certain grid, I'd like to use a specified extent on which the rasters will be calculated (ignoring whether there are points or not, cells without points should result to NA).

In the doc of grid_metric I discovered a parameter start, but I don't know how to calculate the right values to ensure alignment to a given extent - also it seems circumstancial. My workaround so far is to extend the raster to the extent:

# calculate surface model
dsm = grid_canopy(las, res = 0.5, p2r(0.5))

# extend to original LAS extent
dsm = extend(dsm, extent(dtm), value=NA)

But that feels "dirty" to me and I also fear issues with pixel alignment if the point cloud seeds at uneven coordinates.

My naive approach extent(las) = extent(dtm) doesn't work (‘extent’ is not a slot in class “LAS”) and after reading the las formal class doc I am hesitant to manipulate the header itself, since I don't want to create invalid las objects.

Is there a proper way to do this (treat the point cloud as covering a given extent, in particular align raster generation to it)?

Background

I am working on a tiled grid that covers a large area. The point cloud is not always covering the full extent of a tile, as can be seen below for tile 2717_1088 (in green the tile, in grey the extent of the point cloud). enter image description here

To avoid problems with pixel alignment, I'd like to process the point cloud on the full extent, so that pixels fit perfectly (the tile is 1000x1000m, e.g. 10m pixels will be perfectly aligned on the full extent. If the pointcloud however generates a raster starting at an uneven coordinate, the pixels may be shifted. I don't want to resample due to imprecision and computational cost).

1 Answer 1

2

Well, I think you are overthinking the problem.

Considering what I'm understanding of your problem I can't see any problem. In lidR rasters are always properly aligned according to a reference point (start parameter) and the extent of the point cloud does not matter. The grid is snapped and slightly extended to be aligned. No possible misalignment.

If you really want to get a specific raster extend is an option but you can also provide a RasterLayer as input. But it becomes harder to manage when processing an entire LAScatalog collection.

library(lidR)
library(raster)

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las = readLAS(LASfile)

b <- extent(las) + c(-40,70,0,100)
r <- raster(b, res = 8)
m <- grid_metrics(las, ~mean(Z), r)

plot(m)
plot(extent(m), add = T, col = "red", lwd = 2)

5
  • great, the second part of your answer is what I was looking for - just didn't read carefully enough in the doc, it is right there under res numeric. The resolution of the output Raster. Can optionally be a RasterLayer. In that case the RasterLayer is used as the layout
    – Honeybear
    Dec 7, 2021 at 23:32
  • I'm still trying to understand the first part of your answer ("The grid is snapped and slightly extended to be aligned. So it fits."): if my point cloud is something like at xmin,ymin = [7,5,16,15], isn't the first pixel with res = 5 and the default start=(0,0) then xmin,ymin,xmax,ymax = [7,5,12,10]? And the final raster will be [7,5,17,15]? Or does lidR know that it should snap to [5,5], creating a raster [5,5,20,15]?
    – Honeybear
    Dec 7, 2021 at 23:44
  • 1
    Second option, it will create a raster [5,5,20,15]. [7,5,17,15] does not align on [0,0] with a resolution of 5
    – JRR
    Dec 7, 2021 at 23:51
  • Alright. I figured start=[0,0] is to be understood relative to the extent, hence aligning to [7,5] not the absolute [0,0]. But now that I read it again, the doc again is actually clear on this. To be sure: If my tiling (nonsensically) aligns to at [3.5,4.523], then I'd set start=[3.5,4.523] or [8.5,9.523], and the result would perfectly align? Also, if I may say so here, you have done a wonderful job with this package and the comprehensive documentation - thank you! I hope it doesn't bother you, that I still have a question once in a while...
    – Honeybear
    Dec 8, 2021 at 0:06
  • You should not align your raster with the tilling pattern. If the tilling pattern is weird lidR will adjust automatically by using neighbouring tiles (when processing a LAScatalog) to mach your start and res. And if the tilling pattern is regular but your res and start are weird (e.g. res = 13, start = (7,7)) it works too.
    – JRR
    Dec 8, 2021 at 0:13

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.