如何一次读取许多LIDAR文件(.las)并将它们集合到R中的一个数据范围

发布于 2025-01-22 00:10:11 字数 6107 浏览 1 评论 0原文

我有许多LIDAR(.las)文件的文件夹。看起来像是

library(rgdal)
library(raster)
library(tmaptools)
library(tmap)

library(lidR)
library(RStoolbox)
las=readLAS("C:/1/078-638.las")
las1=readLAS("C:/1/082-628.las")
las2=....

100多个文件,很难在每行中写入。有没有办法一次读取所有这些文件,但是格式data.frame? .LAS文件具有

las=payload(las)

las=structure(list(X = c(638238.76, 638238.76, 638239.29, 638235.39, 
638233.86, 638233.86, 638235.55, 638231.97, 638231.91, 638228.41
), Y = c(6078001.09, 6078001.09, 6078001.15, 6078001.15, 6078001.07, 
6078001.07, 6078001.02, 6078001.08, 6078001.09, 6078001.01), 
    Z = c(186.64, 186.59, 199.28, 189.37, 186.67, 186.67, 198.04, 
    200.03, 199.73, 192.14), gpstime = c(319805734.664265, 319805734.664265, 
    319805734.67875, 319805734.678768, 319805734.678777, 319805734.678777, 
    319805734.687338, 319805734.701928, 319805734.701928, 319805734.701945
    ), Intensity = c(13L, 99L, 5L, 2L, 20L, 189L, 2L, 11L, 90L, 
    1L), ReturnNumber = c(2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 
    3L), NumberOfReturns = c(2L, 1L, 3L, 2L, 1L, 1L, 3L, 1L, 
    1L, 4L), ScanDirectionFlag = c(1L, 1L, 0L, 0L, 0L, 0L, 1L, 
    0L, 0L, 0L), EdgeOfFlightline = c(0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L), Classification = c(1L, 2L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L), Synthetic_flag = c(FALSE, FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), Keypoint_flag = c(FALSE, 
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
    ), Withheld_flag = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE), ScanAngleRank = c(-12L, -12L, 
    -12L, -12L, -12L, -12L, -12L, -13L, -13L, -13L), UserData = c(0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), PointSourceID = c(16L, 
    16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L), Pulse.width = c(0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA, 
-10L))

LAS1的

las1=structure(list(X = c(628800.68, 628800.75, 628801.43, 628801.47, 
628802.13, 628802.19, 628800.19, 628800.24, 628799.57, 628799.58
), Y = c(6082001.07, 6082001.08, 6082001.19, 6082001.2, 6082001.3, 
6082001.31, 6082001.21, 6082001.22, 6082001.12, 6082001.12), 
    Z = c(163.16, 162.96, 163.09, 162.97, 163.12, 162.98, 163.29, 
    163.16, 163.02, 162.99), gpstime = c(319799021.884921, 319799021.884921, 
    319799021.884929, 319799021.884929, 319799021.884938, 319799021.884938, 
    319799021.889375, 319799021.889375, 319799021.889384, 319799021.889384
    ), Intensity = c(12L, 99L, 14L, 112L, 14L, 121L, 17L, 167L, 
    20L, 189L), ReturnNumber = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L), NumberOfReturns = c(1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L), ScanDirectionFlag = c(1L, 1L, 1L, 1L, 1L, 
    1L, 0L, 0L, 0L, 0L), EdgeOfFlightline = c(0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L), Classification = c(1L, 2L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 2L), Synthetic_flag = c(FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), 
    Keypoint_flag = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE), Withheld_flag = c(FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), 
    ScanAngleRank = c(17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 
    17L, 17L), UserData = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L), PointSourceID = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
    4L), Pulse.width = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L)), class = "data.frame", row.names = c(NA, -10L))

这种结构,然后在我们读取所有.las文件后,我们将其结合在一个数据集中,并指示这些行属于第一个LAS文件,而这些行属于第二个文件,则是这样的,

