3

I am working in both r and python to process lidar data with .las format. One thing I have noticed is that the x,y co-ordinate when working with laspy is different than x,y co-ordinate when using lidr.

import laspy
inFile = laspy.read ("lidar.laz")
print(inFile.X[0],infile.Y[0])

If i use the code above than i get this value (286999990,191724100)

But then when i switched to lidr in r

library("lidR")
las <- readLAS("lidar.laz")
X <- las$X[1]
Y <- las$Y[1]

If i use this code on the same data i get (368230.8,5807508)

Both code have been run on the same dataset. What can cause the co-ordinates to be different

2 Answers 2

3

Using the Megaplot.laz file from the lidR package I see:

In python:

inFile.X[0]
#> 68499216

In R:

las$X[1]
#> [1] 684992.2

The R data has a scale and offset parameter for coordinates, and if these are applied to the Python values you get the R values:

las$`X scale factor`
#> [1] 0.01
las$`X offset`
#> [1] 0

In other words, the Python values are (0.01 * R_X_Values) + 0 or possibly the offset is done first: (0.01 * (R_X_values - 0)).

I think R's data is correct here for the values of the spatial coordinates since it presents them as UTM Zone 17N coords:

las
#> class        : LAS (v1.2 format 1)
#> memory       : 6.2 Mb 
#> extent       : 684766.4, 684993.3, 5017773, 5018007 (xmin, xmax, ymin, ymax)
#> coord. ref.  : NAD83 / UTM zone 17N 
#> area         : 51572 m²
#> points       : 81.6 thousand points
#> density      : 1.58 points/m²
#> density      : 1.08 pulses/m²

If you get the xyz property in Python you'll get the scaled and offset values:

>>> inFile.xyz
array([[6.84992160e+05, 5.01800692e+06, 1.73000000e+01],
       [6.84992570e+05, 5.01800611e+06, 1.70300000e+01],
       [6.84992990e+05, 5.01800538e+06, 1.61400000e+01],
       ...,
       [6.84946360e+05, 5.01800520e+06, 2.40000000e+00],
       [6.84947430e+05, 5.01800608e+06, 0.00000000e+00],
       [6.84947180e+05, 5.01800671e+06, 8.60000000e-01]])

So I think .X and .Y properties in Python are the raw values. Check this with your data to see what the scale and offset are in R.

2

According to the documentation of laspy

Laspy can actually scale the x, y, and z dimensions for you. Upper case dimensions (las_file.X, las_file.Y, las_file.Z) give the raw integer dimensions, while lower case dimensions (las_file.x, las_file.y, las_file.z) give the scaled value. Both methods support assignment as well, although due to rounding error assignment using the scaled dimensions is not recommended.

In python you printed the raw integers stored in the file. lidR returns the scaled and offseted values (i.e. real coordinates in the file CRS) and does not give direct access to raw integers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.