[Liblas-commits] r1022 - in trunk: include/liblas include/liblas/detail src src/detail

liblas-commits at liblas.org liblas-commits at liblas.org
Sun Feb 15 23:19:11 EST 2009


Author: hobu
Date: Sun Feb 15 23:19:09 2009
New Revision: 1022
URL: http://liblas.org/changeset/1022

Log:
more SRS stuff, quite broken right now unless you link GDAL in

Modified:
   trunk/include/liblas/detail/utility.hpp
   trunk/include/liblas/lasheader.hpp
   trunk/include/liblas/lassrs.hpp
   trunk/src/detail/reader.cpp
   trunk/src/lasheader.cpp
   trunk/src/lassrs.cpp

Modified: trunk/include/liblas/detail/utility.hpp
==============================================================================
--- trunk/include/liblas/detail/utility.hpp	(original)
+++ trunk/include/liblas/detail/utility.hpp	Sun Feb 15 23:19:09 2009
@@ -83,6 +83,18 @@
         assert(0 != del_);
     }
 
+    // FIXME: ooh, this is really, really bad. - hobu
+    raii_wrapper& operator=(raii_wrapper const& rhs)
+    {
+        if (&rhs != this)
+        {
+            p_ = rhs.p_;
+            del_ = NULL;
+        }
+        return *this;        
+    }
+    
+    
     ~raii_wrapper()
     {
         do_delete(p_);
@@ -104,10 +116,11 @@
         std::swap(p_, other.p_);
     }
 
+    
 private:
 
     raii_wrapper(raii_wrapper const& other);
-    raii_wrapper& operator=(raii_wrapper const& rhs);
+    // raii_wrapper& operator=(raii_wrapper const& rhs);
 
     void do_delete(T* p)
     {

Modified: trunk/include/liblas/lasheader.hpp
==============================================================================
--- trunk/include/liblas/lasheader.hpp	(original)
+++ trunk/include/liblas/lasheader.hpp	Sun Feb 15 23:19:09 2009
@@ -43,11 +43,12 @@
 #ifndef LIBLAS_LASHEADER_HPP_INCLUDED
 #define LIBLAS_LASHEADER_HPP_INCLUDED
 
+#include <liblas/lasrecordheader.hpp>
+#include <liblas/lassrs.hpp>
 #include <liblas/cstdint.hpp>
 #include <liblas/guid.hpp>
 #include <liblas/detail/utility.hpp>
-#include <liblas/lasrecordheader.hpp>
-#include <liblas/lassrs.hpp>
+#include <liblas/detail/fwd.hpp>
 
 //std
 #include <string>
@@ -331,7 +332,10 @@
     void SetGeoreference();
     
     /// Fetch the georeference
-    // LASSRS& GetSRS();
+    LASSRS& GetSRS();
+    
+    /// Set the georeference
+    void SetSRS(LASSRS& srs);
     
 private:
     
@@ -388,6 +392,7 @@
     PointExtents m_extents;
     std::vector<LASVLR> m_vlrs;
     std::string m_proj4;
+    LASSRS m_srs;
 };
 
 } // namespace liblas

Modified: trunk/include/liblas/lassrs.hpp
==============================================================================
--- trunk/include/liblas/lassrs.hpp	(original)
+++ trunk/include/liblas/lassrs.hpp	Sun Feb 15 23:19:09 2009
@@ -42,32 +42,16 @@
 #ifndef LIBLAS_LASSRS_HPP_INCLUDED
 #define LIBLAS_LASSRS_HPP_INCLUDED
 
+#include <liblas/lasrecordheader.hpp>
+
 #include <liblas/cstdint.hpp>
 #include <liblas/detail/fwd.hpp>
 #include <liblas/detail/utility.hpp>
-#include <liblas/lasheader.hpp>
-
-#include <liblas/lasheader.hpp>
-#include <liblas/cstdint.hpp>
 #include <liblas/exception.hpp>
-#include <liblas/detail/utility.hpp>
-
-// GeoTIFF
-#ifdef HAVE_LIBGEOTIFF
-#include <geotiff.h>
-#include <geo_simpletags.h>
-#include "geo_normalize.h"
-#include "geo_simpletags.h"
-#include "geovalues.h"
-#endif // HAVE_LIBGEOTIFF
-
-// std
-#include <string>
-
 
 // GDAL OSR
 #ifdef HAVE_GDAL
-#include <ogr_srs_api.h>
+#include "ogr_srs_api.h"
 #include "cpl_port.h"
 #include "cpl_serv.h"
 #include "geo_tiffp.h"
@@ -84,8 +68,8 @@
 
 // GeoTIFF
 #ifdef HAVE_LIBGEOTIFF
-#include <geotiff.h>
-#include <geo_simpletags.h>
+#include "geotiff.h"
+#include "geo_simpletags.h"
 #include "geo_normalize.h"
 #include "geo_simpletags.h"
 #include "geovalues.h"
@@ -106,19 +90,27 @@
 
 
     LASSRS();
-    LASSRS(LASSRS const& other);
+    LASSRS(const std::vector<LASVLR>& vlrs);
+    ///LASSRS(LASSRS const& other);
     LASSRS& operator=(LASSRS const& rhs);
