Closed wiesehahn closed 1 year ago
From the doc:
RasterStack, RasterBrick, multibands stars or multilayer SpatRaster must have 3 layers for RGB colors. It colorizes the point cloud with RGB values.
So this should work
las_rgb <- merge_spatial(las, img)
Yet you found a bug with automatic naming.
Ok, but I still have a problem, with my above mentioned aproach I get one point with NA value for whatever reason (the raster seems to be fine).
> is.na(img)
class : SpatRaster
dimensions : 500, 500, 3 (nrow, ncol, nlyr)
resolution : 0.2, 0.2 (x, y)
extent : 567222.4, 567322.4, 5708785, 5708885 (xmin, xmax, ymin, ymax)
coord. ref. : ETRS89 / UTM zone 32N (EPSG:25832)
source(s) : memory
names : R, G, B
min values : FALSE, FALSE, FALSE
max values : FALSE, FALSE, FALSE
Thats why plot()
did not work and I used las_rgb <- filter_poi(las_rgb, !is.na(R) & !is.na(G) & !is.na(B))
to filter this point.
With las_rgb <- merge_spatial(las, img)
I cannot get around this and get Error: Some points were associated with an NA RGB color. RGB cannot be NA in a LAS object. Colorization aborted.
The img
either does not cover the point cloud entirely or contain NA
. If not please provide a reproducible example.
You were right I was trying to crop the image with the bbox of the las, which did not perfectly fit with default sanpping option nearest
, changing to out
did the trick.
> bbox <- st_bbox(las)
>
>
> # crop to las extent
> img1 <- crop(img, st_as_sfc(bbox))
>
> ext(img1)
SpatExtent : 569137.4, 569147.4, 5709415.4, 5709425.2 (xmin, xmax, ymin, ymax)
> ext(las)
SpatExtent : 569137.482, 569147.434, 5709415.464, 5709425.295 (xmin, xmax, ymin, ymax)
>
> # try to add RGB
> las_rgb <- merge_spatial(sample, img1)
Error: Some points were associated with an NA RGB color. RGB cannot be NA in a LAS object. Colorization aborted.
> # crop to extented bbox
> img2 <- crop(img, st_as_sfc(bbox),snap="out")
>
> ext(img2)
SpatExtent : 569137.4, 569147.6, 5709415.4, 5709425.4 (xmin, xmax, ymin, ymax)
> ext(las)
SpatExtent : 569137.482, 569147.434, 5709415.464, 5709425.295 (xmin, xmax, ymin, ymax)
>
> # add RGB works
> las_rgb <- merge_spatial(sample, img2)
Although I am wondering if it would be possible / useful to add RGB values where there is valid data only (not sure if NA is valid in las data though).
No because NA is not a writable value in a LAS file and lidR tries to ensure that LAS
objects are always writable in LAS files.
Makes sense, thanks!
Fixed, attributes are no longer automatically renamed when filtering a point cloud
Hi, I want to merge RGB values from raster image to the las pointcloud.
Currently I tried:
But I guess there is a better way, since the intermediate
r
value seems obsolete. How would I do it properly?Also it seems strange that
plot(las_rgb, color = "RGB)
cant find RGB values when I do not runadd_lasrgb
(since I named them with lower letters), butfilter_poi
seems to recognize the lower letters as RGB values and renames them to capital RGB, which then results in two attributes for each R, G and B.