[Liblas-commits] hg: reorganize some of the summary stuff
liblas-commits at liblas.org
liblas-commits at liblas.org
Sun Oct 10 23:26:06 EDT 2010
changeset 5e45e6abee41 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=5e45e6abee41
summary: reorganize some of the summary stuff
diffstat:
apps/las2las2.cpp | 16 +++++++--
apps/laskernel.cpp | 47 ++++++++++++++++++------------
apps/laskernel.hpp | 5 ++-
include/liblas/lasheader.hpp | 4 ++
include/liblas/utility.hpp | 6 ++-
src/lasheader.cpp | 67 +++++++++++++++++++++++--------------------
src/utility.cpp | 20 +++++++++++-
7 files changed, 106 insertions(+), 59 deletions(-)
diffs (truncated from 364 to 300 lines):
diff -r bae716d26b73 -r 5e45e6abee41 apps/las2las2.cpp
--- a/apps/las2las2.cpp Sun Oct 10 21:05:20 2010 -0500
+++ b/apps/las2las2.cpp Sun Oct 10 22:25:57 2010 -0500
@@ -151,7 +151,10 @@
ostringstream old_filename;
old_filename << out << "-" << fileno - 1 << ".las";
- RepairHeader(*summary, old_filename.str());
+ liblas::Header hnew = FetchHeader(old_filename.str());
+ RepairHeader(*summary, hnew);
+ RewriteHeader(hnew, old_filename.str());
+
delete summary;
summary = new liblas::Summary;
fileno++;
@@ -175,8 +178,10 @@
ostringstream old_filename;
old_filename << out << "-" << fileno - 1 << ".las";
-
- RepairHeader(*summary, old_filename.str());
+
+ liblas::Header hnew = FetchHeader(old_filename.str());
+ RepairHeader(*summary, hnew);
+ RewriteHeader(hnew, old_filename.str());
delete summary;
summary = new liblas::Summary;
fileno++;
@@ -199,7 +204,10 @@
delete writer;
delete ofs;
- RepairHeader(*summary, output);
+ liblas::Header hnew = FetchHeader(output);
+ RepairHeader(*summary, hnew);
+ RewriteHeader(hnew, output);
+
delete summary;
return true;
diff -r bae716d26b73 -r 5e45e6abee41 apps/laskernel.cpp
--- a/apps/laskernel.cpp Sun Oct 10 21:05:20 2010 -0500
+++ b/apps/laskernel.cpp Sun Oct 10 22:25:57 2010 -0500
@@ -99,8 +99,9 @@
os.precision(prec);
}
-void RepairHeader(liblas::Summary const& summary, std::string const& filename)
+liblas::Header FetchHeader(std::string const& filename)
{
+
std::ifstream ifs;
if (!liblas::Open(ifs, filename.c_str()))
{
@@ -111,11 +112,10 @@
liblas::Reader reader(ifs);
liblas::Header header = reader.GetHeader();
ifs.close();
-
- for (boost::uint32_t i = 0; i < 5; i++)
- {
- header.SetPointRecordsByReturnCount(i, 0);
- }
+ return header;
+}
+void RewriteHeader(liblas::Header const& header, std::string const& filename)
+{
std::ios::openmode m = std::ios::out | std::ios::in | std::ios::binary | std::ios::ate;
@@ -123,18 +123,33 @@
std::ofstream ofs(filename.c_str(), m);
liblas::Writer writer(ofs, header);
ofs.close();
+
+ // Write our updated header with summary info
+ std::ofstream ofs2(filename.c_str(), m);
+ liblas::Writer writer2(ofs2, header);
+ ofs2.close();
+}
+
+void RepairHeader(liblas::Summary const& summary, liblas::Header& header)
+{
+
+ for (boost::uint32_t i = 0; i < 5; i++)
+ {
+ header.SetPointRecordsByReturnCount(i, 0);
+ }
+
liblas::property_tree::ptree tree = summary.GetPTree();
try
{
- header.SetMin(tree.get<double>("minimum.x"),
- tree.get<double>("minimum.y"),
- tree.get<double>("minimum.z"));
+ header.SetMin(tree.get<double>("summary.points.minimum.x"),
+ tree.get<double>("summary.points.minimum.y"),
+ tree.get<double>("summary.points.minimum.z"));
- header.SetMax(tree.get<double>("maximum.x"),
- tree.get<double>("maximum.y"),
- tree.get<double>("maximum.z"));
+ header.SetMax(tree.get<double>("summary.points.maximum.x"),
+ tree.get<double>("summary.points.maximum.y"),
+ tree.get<double>("summary.points.maximum.z"));
} catch (liblas::property_tree::ptree_bad_path const& e)
{
@@ -151,7 +166,7 @@
}
BOOST_FOREACH(ptree::value_type &v,
- tree.get_child("points_by_return"))
+ tree.get_child("summary.points.points_by_return"))
{
boost::uint32_t i = v.second.get<boost::uint32_t>("id");
boost::uint32_t count = v.second.get<boost::uint32_t>("count");
@@ -164,12 +179,6 @@
return;
}
-
- // Write our updated header with summary info
- std::ofstream ofs2(filename.c_str(), m);
- liblas::Writer writer2(ofs2, header);
- ofs2.close();
-
}
bool IsDualRangeFilter(std::string parse_string)
diff -r bae716d26b73 -r 5e45e6abee41 apps/laskernel.hpp
--- a/apps/laskernel.hpp Sun Oct 10 21:05:20 2010 -0500
+++ b/apps/laskernel.hpp Sun Oct 10 22:25:57 2010 -0500
@@ -97,6 +97,9 @@
std::vector<char> TryReadRawFileData(std::string filename);
bool term_progress(std::ostream& os, double complete);
void SetStreamPrecision(std::ostream& os, double scale);
-void RepairHeader(liblas::Summary const& summary, std::string const& filename);
+
+liblas::Header FetchHeader(std::string const& filename);
+void RewriteHeader(liblas::Header const& header, std::string const& filename);
+void RepairHeader(liblas::Summary const& summary, liblas::Header& header);
#endif // LIBLAS_ITERATOR_HPP_INCLUDED
diff -r bae716d26b73 -r 5e45e6abee41 include/liblas/lasheader.hpp
--- a/include/liblas/lasheader.hpp Sun Oct 10 21:05:20 2010 -0500
+++ b/include/liblas/lasheader.hpp Sun Oct 10 22:25:57 2010 -0500
@@ -348,6 +348,10 @@
/// all of the header data in a structured format.
liblas::property_tree::ptree GetPTree() const;
+ void to_rst(std::ostream& os) const;
+ void to_xml(std::ostream& os) const;
+ void to_json(std::ostream& os) const;
+
private:
typedef detail::Point<double> PointScales;
diff -r bae716d26b73 -r 5e45e6abee41 include/liblas/utility.hpp
--- a/include/liblas/utility.hpp Sun Oct 10 21:05:20 2010 -0500
+++ b/include/liblas/utility.hpp Sun Oct 10 22:25:57 2010 -0500
@@ -70,7 +70,7 @@
void AddPoint(liblas::Point const& p);
ptree GetPTree() const;
-
+ void SetHeader(liblas::Header const& h);
private:
@@ -83,7 +83,9 @@
boost::array<boost::uint32_t, 8> returns_of_given_pulse;
bool first;
liblas::Point min;
- liblas::Point max;
+ liblas::Point max;
+ liblas::Header m_header;
+ bool bHaveHeader;
};
std::ostream& operator<<(std::ostream& os, liblas::Summary const& s);
diff -r bae716d26b73 -r 5e45e6abee41 src/lasheader.cpp
--- a/src/lasheader.cpp Sun Oct 10 21:05:20 2010 -0500
+++ b/src/lasheader.cpp Sun Oct 10 22:25:57 2010 -0500
@@ -782,15 +782,14 @@
return pt;
}
-std::ostream& operator<<(std::ostream& os, liblas::Header const& h)
+void Header::to_rst(std::ostream& os) const
{
+
using liblas::property_tree::ptree;
- ptree tree = h.GetPTree();
-
-
- os << "---------------------------------------------------------" << std::endl;
+ ptree tree = GetPTree();
os << " Header Summary" << std::endl;
os << "---------------------------------------------------------" << 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;
@@ -801,60 +800,60 @@
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: ";
try {
- os << tree.get_child("vlrs").size();
+ os << tree.get_child("vlrs").size();
}
catch (liblas::property_tree::ptree_bad_path const& e) {
- ::boost::ignore_unused_variable_warning(e);
- os << "None";
+ ::boost::ignore_unused_variable_warning(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;
-
+
std::ostringstream returns_oss;
BOOST_FOREACH(ptree::value_type &v,
- tree.get_child("returns"))
+ tree.get_child("returns"))
{
- returns_oss << v.second.get<std::string>("count")<< " ";
-
+ 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.z");
-
+
double frac = 0;
double integer = 0;
frac = std::modf(scale, &integer);
-
+
boost::uint32_t prec = static_cast<boost::uint32_t>(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;
+ << tree.get<double>("scale.x") << " "
+ << tree.get<double>("scale.y") << " "
+ << tree.get<double>("scale.z") << std::endl;
os << " Offset X Y Z: "
- << tree.get<double>("offset.x") << " "
- << tree.get<double>("offset.y") << " "
- << tree.get<double>("offset.x") << std::endl;
+ << tree.get<double>("offset.x") << " "
+ << tree.get<double>("offset.y") << " "
+ << tree.get<double>("offset.z") << std::endl;
os << " Min X Y Z: "
- << tree.get<double>("minimum.x") << " "
- << tree.get<double>("minimum.y") << " "
- << tree.get<double>("minimum.x") << std::endl;
+ << tree.get<double>("minimum.x") << " "
+ << tree.get<double>("minimum.y") << " "
+ << tree.get<double>("minimum.z") << std::endl;
os << " Max X Y Z: "
- << tree.get<double>("minimum.x") << " "
- << tree.get<double>("minimum.y") << " "
- << tree.get<double>("minimum.x") << std::endl;
-
+ << tree.get<double>("maximum.x") << " "
+ << tree.get<double>("maximum.y") << " "
+ << tree.get<double>("maximum.z") << std::endl;
+
os << " Spatial Reference: " << std::endl;
os << tree.get<std::string>("srs.prettywkt") << std::endl;
os << tree.get<std::string>("srs.gtiff") << std::endl;
@@ -884,6 +883,12 @@
// catch (liblas::property_tree::ptree_bad_path const& e) {
// ::boost::ignore_unused_variable_warning(e);
// }
+}
+std::ostream& operator<<(std::ostream& os, liblas::Header const& h)
+{
More information about the Liblas-commits
mailing list