[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Wed May 12 16:11:06 EDT 2010


changeset 24ef2ec5718c in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=24ef2ec5718c
summary: add LASWriter_GetHeader

changeset 1aaebd2d44da in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=1aaebd2d44da
summary: more better header accounting

diffstat:

 include/liblas/capi/liblas.h |   7 +++++++
 python/liblas/core.py        |   4 ++++
 python/liblas/file.py        |  32 +++++++++++++++++++++++++-------
 src/las_c_api.cpp            |   9 +++++++++
 4 files changed, 45 insertions(+), 7 deletions(-)

diffs (133 lines):

diff -r f9067b68b402 -r 1aaebd2d44da include/liblas/capi/liblas.h
--- a/include/liblas/capi/liblas.h	Wed May 12 11:28:58 2010 -0500
+++ b/include/liblas/capi/liblas.h	Wed May 12 15:10:56 2010 -0500
@@ -898,6 +898,13 @@
 */
 LAS_DLL void LASWriter_Destroy(LASWriterH hWriter);
 
+/** Returns a LASHeaderH representing the header for the file
+ *  @param hWriter the LASWriterH instance
+ *  @return a LASHeaderH representing the header for the file.  NULL is returned 
+ *  in the event of an error.  Use the LASError_GetLastError* methods to check
+ *  in the event of a NULL return.
+*/
+LAS_DLL LASHeaderH LASWriter_GetHeader(const LASWriterH hWriter);
 
 LAS_DLL LASError LASWriter_SetSRS(LASWriterH hWriter, const LASSRSH hSRS);
 LAS_DLL LASError LASWriter_SetInputSRS(LASWriterH hWriter, const LASSRSH hSRS);
diff -r f9067b68b402 -r 1aaebd2d44da python/liblas/core.py
--- a/python/liblas/core.py	Wed May 12 11:28:58 2010 -0500
+++ b/python/liblas/core.py	Wed May 12 15:10:56 2010 -0500
@@ -554,6 +554,10 @@
 las.LASWriter_SetOutputSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
 las.LASWriter_SetOutputSRS.errcheck = check_return
 
+las.LASWriter_GetHeader.restype = ctypes.c_void_p
+las.LASWriter_GetHeader.argtypes = [ctypes.c_void_p]
+las.LASWriter_GetHeader.errcheck = check_void
+
 las.LASWriter_Destroy.argtypes = [ctypes.c_void_p]
 las.LASWriter_Destroy.errcheck = check_void_done
 las.LASWriter_Destroy.restype = None
diff -r f9067b68b402 -r 1aaebd2d44da python/liblas/file.py
--- a/python/liblas/file.py	Wed May 12 11:28:58 2010 -0500
+++ b/python/liblas/file.py	Wed May 12 15:10:56 2010 -0500
@@ -95,13 +95,20 @@
         """
         self.filename = os.path.abspath(filename)
         self._header = None
-        if header:
-            self._header = core.las.LASHeader_Copy(header.handle)
+        self.ownheader = True
+
+        # import pdb;pdb.set_trace()
+        if header != None:
+            
+            self.ownheader = False
+            self._header = header.handle
+        
         self.handle = None
         self._mode = mode.lower()
         self.in_srs = in_srs
         self.out_srs = out_srs
 
+
         #check in the registry if we already have the file open
         if mode == 'r':
             for f in files['write'] + files['append']:
@@ -122,6 +129,7 @@
     def open(self):
         """Open the file for processing, called by __init__
         """
+        
         if self._mode == 'r' or self._mode == 'rb':
 
             if self._header == None:
@@ -130,7 +138,7 @@
             else:
                 self.handle = \
                 core.las.LASReader_CreateWithHeader(self.filename,
-                                                        self._header.handle)
+                                                        self._header)
 
             self.mode = 0
             try:
@@ -149,6 +157,7 @@
 
             if self._header == None:
                 self._header = core.las.LASHeader_Create()
+
             self.handle = core.las.LASWriter_Create(self.filename,
                                                     self._header,
                                                     1)
@@ -205,8 +214,10 @@
             except:
                 files['write'].remove(self.filename)
             core.las.LASWriter_Destroy(self.handle)
-
-        core.las.LASHeader_Destroy(self._header)
+        
+        if self.ownheader:
+            core.las.LASHeader_Destroy(self._header)
+            
         self._header = None
         self.handle = None
 
@@ -246,9 +257,16 @@
 
     def get_header(self):
         """Returns the liblas.header.Header for the file"""
-        if self._header:
-            return lasheader.Header(handle=self._header, copy=True)
+        if not self.handle:
+            return None
+        
+        if self.mode == 0:
+            return lasheader.Header(handle=core.las.LASReader_GetHeader(self.handle))
+        else:
+            return lasheader.Header(handle=core.las.LASWriter_GetHeader(self.handle))
+
         return None
+
     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."""
diff -r f9067b68b402 -r 1aaebd2d44da src/las_c_api.cpp
--- a/src/las_c_api.cpp	Wed May 12 11:28:58 2010 -0500
+++ b/src/las_c_api.cpp	Wed May 12 15:10:56 2010 -0500
@@ -1513,6 +1513,15 @@
 
     return LE_None;
 }
+
+LAS_DLL LASHeaderH LASWriter_GetHeader(const LASWriterH hWriter)
+{
+    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_GetHeader", NULL);
+
+    liblas::Header header = ((liblas::Writer*) hWriter)->GetHeader();
+    return (LASHeaderH) new liblas::Header( header );
+}
+
 LAS_DLL void LASError_Print(const char* message) {
 
     char* errmsg= NULL;


More information about the Liblas-commits mailing list