[Liblas-devel] LAS I/O and header question?

Howard Butler hobu.inc at gmail.com
Fri Oct 10 20:18:25 EDT 2008


On Oct 10, 2008, at 3:12 PM, Jason Woolard wrote:

> hi everyone,
>
> I just got the library running in Python and I have a quick question  
> for anyone out there. I've had success with the tutorial but a  
> little trouble implementing some things. Just for starters I was  
> trying to read through a LAS file, extract some points by elevation,  
> update the header and write a new file out. I can extract the points  
> I want or update the header I just can make them work together. I  
> just joined the group a few days ago so I apologize if I'm missing  
> something obvious here.
>
> Here is the version of the script that will return the points but  
> not update the header. I can modify this slightly based on the  
> tutorial to return a modified header but the data points seem to be  
> in a different coord system or have a funky scale factor applied.
>
> Thanks in advance for any insight.
>
> import os
> from liblas import file
> from liblas import point
> from liblas import header
>
> infile = file.File('C:\\liblas_test\\debug.las',mode='r')
> outfile = file.File('C:\\liblas_test\\outlas.las',mode='w',header =  
> infile.header)
>
> #Update records in LAS file
>
> outfile.header.set_dataformatid(1)
> outfile.header.set_majorversion(1)
> outfile.header.set_minorversion(0)
> outfile.header.set_softwareid('Test')
>

A gotcha here is you can't change these things after creating  
outfile.  Because of the sequential nature of .LAS files, when you do  
file.File(mode='w', header=myheader), myheader is copied into the  
file.  Updating the header with new values after that point will have  
no effect.

The header business is important because the scale factors are applied  
as points are read out of and written into the file.


This example with the srs.las file in our tests works or me.  Can you  
try something similar?


import liblas

f = liblas.file.File('/Users/hobu/dev/svn/liblas/trunk/test/data/ 
srs.las',mode='r')

h = f.header
h.dataformat_id = 1
h.majorversion = 1
h.minorversion = 0
h.software_id = 'Test'

f2 = liblas.file.File('junk.las',mode='w', header=h)

# this will fetch a copy of the header from the file
# it will not cause the file's header to be reread
print f2.header.dataformat_id,  
f2.header.majorversion,f2.header.minorversion ,f2.header.software_id

for p in f:
     p2 = liblas.point.Point()
     p2.x, p2.y, p2.z = p.x, p.y, p.z

     f2.write(p2)

f2.close()
f.close()

f = liblas.file.File('/Users/hobu/dev/svn/liblas/trunk/test/data/ 
srs.las',mode='r')
f2 = liblas.file.File('junk.las',mode='r')

print f2.header.software_id

inputs = []
for p in f:
     inputs.append(p)

outputs = []
for p in f2:
     outputs.append(p)

# this doesn't throw any exception for me
for i in range(len(inputs)):
     if not inputs[i].x == outputs[i].x and \
        not inputs[i].y == outputs[i].y and \
        not inputs[i].z == outputs[i].z:
        raise Exception("Points were not equal!")






More information about the Liblas-devel mailing list