Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. metrics<-function(z){Q75=quantile(z,probs=c(0.75))
  2.  
  3. aboveq75=sum(z>Q75)
  4.  
  5. dh75=aboveq75/length(z)
  6.  
  7. return(dh75)}
  8.  
  9. DH75<-grid_metrics(lid,~metrics(Z),res = 30)
  10.  
  11. > metrics(runif(1000))
  12. [1] 0.25
  13. > metrics(runif(12))
  14. [1] 0.25
  15. > metrics(runif(13))
  16. [1] 0.2307692
  17.  
  18. LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
  19. las = readLAS(LASfile)
  20. Q75=quantile(las$Z,0.75)
  21. Q75
  22. ## 75%
  23. ## 19.32
  24.  
  25. metrics <-
  26. function(z){
  27. aboveq75=sum(z>Q75)
  28. dh75=aboveq75/length(z)
  29. return(dh75)
  30. }
  31.  
  32. > DH75<-grid_metrics(las,~metrics(Z),res = 3)
  33. > plot(DH75)
  34.  
  35. #dependencies
  36. library(lidR)
  37. library(ggplot2)
  38. library(stats)
  39.  
  40. #specify file path
  41. infile <- 'path_to_your_cloud.las'
  42.  
  43. #read in las cloud
  44. las <- readLAS(infile)
  45.  
  46. #create density raster
  47. density_plot <- grid_density(las, res = 10)
  48.  
  49. #calculate 75th percentile point density
  50. Q75 = quantile(density_plot$point_density, probs = 0.75)
  51.  
  52. #filter raster based on value
  53. density_plot_Q75 <- density_plot[density_plot$point_density > Q75]
  54.  
  55. #plot unfiltered raster
  56. ggplot() +
  57. geom_raster(data = density_plot , aes(x = X, y = Y, fill = point_density)) +
  58. coord_quickmap()
  59.  
  60. #plot filtered raster
  61. ggplot() +
  62. geom_raster(data = density_plot_Q75 , aes(x = X, y = Y, fill = point_density)) +
  63. coord_quickmap()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement