[Liblas-commits] hg: 3 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Aug 20 14:12:35 EDT 2010


changeset 6bc311f2a0e1 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=6bc311f2a0e1
summary: add option to prettyprint wkt

changeset edde81a39a13 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=edde81a39a13
summary: add operator<< to output liblas::Point to ostream

changeset aba1ed12dd3e in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=aba1ed12dd3e
summary: add operator<< to output liblas::Header to ostream

diffstat:

 include/liblas/lasheader.hpp           |   4 +
 include/liblas/laspoint.hpp            |   3 +
 include/liblas/lasspatialreference.hpp |   3 +-
 src/lasheader.cpp                      |  96 ++++++++++++++++++++++++++++++++-
 src/laspoint.cpp                       |  35 ++++++++++++
 src/lasspatialreference.cpp            |  25 +++++++-
 6 files changed, 159 insertions(+), 7 deletions(-)

diffs (284 lines):

diff -r 5721a1944d54 -r aba1ed12dd3e include/liblas/lasheader.hpp
--- a/include/liblas/lasheader.hpp	Thu Aug 19 14:12:27 2010 -0500
+++ b/include/liblas/lasheader.hpp	Fri Aug 20 13:12:14 2010 -0500
@@ -53,12 +53,14 @@
 // boost
 #include <boost/cstdint.hpp>
 #include <boost/property_tree/ptree.hpp>
+#include <boost/foreach.hpp>
 
 //std
 #include <cstddef>
 #include <string>
 #include <vector>
 #include <sstream>
+#include <cmath>
 
 namespace liblas {
 
@@ -390,6 +392,8 @@
     Schema m_format;
 };
 
+std::ostream& operator<<(std::ostream& os, liblas::Header const&);
+
 } // namespace liblas
 
 #endif // LIBLAS_LASHEADER_HPP_INCLUDED
diff -r 5721a1944d54 -r aba1ed12dd3e include/liblas/laspoint.hpp
--- a/include/liblas/laspoint.hpp	Thu Aug 19 14:12:27 2010 -0500
+++ b/include/liblas/laspoint.hpp	Fri Aug 20 13:12:14 2010 -0500
@@ -197,6 +197,7 @@
     HeaderPtr GetHeaderPtr() const;
     
     boost::property_tree::ptree GetPTree() const;
+
 private:
 
     detail::PointRecord m_record;
@@ -367,6 +368,8 @@
 }
 
 
+std::ostream& operator<<(std::ostream& os, liblas::Point const&);
+
 
 } // namespace liblas
 
diff -r 5721a1944d54 -r aba1ed12dd3e include/liblas/lasspatialreference.hpp
--- a/include/liblas/lasspatialreference.hpp	Thu Aug 19 14:12:27 2010 -0500
+++ b/include/liblas/lasspatialreference.hpp	Fri Aug 20 13:12:14 2010 -0500
@@ -128,7 +128,8 @@
     /// coordinate system if there is vertical coordinate system info 
     /// available.
     std::string GetWKT( WKTModeFlag mode_flag = eHorizontalOnly ) const;
-
+    std::string GetWKT( WKTModeFlag mode_flag, bool bPretty) const;
+    
     /// Sets the SRS using GDAL's OGC WKT. If GDAL is not linked, this 
     /// operation has no effect.
     /// \param v - a string containing the WKT string.  
diff -r 5721a1944d54 -r aba1ed12dd3e src/lasheader.cpp
--- a/src/lasheader.cpp	Thu Aug 19 14:12:27 2010 -0500
+++ b/src/lasheader.cpp	Fri Aug 20 13:12:14 2010 -0500
@@ -781,10 +781,10 @@
     pt.put("reserved", GetReserved());
 
 #ifdef HAVE_GDAL
-    pt.put("srs", GetSRS().GetWKT());
+    pt.put("srs", GetSRS().GetWKT(liblas::SpatialReference::eHorizontalOnly, true));
 #else
 #ifdef HAVE_LIBGEOTIFF
-    pt.put("proj4", GetSRS().GetProj4());
+    pt.put("srs", GetSRS().GetProj4());
 #endif
 #endif
     
@@ -834,10 +834,100 @@
         vlr.put("description", r.GetDescription(false));
         vlr.put("length", r.GetRecordLength());
         vlr.put("id", r.GetRecordId());
-        pt.add_child("vlr", vlr);
+        pt.add_child("vlrs.vlr", vlr);
     }    
     
     return pt;
 }
+
+std::ostream& operator<<(std::ostream& os, liblas::Header const& h)
+{
+    using boost::property_tree::ptree;
+    ptree tree = h.GetPTree();
     
+    
+    os << "---------------------------------------------------------" << std::endl;
+    os << "  Header Summary" << std::endl;
+    os << "---------------------------------------------------------" << std::endl;
+
+    os << "  Version:                     " << tree.get<std::string>("version") << std::endl;
+    os << "  Source ID:                   " << tree.get<boost::uint32_t>("filesourceid") << std::endl;
+    os << "  Reserved:                    " << tree.get<std::string>("reserved") << std::endl;
+    os << "  Project ID/GUID:             '" << tree.get<std::string>("projectdid") << "'" << std::endl;
+    os << "  System ID:                   '" << tree.get<std::string>("systemid") << "'" << std::endl;
+    os << "  Generating Software:         '" << tree.get<std::string>("softwareid") << "'" << std::endl;
+    os << "  File Creation Day/Year:      " << tree.get<std::string>("date") << std::endl;
+    os << "  Header Byte Size             " << tree.get<boost::uint32_t>("size") << std::endl;
+    os << "  Data Offset:                 " << tree.get<std::string>("dataoffset") << std::endl;
+    os << "  Number Var. Length Records:  " << tree.get_child("vlrs").size() << std::endl;
+    os << "  Point Data Format:           " << tree.get<boost::uint32_t>("dataformatid") << std::endl;
+    os << "  Number of Point Records:     " << tree.get<boost::uint32_t>("count") << std::endl;
+    
+    std::ostringstream returns_oss;
+    BOOST_FOREACH(ptree::value_type &v,
+            tree.get_child("returns"))
+    {
+            returns_oss << v.second.get<std::string>("count")<< " ";
+        
+    }        
+ 
+    os << "  Number of Points by Return:  " << returns_oss.str() << std::endl;
+
+    os.setf(std::ios_base::fixed, std::ios_base::floatfield);
+    double scale = tree.get<double>("scale.x");
+    
+    double frac = 0;
+    double integer = 0;
+    frac = std::modf(scale, &integer);
+    
+    boost::uint32_t prec = std::fabs(std::floor(std::log10(frac)));
+    os.precision(prec);
+        
+    os << "  Scale Factor X Y Z:          " 
+       << tree.get<double>("scale.x") << " " 
+       << tree.get<double>("scale.y") << " " 
+       << tree.get<double>("scale.x") << std::endl;
+
+    os << "  Offset X Y Z:                " 
+       << tree.get<double>("offset.x") << " " 
+       << tree.get<double>("offset.y") << " " 
+       << tree.get<double>("offset.x") << std::endl;
+
+    os << "  Min X Y Z:                   " 
+       << tree.get<double>("minimum.x") << " " 
+       << tree.get<double>("minimum.y") << " " 
+       << tree.get<double>("minimum.x") << std::endl;
+
+    os << "  Max X Y Z:                   " 
+       << tree.get<double>("minimum.x") << " " 
+       << tree.get<double>("minimum.y") << " " 
+       << tree.get<double>("minimum.x") << std::endl;         
+    
+    os << "  Spatial Reference:  " << std::endl;
+    os << tree.get<std::string>("srs") << std::endl;
+   
+    os << "---------------------------------------------------------" << std::endl;
+    os << "  VLR Summary" << std::endl;
+    os << "---------------------------------------------------------" << std::endl;
+
+    std::ostringstream vlrs_oss;
+    BOOST_FOREACH(ptree::value_type &v,
+            tree.get_child("vlrs"))
+    {
+            vlrs_oss << "    User: '" 
+                     << v.second.get<std::string>("userid")
+                     << "' - Description: '"
+                     << v.second.get<std::string>("description") 
+                     <<"'" 
+                     << std::endl;
+            vlrs_oss << "    ID: " << v.second.get<boost::uint32_t>("id")
+                     << " Length: " <<v.second.get<boost::uint32_t>("length")
+                     << std::endl;
+    }
+    
+    os << vlrs_oss.str();
+    
+    return os;
+    
+}
 } // namespace liblas
diff -r 5721a1944d54 -r aba1ed12dd3e src/laspoint.cpp
--- a/src/laspoint.cpp	Thu Aug 19 14:12:27 2010 -0500
+++ b/src/laspoint.cpp	Fri Aug 20 13:12:14 2010 -0500
@@ -53,6 +53,7 @@
 #include <stdexcept>
 #include <string>
 #include <vector>
+#include <iosfwd>
 
 using namespace boost;
 
@@ -331,6 +332,40 @@
     return pt;
 }
 
