[Liblas-commits] libpc: fix up GDAL CPL_DEBUG output so it at least works (leaks ...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Mar 10 18:04:12 EST 2011


details:   http://hg.liblas.orglibpc/rev/2e5420d71219
changeset: 202:2e5420d71219
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Mar 10 17:04:03 2011 -0600
description:
fix up GDAL CPL_DEBUG output so it at least works (leaks a putenv string right now).  start on an oci example

diffstat:

 CMakeLists.txt             |   2 +-
 apps/Application.cpp       |  28 ++++++------
 apps/pc2pc.cpp             |  31 ++++++++++++++
 src/chipper.cpp            |   2 +
 src/drivers/oci/writer.cpp |  97 ++++++++++++++++++++++++++++-----------------
 src/drivers/oci/writer.hpp |   8 ++-
 6 files changed, 114 insertions(+), 54 deletions(-)

diffs (truncated from 321 to 300 lines):

diff -r 25fdd984e99d -r 2e5420d71219 CMakeLists.txt
--- a/CMakeLists.txt	Thu Mar 10 14:56:29 2011 -0800
+++ b/CMakeLists.txt	Thu Mar 10 17:04:03 2011 -0600
@@ -355,7 +355,7 @@
 # installation commands
 #------------------------------------------------------------------------------
 
-install(FILES AUTHORS COPYING INSTALL LICENSE.txt README.txt
+install(FILES AUTHORS.txt LICENSE.txt
   DESTINATION ${LIBPC_DATA_DIR}/doc)
 
 
diff -r 25fdd984e99d -r 2e5420d71219 apps/Application.cpp
--- a/apps/Application.cpp	Thu Mar 10 14:56:29 2011 -0800
+++ b/apps/Application.cpp	Thu Mar 10 17:04:03 2011 -0600
@@ -90,21 +90,21 @@
     // call derived function
     int status = 0;
     
-    try
-    {
+    // try
+    // {
         status = execute();
-    }
-    catch (std::exception e)
-    {
-        const std::string s(e.what());
-        runtimeError("Caught exception: " + s);
-        status = 1;
-    }
-    catch (...)
-    {
-        runtimeError("Caught unknown exception");
-        status = 1;
-    }
+    // }
+    // catch (std::exception e)
+    // {
+    //     const std::string s(e.what());
+    //     runtimeError("Caught exception: " + s);
+    //     status = 1;
+    // }
+    // catch (...)
+    // {
+    //     runtimeError("Caught unknown exception");
+    //     status = 1;
+    // }
 
     if (status == 0 && hasOption("timer"))
     {
diff -r 25fdd984e99d -r 2e5420d71219 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp	Thu Mar 10 14:56:29 2011 -0800
+++ b/apps/pc2pc.cpp	Thu Mar 10 17:04:03 2011 -0600
@@ -26,10 +26,13 @@
 #include "libpc/LasReader.hpp"
 //#include "libpc/LasHeader.hpp"
 #include "libpc/LasWriter.hpp"
+#include "libpc/CacheFilter.hpp"
 
 #include "libpc/../../src/drivers/liblas/writer.hpp"
 #include "libpc/../../src/drivers/liblas/reader.hpp"
 
+#include "libpc/../../src/drivers/oci/writer.hpp"
+
 
 #include "Application.hpp"
 
@@ -84,6 +87,7 @@
         ("input,i", po::value<std::string>(&m_inputFile), "input file name")
         ("output,o", po::value<std::string>(&m_outputFile), "output file name")
         ("native", "use native LAS classes (not liblas)")
+        ("oracle", "oracle test")
         ;
 
     addOptionSet(file_options);
@@ -116,6 +120,33 @@
         assert(numPoints == np); // BUG
         writer.write(np);
     }
+    else if (hasOption("oracle"))
+    {
+        LasReader reader(*ifs);
+    
+        const boost::uint64_t numPoints = reader.getHeader().getNumPoints();
+        
+        libpc::driver::oci::Options options;
+        boost::property_tree::ptree& tree = options.GetPTree();
+        
+        tree.put("capacity", 15);
+        tree.put("connection", "lidar/lidar at oracle.hobu.biz/crrel");
+        tree.put("debug", true);
+        tree.put("verbose", true);
+        
+        CacheFilter cache(reader);
+        
+        libpc::driver::oci::Writer writer(cache, options);
+        
+        
+        //BUG: handle laz writer.setCompressed(false);
+
+        //writer.setPointFormat( reader.getPointFormatNumber() );
+
+        size_t np = (size_t)numPoints;
+        assert(numPoints == np); // BUG
+        writer.write(np);
+    }    
     else
     {
         LiblasReader reader(*ifs);
diff -r 25fdd984e99d -r 2e5420d71219 src/chipper.cpp
--- a/src/chipper.cpp	Thu Mar 10 14:56:29 2011 -0800
+++ b/src/chipper.cpp	Thu Mar 10 17:04:03 2011 -0600
@@ -142,6 +142,7 @@
 
         for (boost::uint32_t j = 0; j < m_threshold; j++)
         {
+            if (j == num_to_read) break; // we're outta here
             // (v * m_header->GetScaleX()) + m_header->GetOffsetX();
             const double x = (buffer.getField<boost::int32_t>(j, indexX) * xscale) + xoffset;
             const double y = (buffer.getField<boost::int32_t>(j, indexY) * yscale) + yoffset;
@@ -153,6 +154,7 @@
             ref.m_pos = y;
             yvec.push_back(ref);
             counter++;
+
         }
 
         num_points_loaded += num_read;
diff -r 25fdd984e99d -r 2e5420d71219 src/drivers/oci/writer.cpp
--- a/src/drivers/oci/writer.cpp	Thu Mar 10 14:56:29 2011 -0800
+++ b/src/drivers/oci/writer.cpp	Thu Mar 10 17:04:03 2011 -0600
@@ -277,7 +277,6 @@
 
     if (srid == 0) {
         s_srid << "NULL";
-        // bUse3d = true;
     }
     else {
         s_srid << srid;
@@ -287,6 +286,7 @@
     libpc::Bounds<double> e = m_bounds;
 
     if (IsGeographic(srid)) {
+        // FIXME: This should be overrideable
         e.setMinimum(0,-180.0); e.setMaximum(0,180.0);
         e.setMinimum(1,-90.0); e.setMaximum(1,90.0);
         e.setMinimum(2,0.0); e.setMaximum(2,20000.0);
@@ -327,9 +327,10 @@
     // Because of OCIGDALErrorHandler, this is going to throw if there is a 
     // problem.  When it does, the statement should go out of scope and 
     // be destroyed without leaking.
+    statement->Define(szTable);
+
     statement->Execute();
     
-    statement->Define(szTable);
     
     try {
         statement->Execute();
@@ -434,8 +435,18 @@
 {
     std::ostringstream oss;
     std::string sql = m_options.GetPTree().get<std::string>(filename);
-    
-    oss << sql;
+        
+    if (!sql.size()) return;
+
+    if (!Utils::fileExists(sql))
+    {
+        oss << sql;
+    } else {
+        oss << LoadSQLData(sql);  // Our "sql" is really the filename in the ptree
+    }
+
+
+   
 
     if (m_options.IsDebug())
         std::cout << "running "<< filename << " ..." <<std::endl;
@@ -648,6 +659,8 @@
     for ( boost::uint32_t i = 0; i < m_chipper.GetBlockCount(); ++i )
     {
         const chipper::Block& b = m_chipper.GetBlock(i);
+        
+        // FIXME: This only gets called once!
         if (m_bounds.empty()) // If the user already set the bounds for this writer, we're using that
             m_bounds.grow(b.GetBounds());        
     }
@@ -804,12 +817,6 @@
     bool debug = m_options.IsDebug();
     
 
-    const char* gdal_debug = getenv("CPL_DEBUG");
-    if (gdal_debug == 0)
-    {
-        char d[20] = "CPL_DEBUG=ON";
-        putenv(d);
-    }
     
     if (debug)
     {
@@ -817,37 +824,30 @@
     }
 
     CPLPopErrorHandler();
+
     if (debug)
+    {
+        const char* gdal_debug = getenv("CPL_DEBUG");
+        if (gdal_debug == 0)
+        {
+            // FIXME: this leaks
+            const std::string* d = new std::string("CPL_DEBUG=ON");
+            putenv(const_cast<char*>(d->c_str()));
+        }
+        
+        const char* gdal_debug2 = getenv("CPL_DEBUG");
+        std::cout << "Setting GDAL debug handler CPL_DEBUG=" << gdal_debug2 << std::endl;
         CPLPushErrorHandler(OCIGDALDebugErrorHandler);
-    else
-        CPLPushErrorHandler(OCIGDALErrorHandler);
-}
-
-void CPL_STDCALL OCIGDALDebugErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
-{
-    std::ostringstream oss;
-    
-    if (eErrClass == CE_Failure || eErrClass == CE_Fatal) {
-        oss <<"GDAL Failure number=" << err_no << ": " << msg;
-        throw libpc_error(oss.str());
-    } else if (eErrClass == CE_Debug) {
-        std::cout <<"GDAL Debug: " << msg << std::endl;
-    } else {
-        return;
+        
+    }
+    else 
+    {
+        CPLPushErrorHandler(OCIGDALErrorHandler);        
     }
 }
 
-void CPL_STDCALL OCIGDALErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
-{
-    std::ostringstream oss;
-    
-    if (eErrClass == CE_Failure || eErrClass == CE_Fatal) {
-        oss <<"GDAL Failure number=" << err_no << ": " << msg;
-        throw libpc_error(oss.str());
-    } else {
-        return;
-    }
-}
+
+
 
 std::string to_upper(const std::string& input)
 {
@@ -861,3 +861,28 @@
 
 }}} // namespace libpc::driver::oci
 
+void CPL_STDCALL OCIGDALErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
+{
+    std::ostringstream oss;
+    
+    if (eErrClass == CE_Failure || eErrClass == CE_Fatal) {
+        oss <<"GDAL Failure number=" << err_no << ": " << msg;
+        throw libpc::libpc_error(oss.str());
+    } else {
+        return;
+    }
+}
+
+void CPL_STDCALL OCIGDALDebugErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
+{
+    std::ostringstream oss;
+    
+    if (eErrClass == CE_Failure || eErrClass == CE_Fatal) {
+        oss <<"GDAL Failure number=" << err_no << ": " << msg;
+        throw libpc::libpc_error(oss.str());
+    } else if (eErrClass == CE_Debug) {
+        std::cout <<"GDAL Debug: " << msg << std::endl;
+    } else {
+        return;
+    }
+}
diff -r 25fdd984e99d -r 2e5420d71219 src/drivers/oci/writer.hpp
--- a/src/drivers/oci/writer.hpp	Thu Mar 10 14:56:29 2011 -0800
+++ b/src/drivers/oci/writer.hpp	Thu Mar 10 17:04:03 2011 -0600
@@ -47,6 +47,10 @@
 
 #include <cpl_port.h>
 
+void CPL_STDCALL OCIGDALErrorHandler(CPLErr eErrClass, int err_no, const char *msg);
+void CPL_STDCALL OCIGDALDebugErrorHandler(CPLErr eErrClass, int err_no, const char *msg);
+
+


More information about the Liblas-commits mailing list