[Liblas-devel] 0.9.6 Released

Howard Butler hobu.inc at gmail.com
Wed May 14 16:38:17 EDT 2008


Pete,

I think this may be a bug in the Python bindings, not libLAS itself.   
There are also a number of other small issues I see with your script,  
however.  Comments inline...


On May 14, 2008, at 1:59 PM, Kollasch, Pete [DNR] wrote:

> Howard,
>
> I have encountered a small problem with the Python bindings.  I  
> wrote a Python program to copy only class 2 into a new file.  It  
> also counts points read and written, etc.  The program follows:
>
>
>
>
>
> import math
> from liblas import file
>
> f = file.File('f804.las')
> f.open

open is called for you when you instantiate the liblas.file.File, so  
you shouldn't have to do this manually.  Also, f.open is very  
different than f.open() in Python.  f.open is a reference to the  
function open, f.open() actually *calls* the open method.

>
> h = f.header
> j = 0
> i = 0
>
> for p in f:
>    j += 1
>    if j % 100000 == 0:
>        print '.',
>    if p.classification == 2:
>        #print p.x, p.y, p.z
>        #print 'return ', p.return_number, ' of ', p.number_of_returns
>        #print 'cls = ', p.classification,  '  edge = ',  
> p.flightline_edge
>        i += 1
> print
> print i, ' points will be written'
>

I would try closing and reopening the file you are reading from at  
this point.  It might be possible that the iterator you are using  
isn't actually at the end of the file.  If so, this would be a bug or  
at least some poor behavior of the Python bindings and we'll have to  
think about how to make it better.

f.close()
f.open()

This will effectively reset the reader.

> h.set_pointrecordscount(i)
> g = file.File('outlas4.las', h, 'w')
>
> j = 0
> i = 0
> for p in f:
>    j += 1
>    if j % 100000 == 0:
>        print '.',
>    if p.classification == 2:
>        g.write(p)
>        i += 1
> print
> print i, ' points were written'
>
> f.close
> g.close
>

f.close()
g.close()

closing a file that is opened for write effectively flushes all write  
operations.  Note that you shouldn't have to manually close() the file  
if you are running this program as a shell script because the __del__  
method (think of this as the file.File destructor method) gets called  
when the Python interpreter goes away and liblas.file.File.__del__  
attempts to call close() too.

Another suspicion I have has to do with the header you are copying:

>  Header Size                227
>  Offset to Point Data       229
>  Number Var. Length Records 3


If there are three variable length records, the offset to the point  
data should be much larger than 229.  229 would be the offset if there  
are no VLRs.  This is a bug/feature that I am working on fixing  
currently http://liblas.org/ticket/50

A simple confirmation would be to do

from liblas import header
h = header.Header()
h.dataformat_id = 1  #make sure to write point format 1, which has  
time values.

and use this header for the file you are writing instead of copying it  
from the file you are reading from.

I have been working on a tutorial on the wiki http://liblas.org/wiki/PythonTutorial 
   If you want to register (link for registering is in the top right  
part of the site below the search box) for the site and add your  
experience and code to the site where you think it is appropriate, it  
would be much appreciated :)


I see your lasinfo output says 0.9.5.  Are you running the 0.9.5  
Python bindings too, or is that 0.9.6?  There were numerous fixes for  
0.9.6, especially to the Python bindings.  http://liblas.org/wiki/0.9.6


>
>
>
>
>
> My concern is that when this process is completed, there is a  
> slighltly smaller number of points in the output file than the  
> program or the class counts given by lasinfo -c for the input file  
> indicates.
>
> In my example, the program gives the following output:
>
>>>> ================================ RESTART  
>>>> ================================
>>>>
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> 2028818  points will be written
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2028818 
>   points were written
>>>>
>
>
>
>
>
> After doing this, the lasinfo utility reports on the output file as  
> follows:
>
>
>
>
>
>
>
> C:\allstuff\Software\liblas\0.9.5>.\bin\lasinfo -c outlas4.las
>
> ---------------------------------------------------------
>  Header Summary
> ---------------------------------------------------------
>  File Name: outlas4.las
>  Version:                    1.0
>  Source ID:                  0
>  Reserved:                   0
>  Project ID/GUID:           '00000000-0000-0000-0000-000000000000'
>  System Identifier:         ''
>  Generating Software:       'CPS/RTW LAS Lib v1.08'
>  File Creation Day/Year:    0/0
>  Header Size                227
>  Offset to Point Data       229
>  Number Var. Length Records 3
>  Point Data Format          1
>  Point Data Record Length   28
>  Number of Point Records    2028818
>  Number of Points by Return 3561441 3810 360 9 0
>  Scale Factor X Y Z         0.001000 0.001000 0.001000
>  Offset X Y Z               0.000000 4000000.000000 0.000000
>  Min X Y Z                  395999.999000 4803999.999000 350.069000
>  Max X Y Z                  397999.989000 4805999.989000 383.320000
> end of file encountered
>
> ---------------------------------------------------------
>  Point Inspection Summary
> ---------------------------------------------------------
>  Header Point Count: 2028818
>  Actual Point Count: 2028682
>
>  Minimum and Maximum Attributes (min,max)
> ---------------------------------------------------------
>  Min X,Y,Z:            395999.999000,4803999.998000,350.069000
>  Max X,Y,Z:            397999.989000,4805999.989000,363.256000
>  Bounding Box:         396000.00,4804000.00,397999.99,4805999.99
>  Time:                 496966.080479,498706.670229
>  Return Number:        1,4
>  Return Count:         0,1
>  Flightline Edge:      0,0
>  Intensity:            0,255
>  Scan Direction Flag:  0,0
>  Classification:       2,2
>
>  Number of Points by Return
> ---------------------------------------------------------
>        (0) 2026248     (1) 2159        (2) 269 (3) 6   (4) 0
> Total Points: 2028682
>
>  Number of Returns by Pulse
> ---------------------------------------------------------
>        (1) 2026248     (2) 2159        (3) 269 (4) 6   (5) 0   (6)  
> 0   (7) 0
> Total Pulses: 2028682
>
> Actual number of points by return
> is different from header (actual, header):
>        (2026248,3561441)       (2159,3810)     (269,360)        
> (6,9)   (0,0)
>
>  Point Classifications
> ---------------------------------------------------------
>         2028682 Ground (2)
>
> C:\allstuff\Software\liblas\0.9.5>
>
>
>
> Notice the disparity between the points counted by the program, and  
> inserted in the header, (both 2028818) and the actual point count  
> (2028682).
>
> Is it possible that some buffer is not being flushed?  How do you  
> force it to flush the file?  Any ideas?
>
> Pete




More information about the Liblas-devel mailing list