[Liblas-commits] hg: 3 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Sat Aug 21 16:26:30 EDT 2010
changeset 8448d89273c1 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=8448d89273c1
summary: add GetPTree method
changeset ae530202a506 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=ae530202a506
summary: add GetPTree method
changeset 7b1e720b4f17 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=7b1e720b4f17
summary: use new VLR and SRS GetPTree methods
diffstat:
include/liblas/lasspatialreference.hpp | 8 +++
include/liblas/lasvariablerecord.hpp | 3 +
src/lasheader.cpp | 76 +++++++++++++++++++--------------
src/lasspatialreference.cpp | 42 ++++++++++++++++++
src/lasvariablerecord.cpp | 12 +++++
5 files changed, 108 insertions(+), 33 deletions(-)
diffs (241 lines):
diff -r aba1ed12dd3e -r 7b1e720b4f17 include/liblas/lasspatialreference.hpp
--- a/include/liblas/lasspatialreference.hpp Fri Aug 20 13:12:14 2010 -0500
+++ b/include/liblas/lasspatialreference.hpp Sat Aug 21 15:26:15 2010 -0500
@@ -74,10 +74,16 @@
#include <geovalues.h>
#endif // HAVE_LIBGEOTIFF
+
+// boost
+#include <boost/property_tree/ptree.hpp>
+
+
// std
#include <stdexcept> // std::out_of_range
#include <cstdlib> // std::size_t
#include <string>
+#include <stdio.h>
// Fake out the compiler if we don't have libgeotiff
#if !defined(LIBGEOTIFF_VERSION) && !defined(HAVE_LIBGEOTIFF)
@@ -184,6 +190,7 @@
/// Return a copy of the LASVLRs that SpatialReference maintains
std::vector<VariableRecord> GetVLRs() const;
+ boost::property_tree::ptree GetPTree() const;
private:
// FIXME: Define as shared_ptr<GTIF> with custom deleter to get rid of bloated mem management, unsafe anyway --mloskot
@@ -192,6 +199,7 @@
std::vector<VariableRecord> m_vlrs;
bool IsGeoVLR(VariableRecord const& vlr) const;
+ std::string GetGTIFFText() const;
/// Reset the VLRs of the SpatialReference using the existing GTIF* and ST_TIF*
/// Until this method is called,
diff -r aba1ed12dd3e -r 7b1e720b4f17 include/liblas/lasvariablerecord.hpp
--- a/include/liblas/lasvariablerecord.hpp Fri Aug 20 13:12:14 2010 -0500
+++ b/include/liblas/lasvariablerecord.hpp Sat Aug 21 15:26:15 2010 -0500
@@ -47,6 +47,7 @@
// boost
#include <boost/array.hpp>
#include <boost/cstdint.hpp>
+#include <boost/property_tree/ptree.hpp>
// std
#include <string>
#include <vector>
@@ -121,6 +122,8 @@
/// Get the total size of the VLR in bytes
std::size_t GetTotalSize() const;
+
+ boost::property_tree::ptree GetPTree() const;
private:
diff -r aba1ed12dd3e -r 7b1e720b4f17 src/lasheader.cpp
--- a/src/lasheader.cpp Fri Aug 20 13:12:14 2010 -0500
+++ b/src/lasheader.cpp Sat Aug 21 15:26:15 2010 -0500
@@ -780,13 +780,16 @@
pt.put("filesourceid", GetFileSourceId());
pt.put("reserved", GetReserved());
-#ifdef HAVE_GDAL
- pt.put("srs", GetSRS().GetWKT(liblas::SpatialReference::eHorizontalOnly, true));
-#else
-#ifdef HAVE_LIBGEOTIFF
- pt.put("srs", GetSRS().GetProj4());
-#endif
-#endif
+// #ifdef HAVE_GDAL
+// pt.put("srs", GetSRS().GetWKT(liblas::SpatialReference::eHorizontalOnly, true));
+// #else
+// #ifdef HAVE_LIBGEOTIFF
+// pt.put("srs", GetSRS().GetProj4());
+// #endif
+// #endif
+
+ ptree srs = GetSRS().GetPTree();
+ pt.add_child("srs", srs);
std::ostringstream date;
date << GetCreationDOY() << "/" << GetCreationYear();
@@ -827,14 +830,8 @@
pt.put("maximum.z", GetMaxZ());
- ptree vlr;
for (boost::uint32_t i=0; i< GetRecordsCount(); i++) {
- liblas::VariableRecord const& r = GetVLR(i);
- vlr.put("userid", r.GetUserId(false));
- vlr.put("description", r.GetDescription(false));
- vlr.put("length", r.GetRecordLength());
- vlr.put("id", r.GetRecordId());
- pt.add_child("vlrs.vlr", vlr);
+ pt.add_child("vlrs.vlr", GetVLR(i).GetPTree());
}
return pt;
@@ -859,7 +856,16 @@
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 << " Number Var. Length Records: ";
+ try {
+ os << tree.get_child("vlrs").size();
+ }
+ catch (boost::property_tree::ptree_bad_path const& e) {
+ os << "None";
+ }
+ os << 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;
@@ -904,29 +910,33 @@
<< tree.get<double>("minimum.x") << std::endl;
os << " Spatial Reference: " << std::endl;
- os << tree.get<std::string>("srs") << std::endl;
-
+ os << tree.get<std::string>("srs.prettywkt") << std::endl;
+ os << tree.get<std::string>("srs.gtiff") << 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;
+ try {
+ 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();
}
-
- os << vlrs_oss.str();
-
+ catch (boost::property_tree::ptree_bad_path const& e) {
+ }
return os;
}
diff -r aba1ed12dd3e -r 7b1e720b4f17 src/lasspatialreference.cpp
--- a/src/lasspatialreference.cpp Fri Aug 20 13:12:14 2010 -0500
+++ b/src/lasspatialreference.cpp Sat Aug 21 15:26:15 2010 -0500
@@ -652,5 +652,47 @@
ResetVLRs();
}
+boost::property_tree::ptree SpatialReference::GetPTree( ) const
+{
+ using boost::property_tree::ptree;
+ ptree srs;
+
+ srs.put("proj4", GetProj4());
+ srs.put("prettywkt", GetWKT(liblas::SpatialReference::eHorizontalOnly, true));
+ srs.put("wkt", GetWKT(liblas::SpatialReference::eHorizontalOnly, false));
+ srs.put("compoundwkt", GetWKT(eCompoundOK, false));
+ srs.put("prettycompoundwkt", GetWKT(eCompoundOK, true));
+ srs.put("gtiff", GetGTIFFText());
+
+ return srs;
+
+}
+
+std::string SpatialReference::GetGTIFFText() const
+{
+ std::ostringstream oss;
+ char buffer [L_tmpnam];
+ char * pointer;
+ tmpnam (buffer);
+ FILE* f = fopen(buffer, "wb");
+ GTIFPrint((GTIF*)m_gtiff, 0, f);
+ fclose(f);
+
+ f = fopen(buffer, "rb");
+ boost::uint32_t file_size;
+
+ fseek (f , 0 , SEEK_END);
+ file_size = ftell(f);
+ rewind(f);
+
+ char* data = (char*) malloc(sizeof(char)*file_size);
+ size_t result = fread(data, 1, file_size, f);
+ fclose(f);
+
+ std::string output(data);
+ free(data);
+ return output;
+}
+
} // namespace liblas
diff -r aba1ed12dd3e -r 7b1e720b4f17 src/lasvariablerecord.cpp
--- a/src/lasvariablerecord.cpp Fri Aug 20 13:12:14 2010 -0500
+++ b/src/lasvariablerecord.cpp Sat Aug 21 15:26:15 2010 -0500
@@ -211,5 +211,17 @@
return sum;
}
+boost::property_tree::ptree VariableRecord::GetPTree( ) const
+{
+ using boost::property_tree::ptree;
+ ptree vlr;
+
+ vlr.put("userid", GetUserId(false));
+ vlr.put("description", GetDescription(false));
+ vlr.put("length", GetRecordLength());
+ vlr.put("id", GetRecordId());
+ return vlr;
+
+}
} // namespace liblas
More information about the Liblas-commits
mailing list