-
-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grid_terrain() producing NAs and negative values #283
Comments
There are two things to figure out here.
To answer these two questions I will need a reproducible example. Let try out of a dummy point cloud (see below). As you can see, I can reproduce but the In your case you seems to have NAs in pixels with point according to your gis question. So this is another issue that need a reproducible example I can't produce myself. library(lidR)
las <- lidR:::dummy_las(500)
las@data[, Z := round(Z + 0.005*(X-30)^2 - 0.005*(Y - 50)^2 + 20,3)]
f = tempfile(fileext = ".las")
writeLAS(las, f)
ctg = readLAScatalog(f)
opt_chunk_size(ctg) = 50
opt_chunk_buffer(ctg) = 10
opt_progress(ctg) <- FALSE
plot(ctg, chunk = TRUE)
# From las to RasterLayer in memory
dtm1 = grid_terrain(las, 0.5, knnidw(5))
plot(dtm1)
dtm1
#> class : RasterLayer
#> dimensions : 200, 200, 40000 (nrow, ncol, ncell)
#> resolution : 0.5, 0.5 (x, y)
#> extent : 0, 100, 0, 100 (xmin, xmax, ymin, ymax)
#> crs : NA
#> source : memory
#> names : Z
#> values : 8.605863, 42.92965 (min, max)
# From catalog to RasterLayer in memory
dtm2 = grid_terrain(ctg, 0.5, knnidw(5))
plot(dtm2)
dtm2
#> class : RasterLayer
#> dimensions : 200, 200, 40000 (nrow, ncol, ncell)
#> resolution : 0.5, 0.5 (x, y)
#> extent : 0, 100, 0, 100 (xmin, xmax, ymin, ymax)
#> crs : NA
#> source : memory
#> names : Z
#> values : 8.605863, 42.92965 (min, max)
# From catalog to RasterLayers on disk
opt_output_files(ctg) <- paste0(tempfile(),"/{ID}")
dtm3 = grid_terrain(ctg, 0.5, knnidw(5))
#> Registered S3 method overwritten by 'R.oo':
#> method from
#> throw.default R.methodsS3
plot(dtm3)
dtm3
#> class : RasterLayer
#> dimensions : 200, 200, 40000 (nrow, ncol, ncell)
#> resolution : 0.5, 0.5 (x, y)
#> extent : 0, 100, 0, 100 (xmin, xmax, ymin, ymax)
#> crs : NA
#> source : /tmp/RtmpE5YSeL/file6f8642af2bf2/grid_terrain.vrt
#> names : grid_terrain
#> values : 8.605863, 42.92965 (min, max)
range(dtm3[])
#> [1] -3.400000e+38 4.292965e+01
lasn = lasnormalize(las, dtm3)
range(lasn$Z)
#> [1] -2.911 26.841
plot(lasn)
ctgn = lasnormalize(ctg, dtm3)
spplot(ctgn, "Min.Z") Created on 2019-09-27 by the reprex package (v0.3.0) |
I've found why the NA are not properly interpreted. This has been fixed. As a temporary workaround you can force the las <- lidR:::dummy_las(500)
las@data[, Z := round(Z + 0.005*(X-30)^2 - 0.005*(Y - 50)^2 + 20,3)]
f = tempfile(fileext = ".las")
writeLAS(las, f)
ctg = readLAScatalog(f)
opt_chunk_size(ctg) = 50
opt_chunk_buffer(ctg) = 10
opt_progress(ctg) <- FALSE
opt_output_files(ctg) <- paste0(tempfile(),"/{ID}")
# force NAflag not being -Inf because not interpreted properly by `gdalUtils`
ctg@output_options$drivers$Raster$param$NAflag = -9999999
dtm3 = grid_terrain(ctg, 0.5, knnidw(5))
plot(dtm3) # it works
range(dtm3[]) |
@Jean-Romain Thank you for looking into this, and providing a workaround. I was able to normalize using technique outlined here: #184 (comment) This not ideal however, and is probably ignoring an underlying bug. I'll work on reproducing and submitting something for you. |
Yes if you can make a reproducible example it will help me. I think that I know the issue (the same as in #184). I will change the method of selection of interpolation points for a better one. It actually relies on a old code that could be improved. |
I close this issue, please open a new one if you reproduce. Here a summary of my guess on the issue:
It is a double bug. The first bug is handled internally an fails with an informative error but the second bug generated a side effect that enabled the code to work instead of failing. |
I added an option |
The
grid_terrain.vrt
file produced bygrid_terrain()
has several huge negative values (looks like it might be the most negative number possible). Here is a summary of thegrid_terrain.vrt
file:It looks like there are plenty of these negative values too:
Digging a little bit deeper I made a mosaic out of the
.tif
files generated bygrid_terrain
so that I could compare with the previous.vrt
file:The mosaic of tifs is called
dtm
and at a first glance it looks better - no massive negative values. But really we just haveNA
s instead of the large negatives.The text was updated successfully, but these errors were encountered: