1

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])
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Gianni Spear
  • 7,033
  • 22
  • 82
  • 131

1 Answers1

1

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]
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Yes it work. Maybe it's not elegant code my i did in these way (see on the top) – Gianni Spear Oct 10 '12 at 17:05
  • 1
    @Gianni: It's a method used by the `x` property; it's the function called when you access `pt.x`. – Martijn Pieters Oct 10 '12 at 17:15
  • for instance. If i wish to create a new field (field x,y,z, and h). Do i able to do this? – Gianni Spear Oct 10 '12 at 17:16
  • 1
    @Gianni: Sure, but I suspect you want to learn some more Python first. :-) See the [`property` documentation](http://docs.python.org/library/functions.html#property) for how that particular trick works. – Martijn Pieters Oct 10 '12 at 17:17
  • sry for interupt you discussion, but i think that in liblas module we already have methods which parse strings like this – Ishikawa Yoshi Oct 10 '12 at 17:18
  • @IshikawaYoshi: It already does, but the OP seems to have a need to bypass those (note the assignment of the last value to the `z` property). – Martijn Pieters Oct 10 '12 at 17:19
  • thanks Martijn Pieters. Currently i need (and i like) to work with Python/Liblas. I always code with R but i start to understand and appreciate the philosophy under python. THANK ALWAYS FOR YOUR HELP. I hope to return one day your help (maybe in front a good wine or beer) – Gianni Spear Oct 10 '12 at 17:21
  • @MartijnPieters: Please could you correct t.x, pt.y, pt.z = s[0], s[1], s[12]in t.x, pt.y, pt.z = s[0], s[1], s[11], changing 12 with 11. Because the s has 12 element and the last one is in 11 position – Gianni Spear Oct 10 '12 at 17:35
  • @Gianni: There you go. That's the kind of small correction you could make in my post, albeit that it may not make it through the suggested edit queue.. – Martijn Pieters Oct 10 '12 at 17:37