[Liblas-commits] hg-main-tree: incremental SRS work for las reader

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Apr 22 14:12:18 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/dc91d5738c48
changeset: 627:dc91d5738c48
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Apr 22 11:12:04 2011 -0700
description:
incremental SRS work for las reader
Subject: hg-main-tree: merge

details:   http://hg.libpc.orghg-main-tree/rev/899f40112f57
changeset: 628:899f40112f57
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Apr 22 11:12:12 2011 -0700
description:
merge

diffstat:

 include/libpc/drivers/las/Reader.hpp    |    2 +
 include/libpc/drivers/liblas/Reader.hpp |    2 +
 src/drivers/las/Reader.cpp              |   14 ++++++++
 src/drivers/liblas/Reader.cpp           |    6 +++
 src/drivers/oci/Writer.cpp              |   56 ++++++++++++++++++++++++-------
 src/drivers/oci/common.cpp              |    1 +
 test/data/utm15.las                     |    0 
 test/data/utm17.las                     |    0 
 test/unit/OCITest.cpp                   |    3 +-
 test/unit/SpatialReferenceTest.cpp      |   54 +++++++++++++-----------------
 10 files changed, 94 insertions(+), 44 deletions(-)

diffs (truncated from 322 to 300 lines):

diff -r 9c0730a8eb2e -r 899f40112f57 include/libpc/drivers/las/Reader.hpp
--- a/include/libpc/drivers/las/Reader.hpp	Fri Apr 22 10:21:05 2011 -0700
+++ b/include/libpc/drivers/las/Reader.hpp	Fri Apr 22 11:12:12 2011 -0700
@@ -81,6 +81,8 @@
     boost::uint8_t getVersionMajor() const;
     boost::uint8_t getVersionMinor() const;
 
+    const SpatialReference& getSpatialReference() const;
+
     boost::uint64_t getPointDataOffset() const;
 
 protected:
diff -r 9c0730a8eb2e -r 899f40112f57 include/libpc/drivers/liblas/Reader.hpp
--- a/include/libpc/drivers/liblas/Reader.hpp	Fri Apr 22 10:21:05 2011 -0700
+++ b/include/libpc/drivers/liblas/Reader.hpp	Fri Apr 22 11:12:12 2011 -0700
@@ -71,6 +71,8 @@
     int getMetadataRecordCount() const;
     const MetadataRecord& getMetadataRecord(int index) const;
 
+    const SpatialReference& getSpatialReference() const;
+
     bool supportsIterator (StageIteratorType t) const
     {   
         if (t == StageIterator_Sequential ) return true;
diff -r 9c0730a8eb2e -r 899f40112f57 src/drivers/las/Reader.cpp
--- a/src/drivers/las/Reader.cpp	Fri Apr 22 10:21:05 2011 -0700
+++ b/src/drivers/las/Reader.cpp	Fri Apr 22 11:12:12 2011 -0700
@@ -56,6 +56,14 @@
     this->setBounds(m_lasHeader.getBounds());
     this->setNumPoints(m_lasHeader.GetPointRecordsCount());
 
+    //const std::vector<VariableLengthRecord>& vlrs = m_lasHeader.getVLRs();
+    //if (vlrs.size() > 0)
+    //{
+    //    SpatialReference srs;
+    //    VariableLengthRecord::setSRS(vlrs, srs);
+    //    this->setSpatialReference(srs);
+    //}
+
     Utils::closeFile(str);
 
     return;
@@ -111,6 +119,12 @@
 }
 
 
+const SpatialReference& LasReader::getSpatialReference() const
+{
+    throw not_yet_implemented("SRS support in native las reader not yet implemented");
+}
+
+
 boost::uint64_t LasReader::getPointDataOffset() const
 {
     return m_lasHeader.GetDataOffset();
diff -r 9c0730a8eb2e -r 899f40112f57 src/drivers/liblas/Reader.cpp
--- a/src/drivers/liblas/Reader.cpp	Fri Apr 22 10:21:05 2011 -0700
+++ b/src/drivers/liblas/Reader.cpp	Fri Apr 22 11:12:12 2011 -0700
@@ -113,6 +113,12 @@
 }
 
 