-
+    // 
     std::string GetWKT() const;
     void SetWKT(std::string const& v);
     
+    std::string GetProj4() const;
+    
+    bool HasKeys();
 
 private:
 
+    LASSRS(LASSRS const& other);
+  
+    
     std::string m_wkt;
     std::string m_proj4;
-    GTIF* m_gtiff;
-    ST_TIFF* m_tiff;
+    detail::raii_wrapper<ST_TIFF> m_tiff;
+    // detail::raii_wrapper<GTIF> m_gtiff;
+
 
 protected:
     

Modified: trunk/src/detail/reader.cpp
==============================================================================
--- trunk/src/detail/reader.cpp	(original)
+++ trunk/src/detail/reader.cpp	Sun Feb 15 23:19:09 2009
@@ -60,6 +60,7 @@
 #include <cassert>
 #include <cstdlib> // std::size_t
 #include <stdexcept>
+#include <iostream>
 
 namespace liblas { namespace detail {
 
@@ -127,57 +128,35 @@
 
 bool Reader::ReadGeoreference(LASHeader& header)
 {
-#ifndef HAVE_LIBGEOTIFF
-    UNREFERENCED_PARAMETER(header);
-#else
+// #ifndef HAVE_LIBGEOTIFF
+//     UNREFERENCED_PARAMETER(header);
+// #else
 
-    std::string const uid("LASF_Projection");
 
-    detail::raii_wrapper<ST_TIFF> st(ST_Create(), ST_Destroy);
 
+    std::vector<LASVLR> vlrs;
     for (uint16_t i = 0; i < header.GetRecordsCount(); ++i)
     {
         LASVLR record = header.GetVLR(i);
-        std::vector<uint8_t> data = record.GetData();
-        if (uid == record.GetUserId(true).c_str() && 34735 == record.GetRecordId())
-        {
-            int count = data.size()/sizeof(int16_t);
-            ST_SetKey(st.get(), record.GetRecordId(), count, STT_SHORT, &(data[0]));
-        }
-
-        if (uid == record.GetUserId(true).c_str() && 34736 == record.GetRecordId())
-        {
-            int count = data.size() / sizeof(double);
-            ST_SetKey(st.get(), record.GetRecordId(), count, STT_DOUBLE, &(data[0]));
-        }        
-
-        if (uid == record.GetUserId(true).c_str() && 34737 == record.GetRecordId())
-        {
-            int count = data.size()/sizeof(uint8_t);
-            ST_SetKey(st.get(), record.GetRecordId(), count, STT_ASCII, &(data[0]));
-        }
+        vlrs.push_back(record);
     }
+    LASSRS* ref =  new LASSRS(vlrs);
 
-    if (st.get()->key_count)
-    {
-        raii_wrapper<GTIF> gtif(GTIFNewSimpleTags(st.get()), GTIFFree);
-
-        GTIFDefn defn;
-        if (GTIFGetDefn(gtif.get(), &defn)) 
-        {
-            char* proj4def = GTIFGetProj4Defn(&defn);
-            std::string tmp(proj4def);
-            std::free(proj4def);
-
-            header.SetProj4(tmp);
-        }
+    LASSRS srs(vlrs);
+    
+    header.SetSRS(srs);
+    
+    header.SetProj4(ref->GetProj4());
+    
+    std::cout << ref->GetWKT() << std::endl;
+    
+    delete ref;
         
         return true;
-    }
 
-#endif /* def HAVE_LIBGEOTIFF */
+//#endif /* def HAVE_LIBGEOTIFF */
 
-    return false;
+//    return false;
 }
 
 Reader* ReaderFactory::Create(std::istream& ifs)

Modified: trunk/src/lasheader.cpp
==============================================================================
--- trunk/src/lasheader.cpp	(original)
+++ trunk/src/lasheader.cpp	Sun Feb 15 23:19:09 2009
@@ -44,6 +44,8 @@
 #include <liblas/cstdint.hpp>
 #include <liblas/guid.hpp>
 #include <liblas/detail/utility.hpp>
+#include <liblas/lassrs.hpp>
+
 // GeoTIFF
 #ifdef HAVE_LIBGEOTIFF
 #include <geotiff.h>
@@ -53,6 +55,7 @@
 #include "geovalues.h"
 #include "geotiffio.h"
 #endif // HAVE_LIBGEOTIFF
+
 //std
 #include <algorithm>
 #include <fstream>
@@ -882,5 +885,10 @@
 #endif // HAVE_LIBGEOTIFF
 }
 
+void LASHeader::SetSRS(LASSRS& srs)
+{
+    m_srs = srs;
+}
+
 } // namespace liblas
 

Modified: trunk/src/lassrs.cpp
==============================================================================
--- trunk/src/lassrs.cpp	(original)
+++ trunk/src/lassrs.cpp	Sun Feb 15 23:19:09 2009
@@ -41,52 +41,82 @@
 
 #include <liblas/lassrs.hpp>
 #include <liblas/detail/utility.hpp>
