[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Sep 27 11:10:21 EDT 2010


changeset 36cb459dc36d in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=36cb459dc36d
summary: add a dummy points_by_return value for summaries that do not have any return #s

changeset b9c673e070f9 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=b9c673e070f9
summary: add --split-pts and --split-mb, update to do proper header accounting as well

diffstat:

 apps/las2las2.cpp  |  89 ++++++++++++++++++++++++++++++++++++++++++++---------
 apps/las2oci.cpp   |   3 +-
 apps/laskernel.cpp |  13 ++++++-
 apps/laskernel.hpp |   1 +
 src/utility.cpp    |  14 ++++++++
 5 files changed, 101 insertions(+), 19 deletions(-)

diffs (truncated from 328 to 300 lines):

diff -r 04c21c394645 -r b9c673e070f9 apps/las2las2.cpp
--- a/apps/las2las2.cpp	Fri Sep 24 22:23:29 2010 -0500
+++ b/apps/las2las2.cpp	Mon Sep 27 10:10:09 2010 -0500
@@ -98,7 +98,7 @@
 
     std::ios::openmode m = std::ios::out | std::ios::in | std::ios::binary | std::ios::ate;
 
-    // Write a blank header first
+    // Write a blank PointRecordsByReturnCount first
     std::ofstream ofs(filename.c_str(), m);
     liblas::Writer writer(ofs, header);
     ofs.close();
@@ -114,6 +114,15 @@
         header.SetMax(tree.get<double>("maximum.x"),
                       tree.get<double>("maximum.y"),
                       tree.get<double>("maximum.z"));
+        
+    }     catch (liblas::property_tree::ptree_bad_path const& e) 
+    {
+        std::cerr << "Unable to write header bounds info.  Does the outputted file have any points?";
+        return;
+    }
+
+    try
+    {
 
         for (boost::uint32_t i = 0; i < 5; i++)
         {
@@ -130,10 +139,11 @@
         
     }     catch (liblas::property_tree::ptree_bad_path const& e) 
     {
-        std::cerr << "Unable to write summarized header info.  Does the outputted file have any points?";
+        std::cerr << "Unable to write header point return count info.  Does the outputted file have any points?";
         return;
     }
     
+    
     // Write our updated header with summary info
     std::ofstream ofs2(filename.c_str(), m);
     liblas::Writer writer2(ofs2, header);
@@ -158,7 +168,8 @@
                 liblas::Header & header,
                 std::vector<liblas::FilterPtr>& filters,
                 std::vector<liblas::TransformPtr>& transforms,
-                boost::uint32_t split_size,
+                boost::uint32_t split_mb,
+                boost::uint32_t split_pts,
                 bool verbose,
                 bool min_offset)
 {
@@ -172,7 +183,7 @@
         return false;
     }
     liblas::Reader reader(ifs);
-    liblas::Summary summary;
+    liblas::Summary* summary = new liblas::Summary;
     
     reader.SetFilters(filters);
     reader.SetTransforms(transforms);
@@ -213,7 +224,7 @@
     std::ofstream* ofs = new std::ofstream;
     std::string out = output;
     liblas::Writer* writer = 0;
