[Liblas-commits] hg-main-tree: clean up oracle reader/writer processes

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Jul 20 13:34:25 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/da0ec6dad709
changeset: 887:da0ec6dad709
user:      Howard Butler <hobu.inc at gmail.com>
date:      Wed Jul 20 12:32:00 2011 -0500
description:
clean up oracle reader/writer processes
Subject: hg-main-tree: reapply 8b71a4ec238e

details:   http://hg.libpc.orghg-main-tree/rev/cd1f7f438601
changeset: 888:cd1f7f438601
user:      Howard Butler <hobu.inc at gmail.com>
date:      Wed Jul 20 12:34:15 2011 -0500
description:
reapply 8b71a4ec238e

diffstat:

 apps/pc2pc.cpp             |  118 ++++++++++++++------------------------------
 src/drivers/oci/Writer.cpp |   39 ++++++++++++++-
 2 files changed, 76 insertions(+), 81 deletions(-)

diffs (240 lines):

diff -r 50f7d0d2b5fa -r cd1f7f438601 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp	Wed Jul 20 10:25:35 2011 -0500
+++ b/apps/pc2pc.cpp	Wed Jul 20 12:34:15 2011 -0500
@@ -147,53 +147,42 @@
         boost::property_tree::read_xml(m_xml, load_tree);
         
         boost::property_tree::ptree oracle_options = load_tree.get_child("pdal.drivers.oci.writer");
+        boost::property_tree::ptree las_options = load_tree.get_child("pdal.drivers.las");
     
         pdal::OptionsOld options(oracle_options);
         
-        boost::property_tree::ptree in_srs_options = oracle_options.get_child("spatialreference");
+        boost::property_tree::ptree in_srs_options = las_options.get_child("spatialreference");
         std::string out_wkt = in_srs_options.get<std::string>("userinput");
-        boost::property_tree::ptree las_options = load_tree.get_child("pdal.drivers.las");
-        boost::property_tree::ptree out_srs_options = las_options.get_child("spatialreference");
+        boost::property_tree::ptree out_srs_options = oracle_options.get_child("spatialreference");
         std::string in_wkt = out_srs_options.get<std::string>("userinput");
+        
         pdal::SpatialReference in_ref(in_wkt);
         pdal::SpatialReference out_ref(out_wkt);
                 
         boost::property_tree::ptree& tree = options.GetPTree();
         
         boost::uint32_t capacity = tree.get<boost::uint32_t>("capacity");
-        
-        
-        pdal::filters::CacheFilter cache(reader, 1, capacity);
-        pdal::filters::Chipper chipper(cache, capacity);
-        pdal::filters::ByteSwapFilter swapper(chipper);
-
-     
-        pdal::filters::ScalingFilter scalingFilter(swapper, false);
-
-        pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, in_ref, out_ref);
-
-        // convert to ints, using custom scale factor
-        
         double scalex = oracle_options.get<double>("scale.x");
         double scaley = oracle_options.get<double>("scale.y");
         double scalez = oracle_options.get<double>("scale.z");
 
         double offsetx = oracle_options.get<double>("offset.x");
         double offsety = oracle_options.get<double>("offset.y");
-        double offsetz = oracle_options.get<double>("offset.z");
-
+        double offsetz = oracle_options.get<double>("offset.z");        
+        
+        pdal::filters::CacheFilter cache(reader, 1, capacity);
+        // pdal::filters::Chipper chipper(cache, capacity);
+        pdal::filters::ScalingFilter scalingFilter(cache, false);
+        pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, in_ref, out_ref);
         pdal::filters::ScalingFilter descalingFilter(   reprojectionFilter, 
                                                         scalex, offsetx,
                                                         scaley, offsety, 
                                                         scalez, offsetz, 
                                                         true);
         
+        pdal::filters::ByteSwapFilter swapper(descalingFilter);
         pdal::drivers::oci::Writer writer(descalingFilter, options);
 
-        // pdal::filters::CacheFilter cache(reader, 1, capacity);
-        // pdal::filters::Chipper chipper(cache, capacity);
-        // pdal::drivers::oci::Writer writer(chipper, options);
-
         writer.write(numPoints);
         boost::property_tree::ptree output_tree;
         // output_tree.put_child(writer.getName(), options.GetPTree());
@@ -216,73 +205,44 @@
         boost::property_tree::ptree las_options = load_tree.get_child("pdal.drivers.las");
         boost::property_tree::ptree srs_options = las_options.get_child("spatialreference");
         
+        double scalex = las_options.get<double>("scale.x");
+        double scaley = las_options.get<double>("scale.y");
+        double scalez = las_options.get<double>("scale.z");
+
+        double offsetx = las_options.get<double>("offset.x");
+        double offsety = las_options.get<double>("offset.y");
+        double offsetz = las_options.get<double>("offset.z");
+        
         bool compress = las_options.get<bool>("compress");
         
         std::string out_wkt = srs_options.get<std::string>("userinput");
         pdal::OptionsOld options(oracle_options);
+
+
+        pdal::drivers::oci::Reader reader(options);
+        // pdal::filters::ByteSwapFilter swapper(reader);
+        pdal::filters::ScalingFilter scalingFilter(reader, false);
+
+        pdal::SpatialReference out_ref(out_wkt);
+        pdal::SpatialReference in_ref(reader.getSpatialReference());
         