+#include <iostream>
 namespace liblas {
 
-LASSRS::LASSRS() 
+LASSRS::LASSRS() : 
+    m_tiff(ST_Create(), ST_Destroy)
 {
-    detail::raii_wrapper<ST_TIFF> m_tiff(ST_Create(), ST_Destroy);
-    detail::raii_wrapper<GTIF> m_gtiff(GTIFNewSimpleTags(m_tiff.get()), GTIFFree);    
+
 }
-// 
-// LASPoint::LASPoint(LASPoint const& other) :
-//     m_intensity(other.m_intensity),
-//     m_flags(other.m_flags),
-//     m_class(other.m_class),
-//     m_angleRank(other.m_angleRank),
-//     m_userData(other.m_userData),
-//     m_pointSourceId(other.m_pointSourceId),
-//     m_gpsTime(other.m_gpsTime)
+
+LASSRS::LASSRS(const std::vector<LASVLR>& vlrs) : 
+    m_tiff(ST_Create(), ST_Destroy)
+{
+
+
+    std::string const uid("LASF_Projection");
+
+    for (uint16_t i = 0; i < vlrs.size(); ++i)
+    {
+        LASVLR record = vlrs[i];
+        std::vector<uint8_t> data = record.GetData();
+        if (uid == record.GetUserId(true).c_str() && 34735 == record.GetRecordId())
+        {
+            int count = data.size()/sizeof(int16_t);
+            ST_SetKey(m_tiff.get(), record.GetRecordId(), count, STT_SHORT, &(data[0]));
+        }
+
+        if (uid == record.GetUserId(true).c_str() && 34736 == record.GetRecordId())
+        {
+            int count = data.size() / sizeof(double);
+            ST_SetKey(m_tiff.get(), record.GetRecordId(), count, STT_DOUBLE, &(data[0]));
+        }        
+
+        if (uid == record.GetUserId(true).c_str() && 34737 == record.GetRecordId())
+        {
+            int count = data.size()/sizeof(uint8_t);
+            ST_SetKey(m_tiff.get(), record.GetRecordId(), count, STT_ASCII, &(data[0]));
+        }
+    }
+
+    
+}
+
+bool LASSRS::HasKeys() 
+{
+    return (m_tiff.get()->key_count > 0);
+}
+
+// LASSRS::LASSRS()
 // {
-//     std::memcpy(m_coords, other.m_coords, sizeof(m_coords));
+//     // m_tiff = NULL;
+//     // m_gtiff = NULL;
 // }
-// 
-// LASPoint& LASPoint::operator=(LASPoint const& rhs)
+// LASSRS::LASSRS(LASSRS const& other) :
+//     m_tiff(other.m_tiff),
+//     m_gtiff(other.m_gtiff)
 // {
-//     if (&rhs != this)
-//     {
-//         m_coords[0] = rhs.m_coords[0];
-//         m_coords[1] = rhs.m_coords[1];
-//         m_coords[2] = rhs.m_coords[2];
-//         m_intensity = rhs.m_intensity;
-//         m_flags = rhs.m_flags;
-//         m_class = rhs.m_class;
-//         m_angleRank = rhs.m_angleRank;
-//         m_userData = rhs.m_userData;
-//         m_pointSourceId = rhs.m_pointSourceId;
-//         m_gpsTime = rhs.m_gpsTime;
-//     }
-//     return *this;
+// 
 // }
-
+// 
+LASSRS& LASSRS::operator=(LASSRS const& rhs)
+{
+    if (&rhs != this)
+    {
+        m_tiff = rhs.m_tiff;
+    }
+    return *this;
+}
+// 
 /// Fetch the SRS as WKT
 std::string LASSRS::GetWKT() const 
 {
-    GTIFDefn	sGTIFDefn;
+    GTIFDefn sGTIFDefn;
     char* pszWKT = NULL;
-    
-    if( GTIFGetDefn( m_gtiff, &sGTIFDefn ) ) {
-        pszWKT = GTIFGetOGISDefn( m_gtiff, &sGTIFDefn );
+    detail::raii_wrapper<GTIF> m_gtiff(GTIFNewSimpleTags(m_tiff.get()), GTIFFree);
+    if( GTIFGetDefn( m_gtiff.get(), &sGTIFDefn ) ) {
+        pszWKT = GTIFGetOGISDefn( m_gtiff.get(), &sGTIFDefn );
         if (pszWKT) {
             std::string tmp(pszWKT);
             std::free(pszWKT);
@@ -102,6 +132,22 @@
     m_wkt = v;
 }
 
+std::string LASSRS::GetProj4() const 
+{
+
+    GTIFDefn defn;
+    detail::raii_wrapper<GTIF> m_gtiff(GTIFNewSimpleTags(m_tiff.get()), GTIFFree);
+    if (GTIFGetDefn(m_gtiff.get(), &defn)) 
+    {
+        char* proj4def = GTIFGetProj4Defn(&defn);
+        std::string tmp(proj4def);
+        std::free(proj4def);
+
+        return tmp;
+    }
+
+    return std::string("");
+}
 
 
 } // namespace liblas


More information about the Liblas-commits mailing list