+const SpatialReference& LiblasReader::getSpatialReference() const
+{
+    throw not_yet_implemented("SRS support in liblas reader not yet implemented");
+}
+
+
 void LiblasReader::processExternalHeader(::liblas::Reader& externalReader)
 {
     const ::liblas::Header& externalHeader = externalReader.GetHeader();
diff -r 9c0730a8eb2e -r 899f40112f57 src/drivers/oci/Writer.cpp
--- a/src/drivers/oci/Writer.cpp	Fri Apr 22 10:21:05 2011 -0700
+++ b/src/drivers/oci/Writer.cpp	Fri Apr 22 11:12:12 2011 -0700
@@ -441,12 +441,15 @@
     std::string header_blob_column_name = to_upper(tree.get<std::string>("header_blob_column_name"));
     std::string base_table_boundary_column = to_upper(tree.get<std::string>("base_table_boundary_column"));
     std::string base_table_boundary_wkt = to_upper(tree.get<std::string>("base_table_boundary_wkt"));
+    std::string point_schema_override = to_upper(tree.get<std::string>("point_schema_override"));
     
     boost::uint32_t srid = tree.get<boost::uint32_t>("srid");
     boost::uint32_t precision = tree.get<boost::uint32_t>("precision");
     boost::uint32_t capacity = tree.get<boost::uint32_t>("capacity");
     boost::uint32_t dimensions = tree.get<boost::uint32_t>("dimensions");
     bool bUse3d = tree.get<bool>("is3d");
+
+    bool bHaveSchemaOverride = (point_schema_override.size() > 0);
     
     std::ostringstream oss;
 
@@ -466,11 +469,16 @@
         values << "pc";
     }
 
-    int nPos = 2; // Bind column position    
-    if (!header_blob_column_name.empty()){
-        columns << "," << header_blob_column_name;
-        values <<", :" << nPos;
-    }
+    int nPCPos = 1;
+    int nSchemaPos = 1;
+    if (bHaveSchemaOverride)
+        nSchemaPos++;
+
+    int nPos = nSchemaPos+1; // Bind column position    
+    // if (!header_blob_column_name.empty()){
+    //     columns << "," << header_blob_column_name;
+    //     values <<", :" << nPos;
+    // }
 
     if (!base_table_boundary_column.empty()){
         columns << "," << base_table_boundary_column;
@@ -484,7 +492,8 @@
 
     std::ostringstream s_srid;
     std::ostringstream s_geom;
-
+    std::ostringstream s_schema;
+    
 
     // IsGeographic(srid);
 
@@ -497,6 +506,14 @@
         s_srid << srid;
     }
 
+    if (bHaveSchemaOverride)
+    {
+        s_schema << "xmltype(:"<<nSchemaPos<<")";
+    } else
+    {
+        s_schema << "NULL";
+    }
+    
     long gtype = GetGType();
     
     std::string eleminfo = CreatePCElemInfo();
@@ -524,7 +541,7 @@
     
     
 oss << "declare\n"
-"  pc_id NUMBER := :1;\n"
+"  pc_id NUMBER := :"<<nPCPos<<";\n"
 "  pc sdo_pc;\n"
 
 "begin\n"
@@ -538,8 +555,10 @@
 ",  -- Extent\n"
 "     0.5, -- Tolerance for point cloud\n"
 "           "<<dimensions<<", -- Total number of dimensions\n"
-"           null);\n"
-"  :1 := pc.pc_id;\n"
+"           NULL,"
+"            NULL,"
+"            "<< s_schema.str() <<");\n"
+"  :"<<nPCPos<<" := pc.pc_id;\n"
 
 "  -- Insert the Point Cloud object  into the \"base\" table.\n"
 "  insert into " << base_table_name << " ( ID, "<< columns.str() <<
@@ -554,6 +573,19 @@
     Statement statement = Statement(m_connection->CreateStatement(oss.str().c_str()));
 
     statement->Bind(&pc_id);
+
+
+    OCILobLocator* schema_locator ; 
+    OCILobLocator* boundary_locator ; 
+
+    if (bHaveSchemaOverride)
+    {
+        char* schema = (char*) malloc(point_schema_override.size() * sizeof(char));
+        strncpy(schema, point_schema_override.c_str(), point_schema_override.size());
+        statement->WriteCLob( &schema_locator, schema ); 
+        statement->Bind(&schema_locator);
+    }
+
     // if (header_data->size() != 0) 
     // {
     //     OCILobLocator** locator =(OCILobLocator**) VSIMalloc( sizeof(OCILobLocator*) * 1 );
@@ -565,10 +597,8 @@
     strncpy(wkt, base_table_boundary_wkt.c_str(), base_table_boundary_wkt.size());
     if (!base_table_boundary_column.empty())
     {
-
-        OCILobLocator* locator ; 
-        statement->WriteCLob( &locator, wkt ); 
-        statement->Bind(&locator);
+        statement->WriteCLob( &boundary_locator, wkt ); 
+        statement->Bind(&boundary_locator);
         statement->Bind((long int*)&srid);
 
     }
diff -r 9c0730a8eb2e -r 899f40112f57 src/drivers/oci/common.cpp
--- a/src/drivers/oci/common.cpp	Fri Apr 22 10:21:05 2011 -0700
+++ b/src/drivers/oci/common.cpp	Fri Apr 22 11:12:12 2011 -0700
@@ -75,6 +75,7 @@
     m_tree.put("select_sql", std::string(""));
     m_tree.put("base_table_bounds", libpc::Bounds<double>());
     m_tree.put("blob_read_byte_size", boost::uint32_t(2000));
