[Liblas-commits] hg-main-tree: support io through operator>> and
operator<< for S...
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Jun 14 17:04:40 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/94e490fbce51
changeset: 785:94e490fbce51
user: Howard Butler <hobu.inc at gmail.com>
date: Tue Jun 14 16:04:34 2011 -0500
description:
support io through operator>> and operator<< for SpatialReference via boost::property_tree
diffstat:
include/pdal/SpatialReference.hpp | 4 +++
src/SpatialReference.cpp | 41 +++++++++++++++++++++++++++++++++++--
test/unit/SpatialReferenceTest.cpp | 21 +++++++++++++++++++
3 files changed, 63 insertions(+), 3 deletions(-)
diffs (110 lines):
diff -r 03200c0ec8b3 -r 94e490fbce51 include/pdal/SpatialReference.hpp
--- a/include/pdal/SpatialReference.hpp Tue Jun 14 11:00:21 2011 -0500
+++ b/include/pdal/SpatialReference.hpp Tue Jun 14 16:04:34 2011 -0500
@@ -107,12 +107,16 @@
boost::property_tree::ptree getPTree() const;
+ const std::string& getDescription() const;
+ const std::string& getName() const;
+
private:
std::string m_wkt;
};
extern PDAL_DLL std::ostream& operator<<(std::ostream& ostr, const SpatialReference& srs);
+extern PDAL_DLL std::istream& operator>>(std::istream& istr, SpatialReference& srs);
} // namespace pdal
diff -r 03200c0ec8b3 -r 94e490fbce51 src/SpatialReference.cpp
--- a/src/SpatialReference.cpp Tue Jun 14 11:00:21 2011 -0500
+++ b/src/SpatialReference.cpp Tue Jun 14 16:04:34 2011 -0500
@@ -33,7 +33,10 @@
****************************************************************************/
#include <pdal/SpatialReference.hpp>
+
#include <boost/concept_check.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+
// gdal
#ifdef PDAL_HAVE_GDAL
@@ -282,11 +285,43 @@
std::ostream& operator<<(std::ostream& ostr, const SpatialReference& srs)
{
- ostr << "SRS: ";
- ostr << srs.getWKT();
- ostr << std::endl;
+
+#ifdef PDAL_SRS_ENABLED
+ boost::property_tree::ptree tree;
+ std::string name = srs.getName();
+ tree.put_child(name, srs.getPTree());
+ boost::property_tree::write_xml(ostr, tree);
return ostr;
+
+#else
+ throw pdal_error ("SpatialReference io operator<< is not available without GDAL+libgeotiff support");
+#endif
}
+std::istream& operator>>(std::istream& istr, SpatialReference& srs)
+{
+
+#ifdef PDAL_SRS_ENABLED
+ boost::property_tree::ptree tree;
+ boost::property_tree::read_xml(istr, tree, 0);
+ std::string wkt = tree.get<std::string>("pdal.spatialreference.compoundwkt");
+ SpatialReference ref;
+ ref.setWKT(wkt);
+ srs = ref;
+ return istr;
+
+#else
+ throw pdal_error ("SpatialReference io operator>> is not available without GDAL+libgeotiff support");
+#endif
+}
+
+
+
+const std::string& SpatialReference::getName() const
+{
+ static std::string name("pdal.spatialreference");
+ return name;
+}
+
} // namespace pdal
diff -r 03200c0ec8b3 -r 94e490fbce51 test/unit/SpatialReferenceTest.cpp
--- a/test/unit/SpatialReferenceTest.cpp Tue Jun 14 11:00:21 2011 -0500
+++ b/test/unit/SpatialReferenceTest.cpp Tue Jun 14 16:04:34 2011 -0500
@@ -362,4 +362,25 @@
}
+
+BOOST_AUTO_TEST_CASE(test_io)
+{
+ const std::string wkt = "COMPD_CS[\"WGS 84 + VERT_CS\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],VERT_CS[\"NAVD88 height\",VERT_DATUM[\"North American Vertical Datum 1988\",2005,AUTHORITY[\"EPSG\",\"5103\"],EXTENSION[\"PROJ4_GRIDS\",\"g2003conus.gtx\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Up\",UP],AUTHORITY[\"EPSG\",\"5703\"]]]";
+
+ pdal::SpatialReference ref;
+ ref.setFromUserInput(wkt);
+
+ std::stringstream ss(std::stringstream::in | std::stringstream::out);
+
+ ss << ref;
+
+ pdal::SpatialReference ref2;
+ ss >> ref2;
+
+ BOOST_CHECK(ref == ref2);
+
+
+ return;
+}
+
BOOST_AUTO_TEST_SUITE_END()
More information about the Liblas-commits
mailing list