[Liblas-commits] hg: fix the append point case described by Tim Black on the list...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Dec 2 16:23:08 EST 2010


changeset 16c33aa5bf9d in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=16c33aa5bf9d
summary: fix the append point case described by Tim Black on the list #195

diffstat:

 src/detail/writer/header.cpp |   8 +++++++-
 test/unit/laswriter_test.cpp |  42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletions(-)

diffs (77 lines):

diff -r e45f8f5a4428 -r 16c33aa5bf9d src/detail/writer/header.cpp
--- a/src/detail/writer/header.cpp	Thu Dec 02 14:08:31 2010 -0600
+++ b/src/detail/writer/header.cpp	Thu Dec 02 15:22:53 2010 -0600
@@ -105,7 +105,7 @@
         
         if (points < 0) {
             std::ostringstream oss;
-            oss << "The header's data offset," << m_header.GetDataOffset() 
+            oss << "The header's data offset, " << m_header.GetDataOffset() 
                 <<", is much larger than the size of the file, " << end
                 <<", and something is amiss.  Did you use the right header"
                 <<" offset value?";
@@ -281,7 +281,13 @@
     // If we already have points, we're going to put it at the end of the file.  
     // If we don't have any points,  we're going to leave it where it is.
     if (m_pointCount != 0)
+    {
         m_ofs.seekp(0, std::ios::end);
+    }
+    else
+    {
+        m_ofs.seekp(m_header.GetDataOffset(), std::ios::beg);
+    }
     
 }
 
diff -r e45f8f5a4428 -r 16c33aa5bf9d test/unit/laswriter_test.cpp
--- a/test/unit/laswriter_test.cpp	Thu Dec 02 14:08:31 2010 -0600
+++ b/test/unit/laswriter_test.cpp	Thu Dec 02 15:22:53 2010 -0600
@@ -253,5 +253,47 @@
 
         ensure_equals(ofs, *os); // same streams
     }
+
+    // Test appending to an existing file
+    template<>
+    template<>
+    void to::test<5>()
+    {
+        std::ofstream ofs;
+        ofs.open(tmpfile_.c_str(), std::ios::out | std::ios::binary);
+
+        liblas::Header header;
+      	header.SetDataOffset(759);//Toggle to see the differences
+      	header.SetDataFormatId( liblas::ePointFormat1 );
+      	{
+            liblas::Writer testWriter( ofs, header);
+      	}
+      	
+        ofs.close();
+        
+        ofs.open(tmpfile_.c_str(), std::ios::out | std::ios::binary);
+        {
+            
+    	    liblas::Writer test2Writer( ofs, header);
+
+            size_t count = 500;
+          	for ( size_t i = 0; i < count ; i++ )
+          	{
+                liblas::Point point;
+                point.SetCoordinates( 10 + i, 20 + i, 30 + i );
+                test2Writer.WritePoint( point );
+          	}
+      	}
+      	
+        ofs.close();
+        
+        std::ifstream ifs;
+        ifs.open(tmpfile_.c_str(), std::ios::in | std::ios::binary);
+        liblas::Reader reader(ifs);
+        
+        liblas::Header const& h = reader.GetHeader();
+        ensure_equals("Appended point count does not match", h.GetPointRecordsCount(), 500);
+
+    }
 }
 


More information about the Liblas-commits mailing list