[Liblas-commits] hg-main-tree: add WKT validation for boundary geometry #38

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Aug 12 15:15:16 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/1bc98d42dcd3
changeset: 1073:1bc98d42dcd3
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri Aug 12 14:14:13 2011 -0500
description:
add WKT validation for boundary geometry #38
Subject: hg-main-tree: #ifdef the msvcisms

details:   http://hg.libpc.orghg-main-tree/rev/f2459a56b514
changeset: 1074:f2459a56b514
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri Aug 12 14:14:56 2011 -0500
description:
#ifdef the msvcisms

diffstat:

 include/pdal/drivers/oci/Writer.hpp |   1 +
 src/drivers/oci/Writer.cpp          |  29 ++++++++++++++++++++++++++++-
 test/unit/Support.cpp               |  22 +++++++++++++++++-----
 3 files changed, 46 insertions(+), 6 deletions(-)

diffs (109 lines):

diff -r d17d4f084b1b -r f2459a56b514 include/pdal/drivers/oci/Writer.hpp
--- a/include/pdal/drivers/oci/Writer.hpp	Fri Aug 12 10:37:22 2011 -0700
+++ b/include/pdal/drivers/oci/Writer.hpp	Fri Aug 12 14:14:56 2011 -0500
@@ -112,6 +112,7 @@
     std::string ShutOff_SDO_PC_Trigger();
     void TurnOn_SDO_PC_Trigger(std::string trigger_name);
     pdal::Bounds<double> CalculateBounds(PointBuffer const& buffer);
+    bool IsValidWKT(std::string const& wkt);
     Stage& m_stage;
     
     pdal::Bounds<double> m_bounds; // Bounds of the entire point cloud
diff -r d17d4f084b1b -r f2459a56b514 src/drivers/oci/Writer.cpp
--- a/src/drivers/oci/Writer.cpp	Fri Aug 12 10:37:22 2011 -0700
+++ b/src/drivers/oci/Writer.cpp	Fri Aug 12 14:14:56 2011 -0500
@@ -46,6 +46,10 @@
 
 #include <fstream>
 
+#ifdef PDAL_HAVE_GDAL
+#include <ogr_api.h>
+#endif
+
 namespace pdal { namespace drivers { namespace oci {
 
 IMPLEMENT_STATICS(Writer, "drivers.oci.writer", "OCI Writer")
@@ -759,7 +763,12 @@
     {
         wkt_s << base_table_boundary_wkt;
     } else {
-        wkt_s << LoadSQLData(base_table_boundary_wkt);
+        std::string wkt = LoadSQLData(base_table_boundary_wkt);
+        if (!IsValidWKT(wkt))
+        {
+            throw pdal::pdal_error("WKT for base_table_boundary_wkt was not valid");
+        }
+        wkt_s << wkt;
     }
     
     std::string wkt_string = wkt_s.str();
@@ -787,6 +796,24 @@
     // tree.put("cloud_id", pc_id);
     
 }
+
+bool Writer::IsValidWKT(std::string const& input)
+{
+#ifdef PDAL_HAVE_GDAL
+    
+    OGRGeometryH g;
+    
+    char* wkt = const_cast<char*>(input.c_str());
+    OGRErr e = OGR_G_CreateFromWkt(&wkt, NULL, &g);
+    OGR_G_DestroyGeometry(g);
+    if (e != 0) return false;
+    
+    return true;
+#else
+
+    throw pdal_error("GDAL support not available for WKT validation");
+#endif        
+}
 void Writer::writeBegin(boost::uint64_t targetNumPointsToWrite)
 {
 
diff -r d17d4f084b1b -r f2459a56b514 test/unit/Support.cpp
--- a/test/unit/Support.cpp	Fri Aug 12 10:37:22 2011 -0700
+++ b/test/unit/Support.cpp	Fri Aug 12 14:14:56 2011 -0500
@@ -426,17 +426,24 @@
 {
     const int maxbuf = 4096;
     char buf[maxbuf];
+    
+    std::string cmd;
 
-    const std::string cmd = replaceAll(rawcmd, "/", "\\");
-
+#ifdef PDAL_COMPILER_MSVC
+    cmd = replaceAll(rawcmd, "/", "\\");
+#else
+    cmd = rawcmd;
+#endif
+    
     output = "";
     
+    FILE* fp = 0;
 #ifdef PDAL_COMPILER_MSVC
-    FILE* fp = _popen(cmd.c_str(), "r");
+    fp = _popen(cmd.c_str(), "r");
 #else
-    FILE* fp = popen(cmd.c_str(), "r");
+    fp = popen(cmd.c_str(), "r");
 #endif
-
+    
     while (!feof(fp))
     {
         if (fgets(buf, maxbuf, fp) == NULL)
@@ -445,6 +452,11 @@
 
             if (ferror(fp))
             {
+                #ifdef PDAL_COMPILER_MSVC
+                    _pclose(fp);
+                #else
+                    pclose(fp);
+                #endif
                 throw std::runtime_error("error executing command");
             }
         }


More information about the Liblas-commits mailing list