Search code examples
rgeospatiallidarlaslidr

How to convert lidar format las to data.frame?


Lidar data is simply 3d coordinates, usually in las file format. Сontent example

library(rgdal)
library(raster)
library(tmap)
library(tmaptools)
library(lidR)
library(RStoolbox)
las_cat <- readLAScatalog("C:/1/078-638.las")
summary(las_cat)
opt_chunk_size(las_cat) <- 500
plot(las_cat, chunk_pattern = TRUE)
las_cat
#> class       : LAScatalog (v1.2 format 1)
#> extent      : 637999, 638240.5, 6077999, 6079999 (xmin, xmax, ymin, ymax)
#> coord. ref. : NA 
#> area        : 483081.1 units²
#> points      : 3.68 million points
#> density     : 7.6 points/units²
#> density      : 5.6 pulses/units²
#> num. files  : 1

Is there a way to get point coordinates in a typical data.frame for R? As an example we can use data from this http://data.wvgis.wvu.edu/elevation/. Also, is there a way to get the angle of reflection, the number of reflections in the data.frame from the lidar file?


Solution

  • Please find below one possible solution to get a data.table,data.frame with all the information. You can use as.data.frame() to get a pure data.frame but a data.table is a data.frame

    Reprex

    NB: I used a .las dataset built in the lidR library as it is more convenient.

    • The example dataset from lidR
    library(lidR)
    
    LASfile <- system.file("extdata", "example.laz", package="rlas")
    las <- readLAS(LASfile)
    
    summary(las)
    #> class        : LAS (v1.0 format 1)
    #> memory       : 21.2 Kb 
    #> extent       : 339002.9, 339015.1, 5248000, 5248001 (xmin, xmax, ymin, ymax)
    #> coord. ref.  : NAD83 / UTM zone 17N 
    #> area         : 16 m²
    #> points       : 30  points
    #> density      : 1.88 points/m²
    #> density      : 1.62 pulses/m²
    #> File signature:           LASF 
    #> File source ID:           0 
    #> Global encoding:
    #>  - GPS Time Type: GPS Week Time 
    #>  - Synthetic Return Numbers: no 
    #>  - Well Know Text: CRS is GeoTIFF 
    #>  - Aggregate Model: false 
    #> Project ID - GUID:        00000000-0000-0000-0000-000000000000 
    #> Version:                  1.0
    #> System identifier:        LAStools (c) by rapidlasso GmbH 
    #> Generating software:      las2las (version 201011) 
    #> File creation d/y:        343/2011
    #> header size:              227 
    #> Offset to point data:     323 
    #> Num. var. length record:  1 
    #> Point data format:        1 
    #> Point data record length: 28 
    #> Num. of point records:    30 
    #> Num. of points by return: 26 4 0 0 0 
    #> Scale factor X Y Z:       0.001 0.001 0.001 
    #> Offset X Y Z:             6e+05 6500000 0 
    #> min X Y Z:                339002.9 5248000 973.145 
    #> max X Y Z:                339015.1 5248001 978.345 
    #> Variable Length Records (VLR):
    #>    Variable Length Record 1 of 1 
    #>        Description: by LAStools of rapidlasso GmbH 
    #>        Tags:
    #>           Key 1024 value 1 
    #>           Key 3072 value 26917 
    #>           Key 3076 value 9001 
    #>           Key 4099 value 9001 
    #> Extended Variable Length Records (EVLR):  void
    
    • Suggested code
    payload(las)
    
    • Output
    #>          Z  gpstime Intensity ReturnNumber NumberOfReturns ScanDirectionFlag
    #> 1  975.589 269347.3        82            1               1                 1
    #> 2  974.778 269347.3        54            1               1                 1
    #> 3  974.471 269347.3        27            2               2                 1
    #> 4  974.025 269347.3        55            2               2                 1
    #> 5  974.298 269347.3       117            1               1                 0
    #> 6  974.985 269347.3        81            1               1                 0
    #> 7  975.182 269347.3        84            1               1                 1
    #> 8  974.434 269347.3       104            1               1                 1
    #> 9  974.159 269347.3        91            1               1                 1
    #> 10 973.145 269347.3        99            1               1                 1
    #> 11 976.739 269347.5        87            1               1                 1
    #> 12 976.823 269347.5        83            1               1                 1
    #> 13 977.227 269347.5        87            1               1                 1
    #> 14 975.873 269347.5        87            1               1                 1
    #> 15 975.782 269347.5       107            1               1                 1
    #> 16 975.353 269347.5        76            1               1                 1
    #> 17 974.704 269347.5       113            1               1                 1
    #> 18 977.170 269347.5        64            1               1                 0
    #> 19 977.757 269347.5        89            1               1                 0
    #> 20 978.212 269347.5        98            1               1                 0
    #> 21 978.309 269347.5        50            1               2                 0
    #> 22 974.816 269347.5        31            2               2                 0
    #> 23 978.345 269347.5        51            1               2                 1
    #> 24 974.824 269347.5        32            2               2                 1
    #> 25 978.014 269347.5        85            1               1                 1
    #> 26 977.781 269347.5        94            1               1                 1
    #> 27 976.455 269347.5        78            1               1                 1
    #> 28 976.313 269347.7        71            1               1                 1
    #> 29 975.735 269347.7        75            1               1                 1
    #> 30 975.674 269347.7       106            1               1                 1
    #>    EdgeOfFlightline Classification Synthetic_flag Keypoint_flag Withheld_flag
    #> 1                 1              1          FALSE         FALSE         FALSE
    #> 2                 0              1          FALSE         FALSE         FALSE
    #> 3                 0              1          FALSE         FALSE         FALSE
    #> 4                 0              1          FALSE         FALSE         FALSE
    #> 5                 0              1          FALSE         FALSE         FALSE
    #> 6                 0              1          FALSE         FALSE         FALSE
    #> 7                 1              1          FALSE         FALSE         FALSE
    #> 8                 0              1          FALSE         FALSE         FALSE
    #> 9                 0              1          FALSE         FALSE         FALSE
    #> 10                0              1          FALSE         FALSE         FALSE
    #> 11                1              1          FALSE         FALSE         FALSE
    #> 12                0              1          FALSE         FALSE         FALSE
    #> 13                0              1          FALSE         FALSE         FALSE
    #> 14                0              1          FALSE         FALSE         FALSE
    #> 15                0              1          FALSE         FALSE         FALSE
    #> 16                0              1          FALSE         FALSE         FALSE
    #> 17                0              1          FALSE         FALSE         FALSE
    #> 18                0              1          FALSE         FALSE         FALSE
    #> 19                0              1          FALSE         FALSE         FALSE
    #> 20                0              1          FALSE         FALSE         FALSE
    #> 21                0              1          FALSE         FALSE         FALSE
    #> 22                0              2          FALSE         FALSE         FALSE
    #> 23                1              1          FALSE         FALSE         FALSE
    #> 24                1              2          FALSE         FALSE         FALSE
    #> 25                0              1          FALSE         FALSE         FALSE
    #> 26                0              1          FALSE         FALSE         FALSE
    #> 27                0              1          FALSE         FALSE         FALSE
    #> 28                1              1          FALSE         FALSE         FALSE
    #> 29                0              2          FALSE         FALSE         FALSE
    #> 30                0              1          FALSE         FALSE         FALSE
    #>    ScanAngleRank UserData PointSourceID        X       Y
    #> 1            -21       32            17 339002.9 5248001
    #> 2            -21       32            17 339003.0 5248000
    #> 3            -21       32            17 339002.9 5248000
    #> 4            -21       32            17 339002.9 5248000
    #> 5            -21       32            17 339003.6 5248000
    #> 6            -21       32            17 339003.5 5248000
    #> 7            -21       32            17 339003.6 5248000
    #> 8            -21       32            17 339003.7 5248000
    #> 9            -21       32            17 339003.6 5248000
    #> 10           -21       32            17 339003.7 5248000
    #> 11           -22       32            17 339009.6 5248001
    #> 12           -22       32            17 339009.5 5248001
    #> 13           -22       32            17 339009.2 5248000
    #> 14           -22       32            17 339009.4 5248001
    #> 15           -22       32            17 339009.3 5248000
    #> 16           -22       32            17 339009.3 5248000
    #> 17           -22       32            17 339009.3 5248000
    #> 18           -22       32            17 339009.5 5248000
    #> 19           -22       32            17 339009.5 5248000
    #> 20           -22       32            17 339009.5 5248000
    #> 21           -22       32            17 339009.6 5248000
    #> 22           -22       32            17 339010.7 5248001
    #> 23           -22       32            17 339009.6 5248000
    #> 24           -22       32            17 339010.6 5248001
    #> 25           -22       32            17 339009.5 5248000
    #> 26           -22       32            17 339009.4 5248000
    #> 27           -22       32            17 339009.7 5248000
    #> 28           -22       32            17 339015.1 5248000
    #> 29           -22       32            17 339015.1 5248000
    #> 30           -22       32            17 339015.0 5248000
    

    Created on 2022-03-18 by the reprex package (v2.0.1)