-        if (out_wkt.size() != 0) 
-        {
-            pdal::SpatialReference out_ref(out_wkt);
+        pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, in_ref, out_ref);
+        pdal::filters::ScalingFilter descalingFilter(   reprojectionFilter, 
+                                                        scalex, offsetx,
+                                                        scaley, offsety, 
+                                                        scalez, offsetz, 
+                                                        true);
 
-            pdal::drivers::oci::Reader reader(options);
-            pdal::SpatialReference in_ref(reader.getSpatialReference());
+        pdal::drivers::las::LasWriter writer(descalingFilter, *ofs);
 
-            pdal::filters::ByteSwapFilter swapper(reader);
 
-            pdal::filters::ScalingFilter scalingFilter(swapper, false);
-
-            pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, in_ref, out_ref);
-
-            // convert to ints, using custom scale factor
-            
-            double scalex = las_options.get<double>("scale.x");
-            double scaley = las_options.get<double>("scale.y");
-            double scalez = las_options.get<double>("scale.z");
-
-            double offsetx = las_options.get<double>("offset.x");
-            double offsety = las_options.get<double>("offset.y");
-            double offsetz = las_options.get<double>("offset.z");
-
-            pdal::filters::ScalingFilter descalingFilter(   reprojectionFilter, 
-                                                            scalex, offsetx,
-                                                            scaley, offsety, 
-                                                            scalez, offsetz, 
-                                                            true);
-
-            pdal::drivers::las::LasWriter writer(descalingFilter, *ofs);
-
-
-            if (compress)
-                writer.setCompressed(true);
-            writer.setChunkSize(oracle_options.get<boost::uint32_t>("capacity"));            
-            writer.write(0);
-        } else 
-        {
-            pdal::SpatialReference out_ref(out_wkt);
-
-            pdal::drivers::oci::Reader reader(options);
-            pdal::SpatialReference in_ref(reader.getSpatialReference());
-            pdal::filters::ByteSwapFilter swapper(reader);
+        if (compress)
+            writer.setCompressed(true);
+        writer.setChunkSize(oracle_options.get<boost::uint32_t>("capacity"));
+        writer.setPointFormat(pdal::drivers::las::PointFormat3);
+        writer.write(0);
             
 
-            pdal::drivers::las::LasWriter writer(swapper, *ofs);
-            if (compress)
-                writer.setCompressed(true);
-        
-            writer.setChunkSize(oracle_options.get<boost::uint32_t>("capacity"));            
-            writer.write(0);
-        }
-
-
-
-
-        // boost::property_tree::ptree output_tree;
-        // 
-        // output_tree.put_child(reader.getName(), options.GetPTree());
-        // // output_tree.put_child(writer.getName(), )
-        // // boost::property_tree::write_xml(m_xml, output_tree);
-            
     #else
             throw configuration_error("PDAL not compiled with Oracle support");
     #endif
diff -r 50f7d0d2b5fa -r cd1f7f438601 src/drivers/oci/Writer.cpp
--- a/src/drivers/oci/Writer.cpp	Wed Jul 20 10:25:35 2011 -0500
+++ b/src/drivers/oci/Writer.cpp	Wed Jul 20 12:34:15 2011 -0500
@@ -33,6 +33,9 @@
 ****************************************************************************/
 
 
+#include <pdal/Vector.hpp>
+#include <pdal/Bounds.hpp>
+
 #include <pdal/drivers/oci/Writer.hpp>
 
 #include <iostream>
@@ -1177,7 +1180,6 @@
                           pdal::Bounds<double> const& extent)
 {
     
-    // std::cout << extent << std::endl;
     statement->AddElement(ordinates, extent.getMinimum(0));
     statement->AddElement(ordinates, extent.getMaximum(1));
     if (extent.dimensions().size() > 2)
@@ -1191,6 +1193,38 @@
 
 }
 
+pdal::Bounds<double> CalculateBounds(PointBuffer const& buffer)
+{
+    
+    pdal::Bounds<double> output;
+    pdal::Schema const& schema = buffer.getSchemaLayout().getSchema();
+    
+    const int indexXi = schema.getDimensionIndex(Dimension::Field_X, Dimension::Int32);
+    const int indexYi = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Int32);
+
+    const Dimension& dimXi = schema.getDimension(indexXi);
+    const Dimension& dimYi = schema.getDimension(indexYi);
+    
+    bool first = true;
+    for (boost::uint32_t pointIndex=0; pointIndex<buffer.getNumPoints(); pointIndex++)
+    {
+        const boost::int32_t xi = buffer.getField<boost::int32_t>(pointIndex, indexXi);
+        const boost::int32_t yi = buffer.getField<boost::int32_t>(pointIndex, indexYi);
+        
+        const double xd = dimXi.applyScaling(xi);
+        const double yd = dimYi.applyScaling(yi);
+        
+        Vector<double> v(xd, yd);
+        if (first){
+            output = pdal::Bounds<double>(xd, xd, yd, yd);
+            first = false;
+        }
+        output.grow(v);
+    }
+    
+    return output;
+    
+}
 bool Writer::WriteBlock(PointBuffer const& buffer)
 {
     
@@ -1306,7 +1340,8 @@
     m_connection->CreateType(&sdo_ordinates, m_connection->GetOrdinateType());
     
      // x0, x1, y0, y1, z0, z1, bUse3d
-    SetOrdinates(statement, sdo_ordinates, buffer.getSpatialBounds());
+    pdal::Bounds<double> bounds = CalculateBounds(buffer);
+    SetOrdinates(statement, sdo_ordinates, bounds);
     statement->Bind(&sdo_ordinates, m_connection->GetOrdinateType());
     
     // :9


More information about the Liblas-commits mailing list