X              Y           Z    gpstime        Intensity    ReturnNumber            number las
638238.76   6078001.09  186.64  319805734.664265    13         2                          1
638238.76   6078001.09  186.59  319805734.664265    99         1                          1
638239.29   6078001.15  199.28  319805734.67875      5         1                          1
638235.39   6078001.15  189.37  319805734.678768    2          2                          1
638233.86   6078001.07  186.67  319805734.678777    20         1                          1
638233.86   6078001.07  186.67  319805734.678777    189        1                          1
638235.55   6078001.02  198.04  319805734.687338    2          2                          1
638231.97   6078001.08  200.03  319805734.701928    11         1                          1
638231.91   6078001.09  199.73  319805734.701928    90         1                          1
638228.41   6078001.01  192.14  319805734.701945    1          3                          1
628800.68   6082001.07  163.16  319799021.884921    12         1                          2
628800.75   6082001.08  162.96  319799021.884921    99         1                          2
628801.43   6082001.19  163.09  319799021.884929    14         1                          2
628801.47   6082001.2   162.97  319799021.884929    112        1                          2
628802.13   6082001.3   163.12  319799021.884938    14         1                          2
628802.19   6082001.31  162.98  319799021.884938    121        1                          2
628800.19   6082001.21  163.29  319799021.889375    17         1                          2
628800.24   6082001.22  163.16  319799021.889375    167        1                          2
628799.57   6082001.12  163.02  319799021.889384    20         1                          2
628799.58   6082001.12  162.99  319799021.889384    189        1                          2

所以我该如何才能我如何从文件夹C:/1读取所有.las文件,然后所有这些文件都像我上面提供的那样获取结构格式,然后将其组合到具有LAS文件号的1个数据集中。 感谢您的任何宝贵帮助。

*编辑 现在下一个错误list_df< - fileNames%>%

  • purrr :: map(。 usemethod的错误(“突变”): 没有适用于LAS对象的“突变”方法 我认为它是因为LAS格式具有这样的结构

    las 类:LAS(V1.2格式1) 内存:308.7 MB 范围:637999,638240.5,6077999,6079999(Xmin,Xmax,Ymin,Ymax) 协调。参考。 :na 区域:409328单位² 积分:368万分 密度:8.99点/单位²

但是LAS的数据框必须使用我指出的有效载荷功能。

但是list_df< - fileNames%>%

  • purrr :: map(。 提供错误。

I have folder where many lidar(.las) files. It looks like

library(rgdal)
library(raster)
library(tmaptools)
library(tmap)

library(lidR)
library(RStoolbox)
las=readLAS("C:/1/078-638.las")
las1=readLAS("C:/1/082-628.las")
las2=....

so if more than 100 files It's hard to write in every line. Is there a way to read all these files at once, but in format data.frame?
.las file has such structure

las=payload(las)

las=structure(list(X = c(638238.76, 638238.76, 638239.29, 638235.39, 
638233.86, 638233.86, 638235.55, 638231.97, 638231.91, 638228.41
), Y = c(6078001.09, 6078001.09, 6078001.15, 6078001.15, 6078001.07, 
6078001.07, 6078001.02, 6078001.08, 6078001.09, 6078001.01), 
    Z = c(186.64, 186.59, 199.28, 189.37, 186.67, 186.67, 198.04, 
    200.03, 199.73, 192.14), gpstime = c(319805734.664265, 319805734.664265, 
    319805734.67875, 319805734.678768, 319805734.678777, 319805734.678777, 
    319805734.687338, 319805734.701928, 319805734.701928, 319805734.701945
    ), Intensity = c(13L, 99L, 5L, 2L, 20L, 189L, 2L, 11L, 90L, 
    1L), ReturnNumber = c(2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 
    3L), NumberOfReturns = c(2L, 1L, 3L, 2L, 1L, 1L, 3L, 1L, 
    1L, 4L), ScanDirectionFlag = c(1L, 1L, 0L, 0L, 0L, 0L, 1L, 
    0L, 0L, 0L), EdgeOfFlightline = c(0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L), Classification = c(1L, 2L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L), Synthetic_flag = c(FALSE, FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), Keypoint_flag = c(FALSE, 
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
    ), Withheld_flag = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE), ScanAngleRank = c(-12L, -12L, 
    -12L, -12L, -12L, -12L, -12L, -13L, -13L, -13L), UserData = c(0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), PointSourceID = c(16L, 
    16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L), Pulse.width = c(0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA, 
-10L))

structure of las1

las1=structure(list(X = c(628800.68, 628800.75, 628801.43, 628801.47, 
628802.13, 628802.19, 628800.19, 628800.24, 628799.57, 628799.58
), Y = c(6082001.07, 6082001.08, 6082001.19, 6082001.2, 6082001.3, 
6082001.31, 6082001.21, 6082001.22, 6082001.12, 6082001.12), 
    Z = c(163.16, 162.96, 163.09, 162.97, 163.12, 162.98, 163.29, 
    163.16, 163.02, 162.99), gpstime = c(319799021.884921, 319799021.884921, 
    319799021.884929, 319799021.884929, 319799021.884938, 319799021.884938, 
    319799021.889375, 319799021.889375, 319799021.889384, 319799021.889384
    ), Intensity = c(12L, 99L, 14L, 112L, 14L, 121L, 17L, 167L, 
    20L, 189L), ReturnNumber = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L), NumberOfReturns = c(1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L), ScanDirectionFlag = c(1L, 1L, 1L, 1L, 1L, 
    1L, 0L, 0L, 0L, 0L), EdgeOfFlightline = c(0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L), Classification = c(1L, 2L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 2L), Synthetic_flag = c(FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), 
    Keypoint_flag = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE), Withheld_flag = c(FALSE, FALSE, 
    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), 
    ScanAngleRank = c(17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 
    17L, 17L), UserData = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L), PointSourceID = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
    4L), Pulse.width = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L)), class = "data.frame", row.names = c(NA, -10L))