+    m_tree.put("point_schema_override", "");
     
     boost::property_tree::ptree scales;
     scales.put("x", double(0.01));
diff -r 9c0730a8eb2e -r 899f40112f57 test/data/utm15.las
Binary file test/data/utm15.las has changed
diff -r 9c0730a8eb2e -r 899f40112f57 test/data/utm17.las
Binary file test/data/utm17.las has changed
diff -r 9c0730a8eb2e -r 899f40112f57 test/unit/OCITest.cpp
--- a/test/unit/OCITest.cpp	Fri Apr 22 10:21:05 2011 -0700
+++ b/test/unit/OCITest.cpp	Fri Apr 22 11:12:12 2011 -0700
@@ -193,7 +193,8 @@
     if (!ShouldRunTest()) return;
 
     
-    std::string xml = ReadXML("/Users/hobu/hg/liblas/schemas/las.xml");
+    // std::string xml = ReadXML("/Users/hobu/hg/liblas/schemas/las.xml");
+    std::string xml = ReadXML("/Users/hobu/hg/weblas/8-dimension-schema.xml");
     std::string xsd = ReadXML("/Users/hobu/hg/liblas/schemas/LAS.xsd");
     
     libpc::drivers::oci::Schema schema(xml, xsd);
diff -r 9c0730a8eb2e -r 899f40112f57 test/unit/SpatialReferenceTest.cpp
--- a/test/unit/SpatialReferenceTest.cpp	Fri Apr 22 10:21:05 2011 -0700
+++ b/test/unit/SpatialReferenceTest.cpp	Fri Apr 22 11:12:12 2011 -0700
@@ -36,8 +36,9 @@
 
 #include <libpc/SpatialReference.hpp>
 #include <libpc/Utils.hpp>
+#include <libpc/drivers/las/Reader.hpp>
 
-using namespace libpc;
+#include "Support.hpp"
 
 BOOST_AUTO_TEST_SUITE(SpatialReferenceTest)
 
@@ -47,8 +48,8 @@
     const char* gdal_data = getenv("GDAL_DATA");
     const char* proj_lib = getenv("PROJ_LIB");
 
-    BOOST_CHECK(Utils::fileExists(gdal_data));
-    BOOST_CHECK(Utils::fileExists(proj_lib));
+    BOOST_CHECK(libpc::Utils::fileExists(gdal_data));
+    BOOST_CHECK(libpc::Utils::fileExists(proj_lib));
 
     return;
 }
@@ -56,7 +57,7 @@
 
 BOOST_AUTO_TEST_CASE(test_ctor)
 {
-    SpatialReference srs;
+    libpc::SpatialReference srs;
 
     BOOST_CHECK(srs.getProj4() == "");
     BOOST_CHECK(srs.getWKT() == "");
@@ -68,7 +69,7 @@
 // Test round-tripping proj.4 string
 BOOST_AUTO_TEST_CASE(test_proj4_roundtrip)
 {
-    SpatialReference ref;
+    libpc::SpatialReference ref;
     
     const std::string proj4 = "+proj=utm +zone=15 +datum=WGS84 +units=m +no_defs ";
     const std::string proj4_ellps = "+proj=utm +zone=15 +ellps=WGS84 +datum=WGS84 +units=m +no_defs ";
@@ -88,7 +89,7 @@
 // Test setting EPSG:4326 from User string
 BOOST_AUTO_TEST_CASE(test_userstring_roundtrip)
 {
-    SpatialReference ref;
+    libpc::SpatialReference ref;
 
     const std::string code = "EPSG:4326";
     const std::string proj4 = "+proj=longlat +datum=WGS84 +no_defs ";
@@ -106,32 +107,25 @@
     return;
 }
 
+       
+// Test fetching SRS from an existing file
+BOOST_AUTO_TEST_CASE(test_read_srs)
+{
+    libpc::drivers::las::LasReader reader(Support::datapath("utm17.las"));
+
+    //////libpc::SpatialReference const& ref = reader.getSpatialReference();
+
+    //////const std::string wkt = "PROJCS[\"WGS 84 / UTM zone 17N\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-81],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"32617\"]]";
+    //////BOOST_CHECK(ref.getWKT() == wkt);
+
+    //////const std::string proj4 = "+proj=utm +zone=17 +datum=WGS84 +units=m +no_defs ";
+    //////BOOST_CHECK(ref.getProj4() == proj4);
+
+    return;
+}
+
 
 #if 0
-   utm17_filename(g_test_data_path + "//srs.las")
-   utm15_filename(g_test_data_path + "//1.2_3.las")
-        
-  
-


More information about the Liblas-commits mailing list