-    if (!split_size) {
+    if (!split_mb && !split_pts) {
         writer = start_writer(ofs, output, header);
         
     } else {
@@ -233,25 +244,27 @@
     boost::uint32_t i = 0;
     boost::uint32_t const size = header.GetPointRecordsCount();
     
-    boost::int32_t split_bytes_count = 1024*1024*split_size;
+    boost::int32_t split_bytes_count = 1024*1024*split_mb;
+    boost::uint32_t split_points_count = 0;
     int fileno = 2;
 
     while (reader.ReadNextPoint())
     {
+        
         liblas::Point const& p = reader.GetPoint();
-        summary.AddPoint(p);
+        summary->AddPoint(p);
         writer->WritePoint(p);
         if (verbose)
             term_progress(std::cout, (i + 1) / static_cast<double>(size));
         i++;
+        split_points_count++;
 
         split_bytes_count = split_bytes_count - header.GetSchema().GetByteSize();        
-        if (split_bytes_count < 0 && split_size > 0) {
+        if (split_bytes_count < 0 && split_mb > 0 && ! split_pts) {
             // The user specifies a split size in mb, and we keep counting 
             // down until we've written that many points into the file.  
             // After that point, we make a new file and start writing into 
             // that.  
-            // FIXME. No header accounting is done at this time.
             delete writer;
             delete ofs;
             
@@ -260,15 +273,48 @@
             oss << out << "-"<< fileno <<".las";
 
             writer = start_writer(ofs, oss.str(), header);
+
+            ostringstream old_filename;
+            old_filename << out << "-" << fileno - 1 << ".las";
+
+            RepairHeader(*summary, old_filename.str());
+            delete summary;
+            summary =  new liblas::Summary; 
             fileno++;
-            split_bytes_count = 1024*1024*split_size;
+            split_bytes_count = 1024*1024*split_mb;
         }
+
+        if (split_pts > 0 && ! split_mb && split_points_count == split_pts) {
+            // The user specifies a split size in pts, and we keep counting 
+            // down until we've written that many points into the file.  
+            // After that point, we make a new file and start writing into 
+            // that.  
+
+            delete writer;
+            delete ofs;
+            
+            ofs = new std::ofstream;
+            ostringstream oss;
+            oss << out << "-"<< fileno <<".las";
+
+            writer = start_writer(ofs, oss.str(), header);
+
+            ostringstream old_filename;
+            old_filename << out << "-" << fileno - 1 << ".las";
+
+            RepairHeader(*summary, old_filename.str());
+            delete summary;
+            summary =  new liblas::Summary; 
+            fileno++;
+            split_points_count = 0;
+        }
+
     }
     if (verbose)
         std::cout << std::endl;
     
     reader.Reset();
-    liblas::property_tree::ptree pts = summary.GetPTree();
+    liblas::property_tree::ptree pts = summary->GetPTree();
     liblas::property_tree::ptree top;
     top.add_child("summary.header",reader.GetHeader().GetPTree());
     top.add_child("summary.points",pts);
@@ -279,7 +325,8 @@
     delete writer;
     delete ofs;
     
-    RepairHeader(summary, output);
+    RepairHeader(*summary, output);
+    delete summary;
     
     return true;
 }
@@ -302,7 +349,8 @@
 int main(int argc, char* argv[])
 {
 
-    boost::uint32_t split_size;
+    boost::uint32_t split_mb = 0;
+    boost::uint32_t split_pts = 0;
     std::string input;
     std::string output;
     
@@ -318,6 +366,7 @@
 
         po::options_description file_options("las2las2 options");
         po::options_description filtering_options = GetFilteringOptions();
+        po::options_description header_options = GetHeaderOptions();
         po::options_description transform_options = GetTransformationOptions() ;
 
         po::positional_options_description p;
@@ -326,7 +375,8 @@
 
         file_options.add_options()
             ("help,h", "produce help message")
-            ("split,s", po::value<boost::uint32_t>(&split_size)->default_value(0), "Split file into multiple files with each being this size in MB or less. If this value is 0, no splitting is done")
+            ("split-mb", po::value<boost::uint32_t>(&split_mb)->default_value(0), "Split file into multiple files with each being this size in MB or less. If this value is 0, no splitting is done")
+            ("split-pts", po::value<boost::uint32_t>(&split_pts)->default_value(0), "Split file into multiple files with each being this many points or less. If this value is 0, no splitting is done")
             ("input,i", po::value< string >(), "input LAS file")
             ("output,o", po::value< string >(&output)->default_value("output.las"), "output LAS file")
             ("verbose,v", po::value<bool>(&verbose)->zero_tokens(), "Verbose message output")
@@ -334,7 +384,7 @@
 
         po::variables_map vm;
         po::options_description options;
-        options.add(file_options).add(transform_options).add(filtering_options);
+        options.add(file_options).add(header_options).add(transform_options).add(filtering_options);
         po::store(po::command_line_parser(argc, argv).
           options(options).positional(p).run(), vm);
 
@@ -346,6 +396,12 @@
             return 1;
         }
 
+        if (split_pts > 0 && split_mb > 0) 
+        {
+            std::cerr << "Both split-mb and split-pts cannot be used simultaneously." << std::endl; 
+            return 1;
+        }
+
         if (vm.count("input")) 
         {
             input = vm["input"].as< string >();
@@ -380,7 +436,8 @@
                             header, 
                             filters,
                             transforms,
-                            split_size,
+                            split_mb,
+                            split_pts,
                             verbose,
                             bMinOffset
                             );
diff -r 04c21c394645 -r b9c673e070f9 apps/las2oci.cpp
--- a/apps/las2oci.cpp	Fri Sep 24 22:23:29 2010 -0500
+++ b/apps/las2oci.cpp	Mon Sep 27 10:10:09 2010 -0500
@@ -750,6 +750,7 @@
     try {
 
         po::options_description file_options = GetFileOptions();
+        po::options_description header_options = GetHeaderOptions();        
         po::options_description filtering_options = GetFilteringOptions();
         po::options_description transform_options = GetTransformationOptions() ;
         po::options_description hidden_options = GetHiddenOptions();
@@ -762,7 +763,7 @@
 
         po::variables_map vm;
         po::options_description options;
-        options.add(file_options).add(transform_options).add(filtering_options).add(hidden_options);
+        options.add(file_options).add(header_options).add(transform_options).add(filtering_options).add(hidden_options);
         po::store(po::command_line_parser(argc, argv).
         options(options).positional(p).run(), vm);
 
diff -r 04c21c394645 -r b9c673e070f9 apps/laskernel.cpp
--- a/apps/laskernel.cpp	Fri Sep 24 22:23:29 2010 -0500
+++ b/apps/laskernel.cpp	Mon Sep 27 10:10:09 2010 -0500
@@ -99,8 +99,18 @@
     po::options_description transform_options("Transformation options");
 
     transform_options.add_options()
+        ("t_srs", po::value< string >(), "Coordinate system to reproject output LAS file to.  Use --a_srs or verify that your input LAS file has a coordinate system according to lasinfo")
+    ;
+    
+    return transform_options;
+}
+
+po::options_description GetHeaderOptions() 
+{
+    po::options_description transform_options("Header modification options");
+
+    transform_options.add_options()
         ("a_srs", po::value< string >(), "Coordinate system to assign to input LAS file")
-        ("t_srs", po::value< string >(), "Coordinate system to reproject output LAS file to.  Use --a_srs or verify that your input LAS file has a coordinate system according to lasinfo")   
         ("a_vertcs", po::value< std::vector<string> >()->multitoken(), "Override vertical coordinate system information.  Use --a_vertcs \"verticalCSType [citation [verticalDatum [verticalUnits]]]\"\nFor example: --a_vertcs 5703 \"North American Vertical Datum of 1988 (NAVD88)\" 5103 9001")   
         ("offset", po::value< string >(), "A comma-separated list of offsets to set on the output file: \n--offset 0,0,0")
         ("scale", po::value< string >(), "A comma-separated list of scales to set on the output file: \n--scale 0.1,0.1,0.00001")
@@ -112,7 +122,6 @@
     
     return transform_options;
 }
-
 std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose)
 {
     std::vector<liblas::FilterPtr> filters;
diff -r 04c21c394645 -r b9c673e070f9 apps/laskernel.hpp
--- a/apps/laskernel.hpp	Fri Sep 24 22:23:29 2010 -0500
+++ b/apps/laskernel.hpp	Mon Sep 27 10:10:09 2010 -0500
@@ -80,6 +80,7 @@
 
 po::options_description GetFilteringOptions();
 po::options_description GetTransformationOptions();
+po::options_description GetHeaderOptions();
 
 std::vector<liblas::FilterPtr> GetFilters(po::variables_map vm, bool verbose);
 std::vector<liblas::TransformPtr> GetTransforms(po::variables_map vm, bool verbose, liblas::Header& header);
diff -r 04c21c394645 -r b9c673e070f9 src/utility.cpp
--- a/src/utility.cpp	Fri Sep 24 22:23:29 2010 -0500
+++ b/src/utility.cpp	Mon Sep 27 10:10:09 2010 -0500
@@ -50,7 +50,12 @@
 namespace liblas { 
 
 Summary::Summary() :
+    synthetic(0),
+    withheld(0),
+    keypoint(0),
+    count(0),
     first(true)
+    
 {
     classes.assign(0);
     points_by_return.assign(0);


More information about the Liblas-commits mailing list