then after we read all .las files , we combine it in one dataset, with indicating that these rows belong to the first las file, and these to the second, something like this

X              Y           Z    gpstime        Intensity    ReturnNumber            number las
638238.76   6078001.09  186.64  319805734.664265    13         2                          1
638238.76   6078001.09  186.59  319805734.664265    99         1                          1
638239.29   6078001.15  199.28  319805734.67875      5         1                          1
638235.39   6078001.15  189.37  319805734.678768    2          2                          1
638233.86   6078001.07  186.67  319805734.678777    20         1                          1
638233.86   6078001.07  186.67  319805734.678777    189        1                          1
638235.55   6078001.02  198.04  319805734.687338    2          2                          1
638231.97   6078001.08  200.03  319805734.701928    11         1                          1
638231.91   6078001.09  199.73  319805734.701928    90         1                          1
638228.41   6078001.01  192.14  319805734.701945    1          3                          1
628800.68   6082001.07  163.16  319799021.884921    12         1                          2
628800.75   6082001.08  162.96  319799021.884921    99         1                          2
628801.43   6082001.19  163.09  319799021.884929    14         1                          2
628801.47   6082001.2   162.97  319799021.884929    112        1                          2
628802.13   6082001.3   163.12  319799021.884938    14         1                          2
628802.19   6082001.31  162.98  319799021.884938    121        1                          2
628800.19   6082001.21  163.29  319799021.889375    17         1                          2
628800.24   6082001.22  163.16  319799021.889375    167        1                          2
628799.57   6082001.12  163.02  319799021.889384    20         1                          2
628799.58   6082001.12  162.99  319799021.889384    189        1                          2

So How can i read all .las files from folder C:/1, then for all of them get structure format like i provided above, and them combine it into 1 dataset with las file number.
Thanks for any of your valuable help.

*Edit
now next error list_df <- filenames %>%

  • purrr::map(., ~readLAS(.x) %>% mutate(filenumber = match(.x, filenames)))
    Error in UseMethod("mutate") :
    no suitable method for 'mutate' applied to object of las
    I think it becauase las format has such structure

    las
    class : LAS (v1.2 format 1)
    memory : 308.7 Mb
    extent : 637999, 638240.5, 6077999, 6079999 (xmin, xmax, ymin, ymax)
    coord. ref. : NA
    area : 409328 units²
    points : 3.68 million points
    density : 8.99 points/units²

but dataframe from las must be using payload function which i indicated.

but list_df <- filenames %>%

  • purrr::map(., ~readLAS(.x) %>% payload(filenumber = match(.x, filenames)))
    provide error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉南桥 2025-01-29 00:10:11

也许这样的东西

filenames <- list.files(path <- "C:/1/", pattern="*.las", full.names=TRUE)
    
list_df <- filenames %>%
  purrr::map(., ~read.LAS(.x) %>% payload() %>% mutate(filenumber = match(.x, filenames))) 


# If all data has the same structure, you can easily bind them together, i.e.
list_df %>% bind_rows()

Maybe somthing like this

filenames <- list.files(path <- "C:/1/", pattern="*.las", full.names=TRUE)
    
list_df <- filenames %>%
  purrr::map(., ~read.LAS(.x) %>% payload() %>% mutate(filenumber = match(.x, filenames))) 


# If all data has the same structure, you can easily bind them together, i.e.
list_df %>% bind_rows()
星光不落少年眉 2025-01-29 00:10:11

无需循环。 RLAS已经在本地支持读取倍数文件

rlas::read.las(filenames)

No need to loop. rlas already natively support reading multiples files

rlas::read.las(filenames)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文