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

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Feb 16 15:34:30 EST 2009


Author: hobu
Date: Mon Feb 16 15:34:30 2009
New Revision: 1025
URL: http://liblas.org/changeset/1025

Log:
oh, it seems to work now :) 

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

Modified: trunk/include/liblas/lassrs.hpp
==============================================================================
--- trunk/include/liblas/lassrs.hpp	(original)
+++ trunk/include/liblas/lassrs.hpp	Mon Feb 16 15:34:30 2009
@@ -95,25 +95,23 @@
     ~LASSRS();
     LASSRS(const std::vector<LASVLR>& vlrs);
     LASSRS(LASSRS const& other);
-    // LASSRS& operator=(LASSRS const& rhs);
+    LASSRS& operator=(LASSRS const& rhs);
     
-    GTIF* GetGTIF();
-    void SetGTIF(GTIF* gtiff);
+    const GTIF* GetGTIF();
+    void SetGTIF(const GTIF* gtiff);
     void ResetVLRs();
     
     std::string GetWKT() const;
     void SetWKT(std::string const& v);
     
     std::string GetProj4() const;
-    void SetProj4();
+    void SetProj4(std::string const& v);
     
     void SetVLRs(const std::vector<LASVLR>& vlrs);
     std::vector<LASVLR> GetVLRs() const;
     
 
 private:
-
-// >     LASSRS(LASSRS const& other);
   
     GTIF* m_gtiff;
     ST_TIFF* m_tiff;

Modified: trunk/src/lasheader.cpp
==============================================================================
--- trunk/src/lasheader.cpp	(original)
+++ trunk/src/lasheader.cpp	Mon Feb 16 15:34:30 2009
@@ -98,7 +98,8 @@
     m_scales(other.m_scales),
     m_offsets(other.m_offsets),
     m_extents(other.m_extents),
-    m_proj4(other.m_proj4)
+    m_proj4(other.m_proj4),
+    m_srs(other.m_srs)
 {
     void* p = 0;
 
@@ -155,6 +156,7 @@
         m_offsets = rhs.m_offsets;
         m_extents = rhs.m_extents;
         m_proj4 = rhs.m_proj4;
+        m_srs = rhs.m_srs;
     }
     return *this;
 }
@@ -747,8 +749,6 @@
 // #else
 //     
     m_srs.SetVLRs(m_vlrs);
-    GTIF* gt = m_srs.GetGTIF();
-    m_srs.SetGTIF(gt);
     m_srs.ResetVLRs();
     
     std::vector<LASVLR> vlrs;

Modified: trunk/src/lassrs.cpp
==============================================================================
--- trunk/src/lassrs.cpp	(original)
+++ trunk/src/lassrs.cpp	Mon Feb 16 15:34:30 2009
@@ -47,7 +47,20 @@
 LASSRS::LASSRS() 
 
 {
+    m_tiff = NULL;
+    m_gtiff = NULL;
+}
 
+LASSRS& LASSRS::operator=(LASSRS const& rhs)
+{
+    if (&rhs != this)
+    {
+        m_tiff = NULL;
+        m_gtiff = NULL;        
+        SetVLRs(rhs.GetVLRs());
+        GetGTIF();
+    }
+    return *this;
 }
 
 LASSRS::~LASSRS() 
@@ -71,7 +84,10 @@
 
 LASSRS::LASSRS(LASSRS const& other) 
 {
+    m_tiff = NULL;
+    m_gtiff = NULL;
     SetVLRs(other.GetVLRs());
+    GetGTIF();
 }
 LASSRS::LASSRS(const std::vector<LASVLR>& vlrs) 
 {
@@ -108,8 +124,10 @@
     return m_vlrs;
 }
 
-void LASSRS::ResetVLRs() 
+void LASSRS::ResetVLRs()
 {
+
+
     int ret = 0;
     short* kdata = NULL;
     short kvalue = 0;
@@ -120,18 +138,11 @@
     int ktype = 0;
     int kcount = 0;
     
-        
-
-
-    ret = GTIFWriteKeys(m_gtiff);
-    if (!ret)
-	{
-        throw std::runtime_error("The geotiff keys could not be written");
-    }
-    
-    
     m_vlrs.clear();
     
+    if (!m_tiff) throw std::invalid_argument("m_tiff was null");
+    if (!m_gtiff) throw std::invalid_argument("m_gtiff was null");
+
     //GTIFF_GEOKEYDIRECTORY == 34735
     ret = ST_GetKey(m_tiff, 34735, &kcount, &ktype, (void**)&kdata);
     if (ret)
@@ -236,9 +247,11 @@
     }    
 }
 
-GTIF* LASSRS::GetGTIF(){
+const GTIF* LASSRS::GetGTIF(){
+
+    // if we're already set, don't overwrite
+    if (m_gtiff) return m_gtiff;
 
-    
     m_tiff = ST_Create();
     std::string const uid("LASF_Projection");
 
@@ -265,8 +278,6 @@
         }
     }
 
-
-
     if (m_tiff->key_count)
     {
         m_gtiff = GTIFNewSimpleTags(m_tiff);
@@ -279,32 +290,7 @@
     }
 }
 
-void LASSRS::SetGTIF(GTIF* gtiff)
-{
-    if (gtiff){
-        if (m_gtiff) {
-            GTIFFree(m_gtiff);
-            m_gtiff = NULL;
-            m_gtiff = gtiff;
-        }
-        if (m_tiff) {
-            ST_Destroy(m_tiff);
-            m_tiff = NULL;
-            m_tiff = (ST_TIFF*)gtiff->gt_tif;
-        }
-    }
-}
-
 
-// 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 
 {
@@ -327,7 +313,17 @@
        
 void LASSRS::SetWKT(std::string const& v)
 {
-    // m_wkt = v;
+
+#ifdef HAVE_GDAL
+    
+    int ret = 0;
+    ret = GTIFSetFromOGISDefn( m_gtiff, v.c_str() );
+    if (!ret) throw std::invalid_argument("could not set m_gtiff from WKT");
+#else
+    ;
+
+#endif
+
 }
 
 std::string LASSRS::GetProj4() const 
@@ -370,6 +366,34 @@
     return std::string("");
 }
 
+void LASSRS::SetProj4(std::string const& v)
+{
+
+#ifdef HAVE_GDAL
+
+    // std::string wkt = GetWKT();
+    char* poWKT = NULL;
+    const char* poProj4 = v.c_str();
+    OGRSpatialReference* poSRS = new OGRSpatialReference();
+    if( poSRS->importFromProj4((char *) poProj4) != OGRERR_NONE )
+    {
+        delete poSRS;
+    }
+    
+    poSRS->exportToWkt(&poWKT);
+    std::string tmp(poWKT);
+    std::free(poWKT);
+        
+    int ret = 0;
+    ret = GTIFSetFromOGISDefn( m_gtiff, tmp.c_str() );
+    if (!ret) throw std::invalid_argument("could not set m_gtiff from Proj4");
+#else
+    ;
+
+#endif
+
+}
+
 
 } // namespace liblas
 


More information about the Liblas-commits mailing list