[Liblas-devel] problem to read las file in chunk-by-chunk via Python+Liblas
gianni lavaredo
gianni.lavaredo at gmail.com
Sun Oct 7 12:40:16 PDT 2012
Dear Members list,
I wrote a script to read in chunk-by-chunk and check if the points are
inside a polygon. When I arrive at the end of the file I get this
message: LASException:
LASError in "LASReader_GetPointAt": point subscript out of range because
the number of points is under the chunk dimension. I cannot figure how to
resolve this problem.
*
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\liblas\file.py", line 358, in
__getitem__
output.append(self.read(i))
File "C:\Python27\lib\site-packages\liblas\file.py", line 305, in read
handle=core.las.LASReader_GetPointAt(self.handle, index),
File "C:\Python27\lib\site-packages\liblas\core.py", line 85, in
check_void_done
raise LASException(msg)
LASException: LASError in "LASReader_GetPointAt": point subscript out of
range
*
For this reasion i used "try:" and "except LASException:" but i get this
error message
*Traceback (most recent call last):
File "<interactive input>", line 4, in <module>
NameError: name 'LASException' is not defined*
some people have some suggestions or help?
Thanks in advance
Gianni
Below i post my code in python
sf = shapefile.Reader(poly)#open shpfile
shapes = sf.shapes()
verts = np.array(shapes[0].points,float)
f = lasfile.File(inFile,None,'r') # open LAS
h = f.header
file_out = lasfile.File(outFile,mode='w',header= h)
chunkSize = 100000
for i in xrange(0,len(f), chunkSize):
try:
chunk = f[i:i+chunkSize]
except LASException:
rem = len(f)-i
chunk = f[i:i+rem]
x,y = [],[]
for p in xrange(len(chunk)):
x.append(chunk[p].x)
y.append(chunk[p].y)
points = np.array(zip(x,y))
index = nonzero(points_inside_poly(points, verts))[0]
if len(index) != 0:
c = [chunk[l] for l in index]
a = [file_out.write(c[m]) for m in xrange(len(c))]
f.close()
file_out.close()
Traceback (most recent call last):
File "<interactive input>", line 4, in <module>
NameError: name 'LASException' is not defined
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/liblas-devel/attachments/20121007/216d8915/attachment.html>
More information about the Liblas-devel
mailing list