Points clouds with R
In today’s post, we’ll stay on the holiday theme and show you how to load point clouds in R. The ability to load this type of files have many packages, but the universal tool that contains many features to work with this data, in our opinion, is the package lidR. Let’s install and initialize this package in R (read here). In our exercise, we will use our dataset, which is stored in the format LAZ and which you can download here. And it looks like this 🙂
After loading the package, we start loading the point cloud into the pc variable using the readLAS function, giving the path to the file as an argument:
pc <- readLAS('D:/data.laz')
After loading the file, we can call it:
> lidar class : LAS (LASF v1.2) memory : 169.1 Mb extent : -2.93889 , 4.511044 , -5.501742 , 2.620667 (xmin, xmax, ymin, ymax) area : 48.60705 m2 (convex hull) points : 1927722 points, NA pulses density : 39659.3 points/m2, NA pulses/m2 field names : X Y Z gpstime Intensity ReturnNumber NumberOfReturns ScanDirectionFlag EdgeOfFlightline Classification Synthetic_flag Keypoint_flag Withheld_flag ScanAngle UserData PointSourceID R G B coord. ref. : NA
We then get basic information about the data stored in the file. We can also view the stored points in detail by selecting:
> pc@data X Y Z gpstime Intensity ReturnNumber NumberOfReturns ScanDirectionFlag EdgeOfFlightline Classification Synthetic_flag Keypoint_flag Withheld_flag 1: 4.443461 -3.535939 -20.74261 0 0 0 0 0 0 0 FALSE FALSE FALSE 2: 4.443162 -3.540033 -20.75485 0 0 0 0 0 0 0 FALSE FALSE FALSE 3: 4.441204 -3.546241 -20.76430 0 0 0 0 0 0 0 FALSE FALSE FALSE 4: 4.438651 -3.553199 -20.77274 0 0 0 0 0 0 0 FALSE FALSE FALSE 5: 4.435916 -3.527723 -20.74886 0 0 0 0 0 0 0 FALSE FALSE FALSE --- 1927718: -1.728747 -4.646368 -19.82108 0 0 0 0 0 0 0 FALSE FALSE FALSE 1927719: -1.726810 -4.653493 -19.82575 0 0 0 0 0 0 0 FALSE FALSE FALSE 1927720: -1.708234 -4.716075 -19.85415 0 0 0 0 0 0 0 FALSE FALSE FALSE 1927721: -1.734891 -4.667811 -19.85303 0 0 0 0 0 0 0 FALSE FALSE FALSE 1927722: -1.716344 -4.719571 -19.85127 0 0 0 0 0 0 0 FALSE FALSE FALSE ScanAngle UserData PointSourceID R G B 1: 0 0 0 30976 12288 10752 2: 0 0 0 30976 12544 10496 3: 0 0 0 30976 13312 9728 4: 0 0 0 30976 13312 8960 5: 0 0 0 31744 14080 10496 --- 1927718: 0 0 0 5376 1536 256 1927719: 0 0 0 5632 1280 0 1927720: 0 0 0 8448 3584 2304 1927721: 0 0 0 4864 1024 768 1927722: 0 0 0 6656 2304 2304
The set of points can be plotted using the plot function:
plot(pc)
We can also write the point cloud using the function:
writeLAS(pc,'D:/data_out.laz')
That’s it for this post 🙂 Keep testing the capabilities of today’s featured lidR library.
For the new year 2019, we wish you many new geo-explorations and more.