extend rasterize_terrain() #691
Replies: 2 comments 8 replies
-
According to the documentation the function |
Beta Was this translation helpful? Give feedback.
-
Ok so we can triangulate 2D points. But you do not have any interpolation method. So we will use some lidR's internal functions for linear interpolation. However, you must be careful here, you are using my internal function with your external tools. I don't know to which extent they fit together. For exemple the triangulation<- function(a = NULL, q = NULL, Y = FALSE, j = FALSE, D = FALSE, S = 10000, extrapolate = knnidw(3,1,50))
{
f = function(gnd, where)
{
# pslg needs a 2 coordinates object
M = lidR:::coordinates(gnd)
# Triangulation
pslg = RTriangle::pslg(P = M)
tri = RTriangle::triangulate(pslg, a, q, Y, j, D, S)
# lidR's internal linear interpolation of triangles
D = tri[["T"]]
P = as.matrix(lidR:::coordinates3D(gnd))
X = as.matrix(where)
z = lidR:::tInterpolate(D,P,X)
# Extrapolate beyond the convex hull
isna <- is.na(z)
nnas <- sum(isna)
if (nnas > 0)
{
lidR.context <- "spatial_interpolation"
where2 <- data.frame(X = where$X[isna], Y = where$Y[isna])
zknn <- extrapolate(gnd, where2)
z[isna] <- zknn
}
return(z)
}
# f is a function but we can set compatible classes. Here it is an
# algorithm for DTM
f <- plugin_dtm(f)
return(f)
}
library(lidR)
LASfile <- system.file("extdata", "Topography.laz", package="lidR")
las = readLAS(LASfile)
dtm = rasterize_terrain(las, 1, triangulation())
plot(dtm)
plot_dtm3d(dtm)
# generate incorrect result
dtm = rasterize_terrain(las, 1, triangulation(a = 100, S = 2))
plot(dtm)
# force 0 Steiner points (which should fall to regular Delaunay I guess)
dtm = rasterize_terrain(las, 1, triangulation(a = 100, S = 0))
plot(dtm) |
Beta Was this translation helpful? Give feedback.
-
This package looks incredible. Thank you.
I want to understand something please.
You allow lidR to be extended through integrating other packages?
I want to extend the rasterize_terrain() with Shewchuk’s Triangle. It accommodates a constrained Delaunay with holes.
Would implementing it be similar to the mba example in the tutorial? Your help would be appreciated. Does that mean I would need to ‘create’ the Triangle algorithm everytime I want to execute the option?
Beta Was this translation helpful? Give feedback.
All reactions