[Liblas-commits] hg: 3 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Apr 1 23:20:00 EDT 2010
changeset 762733fd6827 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=762733fd6827
summary: update for new defaults
changeset 08abc5afc573 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=08abc5afc573
summary: add more docs
changeset 9d6ed479de3d in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=9d6ed479de3d
summary: fix up 1.0 pad byte accounting for the append case
diffstat:
doc/python/classes.txt | 6 ++-
doc/python/tutorial.txt | 2 +-
include/liblas/lasheader.hpp | 1 +
python/liblas/file.py | 58 ++++++++++++++++++++++++++++++--
python/tests/File.txt | 76 ++++++++++++++++++++++++++++++++++++++-----
python/tests/Format.txt | 6 ++-
python/tests/VLR.txt | 5 +-
src/detail/writer/header.cpp | 13 ++++++-
src/detail/writer/point.cpp | 1 -
src/detail/writer/writer.cpp | 1 -
src/lasheader.cpp | 36 +++++++++-----------
11 files changed, 159 insertions(+), 46 deletions(-)
diffs (truncated from 455 to 300 lines):
diff -r 59eba98aa75c -r 9d6ed479de3d doc/python/classes.txt
--- a/doc/python/classes.txt Thu Apr 01 14:14:47 2010 -0500
+++ b/doc/python/classes.txt Thu Apr 01 22:14:13 2010 -0500
@@ -1,12 +1,14 @@
.. _class_documentation:
****************************************************************
- libLAS Python Class Documentation
+ Python Class Documentation
****************************************************************
.. autoclass:: liblas.point.Point
:members: x, y, z, time, scan_angle, scan_direction, scan_flags, flightline_edge, number_of_returns, return_number
-
+
+.. autoclass:: liblas.file.File
+ :members: __init__, close, header, read, write, __iter__, __getitem__
# .. doxygenclass:: liblas::Color
# :project: class
diff -r 59eba98aa75c -r 9d6ed479de3d doc/python/tutorial.txt
--- a/doc/python/tutorial.txt Thu Apr 01 14:14:47 2010 -0500
+++ b/doc/python/tutorial.txt Thu Apr 01 22:14:13 2010 -0500
@@ -1,7 +1,7 @@
.. _python_tutorial:
*********************************************
-libLAS Python Tutorial
+Python Tutorial
*********************************************
This basic tutorial explains how to use libLAS to read and write
diff -r 59eba98aa75c -r 9d6ed479de3d include/liblas/lasheader.hpp
--- a/include/liblas/lasheader.hpp Thu Apr 01 14:14:47 2010 -0500
+++ b/include/liblas/lasheader.hpp Thu Apr 01 22:14:13 2010 -0500
@@ -348,6 +348,7 @@
//
void Init();
void ClearGeoKeyVLRs();
+ void UpdatePointFormat();
//
// Private data members
diff -r 59eba98aa75c -r 9d6ed479de3d python/liblas/file.py
--- a/python/liblas/file.py Thu Apr 01 14:14:47 2010 -0500
+++ b/python/liblas/file.py Thu Apr 01 22:14:13 2010 -0500
@@ -52,7 +52,21 @@
class File(object):
def __init__(self, filename, header=None, mode='r', in_srs = None, out_srs = None):
-
+ """Instantiate a file object to represent an LAS file. Valid modes are \
+ "r" for read, "w" for write, and "w+" for append. Setting in_srs will override \
+ the file's header SRS, and setting an out_srs will allow the points to be \
+ reprojected on-the-fly to the out_srs coordinate system as they are read/written.
+
+ To open a file in write mode, you must provide a liblas.header.Header instance
+ which will be immediately written to the file. If you provide a header instance
+ in read mode, the values of that header will be used in place of those in the
+ actual file.
+
+ >>> from liblas import file
+ >>> f = file.File('file.las',mode='r')
+ >>> for p in f:
+ ... print 'X,Y,Z: ', p.x, p.y, p.z
+ """
self.filename = os.path.abspath(filename)
self._header = header
self.handle = None
@@ -74,6 +88,8 @@
self.open()
def open(self):
+ """Open the file for processing, called by __init__
+ """
if self._mode == 'r' or self._mode =='rb':
if not self._header:
@@ -121,6 +137,8 @@
self.close()
def close(self):
+ """Closes the LAS file
+ """
if self.mode == 0 :
core.las.LASReader_Destroy(self.handle)
files['read'].remove(self.filename)
@@ -164,7 +182,8 @@
"""Returns the liblas.header.Header for the file"""
return self._header
def set_header(self, header):
-
+ """Sets the liblas.header.Header for the file. If the file is in \
+ append mode, the header will be overwritten in the file."""
# append mode
if mode == 2:
core.las.LASWriter_Destroy(self.handle)
@@ -172,13 +191,24 @@
self._header = header
return True
raise core.LASException("The header can only be set after file creation for files in append mode")
- header = property(get_header)
+ doc = """Get or set the file's liblas.header.Header If the file is in \
+ append mode, the header will be overwritten in the file."""
+ header = property(get_header, set_header, None, doc)
- def read(self, location):
+ def read(self, index):
+ """Reads the point at the given index"""
if self.mode == 0:
- return point.Point(handle=core.las.LASReader_GetPointAt(self.handle, location), copy=True)
+ return point.Point(handle=core.las.LASReader_GetPointAt(self.handle, index), copy=True)
def __iter__(self):
+ """Iterator support (read mode only)
+
+ >>> points = []
+ >>> for i in f:
+ ... points.append(i)
+ ... print i # doctest: +ELLIPSIS
+ <liblas.point.Point object at ...>
+ """
if self.mode == 0:
self.at_end = False
p = core.las.LASReader_GetNextPoint(self.handle)
@@ -191,10 +221,28 @@
self.close()
self.open()
+ def __getitem__(self, index):
+ """Index and slicing support (implemented using read())"""
+ try:
+ index.stop
+ except AttributeError:
+ return self.read(index)
+
+ output = []
+ if index.step:
+ step = index.step
+ else:
+ step = 1
+ for i in range(index.start, index.stop, step):
+ output.append(self.read(i))
+
+ return output
def __len__(self):
+ """Returns the number of points in the file according to the header"""
return self.header.point_records_count
def write(self, pt):
+ """Writes the point to the file if it is append or write mode."""
if not isinstance(pt, point.Point):
raise core.LASException('cannot write %s, it must be of type liblas.point.Point' % pt)
if self.mode == 1 or self.mode == 2:
diff -r 59eba98aa75c -r 9d6ed479de3d python/tests/File.txt
--- a/python/tests/File.txt Thu Apr 01 14:14:47 2010 -0500
+++ b/python/tests/File.txt Thu Apr 01 22:14:13 2010 -0500
@@ -7,7 +7,7 @@
>>> f.header.point_records_count
8L
- >>> header = f.header
+ >>> h = f.header
>>> p = f.read(0)
>>> p.x, p.y, p.z
(630262.30000000005, 4834500.0, 51.530000000000001)
@@ -36,6 +36,13 @@
<liblas.point.Point object at ...>
<liblas.point.Point object at ...>
+ >>> f[0]
+ <liblas.point.Point object at ...>
+
+ >>> out = f[0:3]
+ >>> len(out)
+ 3
+
>>> len(points)
8
@@ -69,10 +76,10 @@
>>> del f
- >>> f = file.File('junk.las', mode="w", header=header)
- >>> sum(header.offset)
+ >>> f = file.File('junk.las', mode="w", header=h)
+ >>> sum(h.offset)
0.0
- >>> header.min
+ >>> h.min
[630262.30000000005, 4834500.0, 50.899999999999999]
>>> for i in points:
@@ -87,7 +94,7 @@
>>> f.header
>>> del f
- >>> f = file.File('junk.las', mode='w+', header=header)
+ >>> f = file.File('junk.las', mode='w+', header=h)
>>> for i in points:
... f.write(i)
@@ -118,12 +125,11 @@
>>> del f3
-The header's offset will change +=2 because of the 1.0
-requirement to write pad bytes at the end of the header
+
>>> f = file.File('junk2.las')
>>> f.header.data_offset
- 1026L
+ 1024L
>>> points = []
>>> for i in f:
@@ -193,13 +199,63 @@
630323.57
630320.95
630280.89
+
+
+The header's offset will change +=2 if there isn't enough room in the
+header after you subtract the VLRs
+
+ >>> from liblas import header
+ >>> h2 = header.Header()
+ >>> h2.data_offset = 227
+ >>> h2.minor_version = 0
+ >>> f4 = file.File('junk4.las',mode='w',header=h2)
+
+ >>> f4.header.data_offset
+ 227L
+
+ >>> for i in points:
+ ... f4.write(i)
+
+ >>> f4.close()
+
+ >>> del f4
+
+
+ >>> f = file.File('junk4.las')
+ >>> f.header.data_offset
+ 229L
+
+ >>> points = []
+ >>> for i in f:
+ ... points.append(i)
+ ... print i # doctest: +ELLIPSIS
+ <liblas.point.Point object at ...>
+ <liblas.point.Point object at ...>
+ <liblas.point.Point object at ...>
+ <liblas.point.Point object at ...>
+ <liblas.point.Point object at ...>
+ <liblas.point.Point object at ...>
+ <liblas.point.Point object at ...>
+ <liblas.point.Point object at ...>
+
+ >>> for g in points:
+ ... print round(g.x, 6)
+ 630262.3
+ 630282.45
+ 630300.07
+ 630346.82
+ 630327.57
+ 630323.57
+ 630320.95
+ 630280.89
>>> import os
>>> os.remove('junk.las')
>>> os.remove('junk2.las')
>>> os.remove('junk3.las')
-
- >>> f = file.File('junk.las', mode="w", header=header)
+ >>> os.remove('junk4.las')
+
+ >>> f = file.File('junk.las', mode="w", header=h)
>>> import liblas.core
>>> liblas.core.las.LASWriter_Destroy(f.handle)
>>> print 'destroyed once'
diff -r 59eba98aa75c -r 9d6ed479de3d python/tests/Format.txt
--- a/python/tests/Format.txt Thu Apr 01 14:14:47 2010 -0500
+++ b/python/tests/Format.txt Thu Apr 01 22:14:13 2010 -0500
@@ -9,7 +9,7 @@
>>> f = h.format
>>> f.major, f.minor
- (1, 0)
+ (1, 2)
>>> f.size
28L
@@ -29,7 +29,9 @@
>>> f.major
1
More information about the Liblas-commits
mailing list