How to fill a liblas.point.Point object using Liblas module?

585 Views Asked by At

I am using liblas in Python to read, manipulate and write a special point format *.las. I have a string as

s = "309437.95 6959999.84 118.98 16 1 1 0 0 1 0 112.992 5.9881"

Where the first is the X, the second the Y, the third element the Z etc.

Using Liblas, I create an empty liblas.point.Point object

>>> pt = liblas.point.Point()
>>> pt
<liblas.point.Point object at 0x0000000005194470>

After that I need to fill this object because is empty.

>>> pt.x, pt.y,pt.z
(0.0, 0.0, 0.0)

probably using

>>> pt.get_x
<bound method Point.get_x of <liblas.point.Point object at 0x0000000005194470>>

I wish to say thanks for all help and suggestion, I really need to solve this step.

from suggestion of Martijn Pieters

    s = "%s %s %s" % (s, value, nh)

    >>> s
    '309437.95 6959999.84 118.98 16 1 1 0 0 1 0 112.992 5.9881'

    # create a liblas.point.Point
    pt = liblas.point.Point()
    pt.x = float(s.split()[0])
    pt.y = float(s.split()[1])
    pt.z = = float(s.split()[11]) # the new Z value
    pt.intensity = = int(s.split()[3])
    pt.return_number= int(s.split()[4])
    pt.number_of_returns = int(s.split()[5])
    pt.scan_direction = int(s.split()[6])
    pt.flightline_edge = int(s.split()[7])
    pt.classification = int(s.split()[8])
    pt.scan_angle = int(s.split()[9])
1

There are 1 best solutions below

9
On

There are raw_x, raw_y and raw_z properties on a Point object; simply set those:

pt.raw_x = 309437.95
pt.raw_y = 6959999.84
pt.raw_z = 118.98

There are also x, y and z properties; it is not immediately clear from the source code what the difference is between the two types:

pt.x = 309437.95
pt.y = 6959999.84
pt.z = 118.98

but the library can produce these objects directly from a .las file for you, can't it? The File class you had trouble with before certainly does return these objects already.

And since you updated to show some code, here is a more readable version of that:

pt = liblas.point.Point()
s = map(float, s.split())
pt.x, pt.y, pt.z = s[0], s[1], s[11]
pt.intensity, pt.return_number = s[3], s[4]
pt.number_of_returns, pt.scan_direction = s[5], s[6]
pt.flightline_edge, pt.classification = s[7], s[8]
pt.scan_angle = s[9]