【问题标题】:How to create polygon according to treeID from spatial points data frame?如何根据空间点数据框中的treeID创建多边形?
【发布时间】:2018-07-30 15:51:02
【问题描述】:

我从 .las 文件创建了一个空间点数据框,该文件具有以下结构和标题。

head(Rnorm@data)

         X       Y     Z  gpstime Intensity ReturnNumber NumberOfReturns Classification ScanAngle pulseID treeID
1: 390385.3 5847998 23.35 8194.459         9            1               2              5       -14       1    291
2: 390385.9 5847998  0.52 8194.479        76            1               1              4       -13       2    291
3: 390385.1 5847998  1.06 8194.483        72            1               1              4       -13       3    291
4: 390385.7 5847999  0.81 8194.483        75            1               1              4       -13       4    291
5: 390386.1 5848001  0.41 8194.503        15            2               2              3       -13       5    241
6: 390385.4 5848000  0.26 8194.503        78            1               1              3       -13       6    241

将此数据转换为空间点数据框

 df <- as.spatial(Rnorm)

空间点数据框的结构如下:

 str(df)

具有 5 个插槽的正式类 'SpatialPointsDataFrame' [package "sp"]

..@ data       :'data.frame':   71164 obs. of  9 variables:
  .. ..$ Z              : num [1:71164] 23.35 0.52 1.06 0.81 0.41 ...
  .. ..$ gpstime        : num [1:71164] 8194 8194 8194 8194 8195 ...
  .. ..$ Intensity      : int [1:71164] 9 76 72 75 15 78 54 76 55 79 ...
  .. ..$ ReturnNumber   : int [1:71164] 1 1 1 1 2 1 1 1 2 1 ...
  .. ..$ NumberOfReturns: int [1:71164] 2 1 1 1 2 1 1 1 2 1 ...
  .. ..$ Classification : int [1:71164] 5 4 4 4 3 3 3 3 3 3 ...
  .. ..$ ScanAngle      : int [1:71164] -14 -13 -13 -13 -13 -13 -13 -14 -14 -14 
  .. ..$ pulseID        : int [1:71164] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..$ treeID         : int [1:71164] 291 291 291 291 241 241 241 291 NA NA 
  ..@ coords.nrs : num(0) 
  ..@ coords     : num [1:71164, 1:2] 390385 390386 390385 390386 390386 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:2] "X" "Y"
  ..@ bbox       : num [1:2, 1:2] 390281 5847998 390386 5848126
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "X" "Y"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
  .. .. ..@ projargs: chr NA

现在我想从包含多个点的每个 treeID 创建多边形,所以想请求您的帮助。

提前感谢您的帮助。

【问题讨论】:

  • 请指定您在标签中使用的语言
  • 请添加已加载的包。
  • 加载的包是lidR和sp和rgdal。
  • @lok​​i,感谢您的链接。我尝试使用类似的结构进行创建,但它不起作用,因为我无法将 treeID 与 SpatialPolygons 中的坐标结合起来,这将为我提供落在它之下的点的边界。我在 xy 和它的 treeID 中有点的坐标,所以我怎样才能将它们结合在一个 Polygons 中。

标签: r spatial polygons lidar


【解决方案1】:

lidR 包具有从点云数据创建单个树多边形所需的功能。以下example 展示了如何将点云数据转换为单个树多边形:

library(lidR)

# read file
las = readLAS("Example.las")

# ground classification
lasground(las, MaxWinSize = 10, InitDist = 0.05, CellSize = 7)

# normalization
lasnormalize(las, method = "knnidw", k = 10L)

# compute a canopy image
chm = grid_canopy(lasnorm, res = 0.5, subcircle = 0.2, na.fill = "knnidw", k = 4)
chm = as.raster(chm)
kernel = matrix(1,3,3)
chm = raster::focal(chm, w = kernel, fun = mean)
chm = raster::focal(chm, w = kernel, fun = mean)

# tree segmentation
crowns = lastrees(las, "watershed", chm, th = 4, extra = TRUE)

# display
tree = lasfilter(las, !is.na(treeID))
plot(tree, color = "treeID", colorPalette = pastel.colors(100), size = 1)

# More stuff
library(raster)
contour = rasterToPolygons(crowns, dissolve = TRUE)

plot(chm, col = height.colors(50))
plot(contour, add = T) 

【讨论】:

    猜你喜欢
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 2019-11-12
    • 2018-08-01
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多