+std::ostream& operator<<(std::ostream& os, liblas::Point const& p)
+{
+    using boost::property_tree::ptree;
+    ptree tree = p.GetPTree();
+
+    os << "---------------------------------------------------------" << std::endl;
+    
+    os.setf(std::ios_base::fixed, std::ios_base::floatfield);
+    os.precision(6);
+
+    os << "  X: \t\t\t" << tree.get<double>("x") << std::endl;
+    os << "  Y: \t\t\t" << tree.get<double>("y") << std::endl;
+    os << "  Z: \t\t\t" << tree.get<double>("z") << std::endl;
+    os << "  Time: \t\t" << tree.get<double>("time") << std::endl;
+    os.unsetf(std::ios_base::fixed);
+    os.unsetf(std::ios_base::floatfield);
+    os << "  Return Number: \t" << tree.get<boost::uint32_t>("returnnumber") << std::endl;
+    os << "  Return Count: \t" << tree.get<boost::uint32_t>("numberofreturns") << std::endl;
+    os << "  Flightline Edge: \t" << tree.get<boost::uint32_t>("flightlineedge") << std::endl;
+    os << "  Intensity: \t\t" << tree.get<boost::uint32_t>("intensity") << std::endl;
+    os << "  Scan Direction: \t" << tree.get<boost::uint32_t>("scandirection") << std::endl;
+    os << "  Scan Angle Rank: \t" << tree.get<boost::int32_t>("scanangle") << std::endl;
+    os << "  Classification: \t" << tree.get<std::string>("classification.name") << std::endl;
+    os << "         witheld: \t" << tree.get<std::string>("classification.withheld") << std::endl;
+    os << "        keypoint: \t" << tree.get<std::string>("classification.keypoint") << std::endl;
+    os << "       synthetic: \t" << tree.get<std::string>("classification.synthetic") << std::endl;
+    os << "  RGB Color: \t\t" << tree.get<boost::uint32_t>("color.red") << " " 
+                              << tree.get<boost::uint32_t>("color.green") << " "
+                              << tree.get<boost::uint32_t>("color.blue") << std::endl;
+    os << "---------------------------------------------------------" << std::endl;
+
+    return os;
+}
+
 void Point::throw_out_of_range() const
 {
     throw std::out_of_range("coordinate subscript out of range");
diff -r 5721a1944d54 -r aba1ed12dd3e src/lasspatialreference.cpp
--- a/src/lasspatialreference.cpp	Thu Aug 19 14:12:27 2010 -0500
+++ b/src/lasspatialreference.cpp	Fri Aug 20 13:12:14 2010 -0500
@@ -367,8 +367,13 @@
 #endif
 }
 
+std::string SpatialReference::GetWKT( WKTModeFlag mode_flag) const 
+{
+    return GetWKT(mode_flag, false);
+}
+
 /// Fetch the SRS as WKT
-std::string SpatialReference::GetWKT( WKTModeFlag mode_flag ) const 
+std::string SpatialReference::GetWKT( WKTModeFlag mode_flag , bool bPretty) const 
 {
 #ifndef HAVE_GDAL
 	boost::ignore_unused_variable_warning(mode_flag);
@@ -385,6 +390,17 @@
     {
         pszWKT = GTIFGetOGISDefn( m_gtiff, &sGTIFDefn );
 
+            if (bPretty) {
+                OGRSpatialReference* poSRS = (OGRSpatialReference*) OSRNewSpatialReference(NULL);
+                char *pszOrigWKT = pszWKT;
+                poSRS->importFromWkt( &pszOrigWKT );
+
+                CPLFree( pszWKT );
+                pszWKT = NULL;
+                poSRS->exportToPrettyWkt(&pszWKT, false);
+                delete poSRS;
+            }
+                
         // Older versions of GDAL lack StripVertical(), but should never
         // actually return COMPD_CS anyways.
 #if (GDAL_VERSION_NUM >= 1700) && (GDAL_RELEASE_DATE >= 20100110)
@@ -400,12 +416,15 @@
             pszWKT = NULL;
 
             poSRS->StripVertical();
-            poSRS->exportToWkt( &pszWKT );
+            if (bPretty) 
+                poSRS->exportToPrettyWkt(&pszWKT, false);
+            else
+                poSRS->exportToWkt( &pszWKT );
             
             delete poSRS;
         }
 #else
-		boost::ignore_unused_variable_warning(mode_flag);
+        boost::ignore_unused_variable_warning(mode_flag);
 #endif
 
 


More information about the Liblas-commits mailing list