[Liblas-commits] hg: start on re-enabling SRS transformation
methods to C API
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Jan 26 12:15:12 EST 2011
details: http://hg.liblas.orghg/rev/5f20ff1a6bee
changeset: 2821:5f20ff1a6bee
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Jan 26 10:52:00 2011 -0600
description:
start on re-enabling SRS transformation methods to C API
Subject: hg: put back liblas::WriterImpl point count accounting. The point count given to us from a header upon liblas::Writer creation should not be believed because of opening files in append mode
details: http://hg.liblas.orghg/rev/b419fa13bed9
changeset: 2822:b419fa13bed9
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Jan 26 11:15:06 2011 -0600
description:
put back liblas::WriterImpl point count accounting. The point count given to us from a header upon liblas::Writer creation should not be believed because of opening files in append mode
diffstat:
include/liblas/detail/writer/header.hpp | 3 +-
include/liblas/detail/writer/point.hpp | 3 +-
src/c_api.cpp | 98 +++++++++++++++++++++-----------
src/detail/writer/header.cpp | 10 ++-
src/detail/writer/point.cpp | 7 +-
src/detail/writer/writer.cpp | 25 +++-----
src/detail/writer/zipwriter.cpp | 12 +---
7 files changed, 88 insertions(+), 70 deletions(-)
diffs (truncated from 372 to 300 lines):
diff -r b71d99522ec2 -r b419fa13bed9 include/liblas/detail/writer/header.hpp
--- a/include/liblas/detail/writer/header.hpp Wed Jan 26 09:47:57 2011 -0600
+++ b/include/liblas/detail/writer/header.hpp Wed Jan 26 11:15:06 2011 -0600
@@ -57,7 +57,7 @@
public:
- Header(std::ostream& ofs, liblas::Header const& header );
+ Header(std::ostream& ofs, boost::uint32_t& count, liblas::Header const& header );
liblas::Header const& GetHeader() const { return m_header; }
void write();
@@ -71,6 +71,7 @@
std::ostream& m_ofs;
liblas::Header m_header;
+ boost::uint32_t& m_pointCount;
};
}}} // namespace liblas::detail::writer
diff -r b71d99522ec2 -r b419fa13bed9 include/liblas/detail/writer/point.hpp
--- a/include/liblas/detail/writer/point.hpp Wed Jan 26 09:47:57 2011 -0600
+++ b/include/liblas/detail/writer/point.hpp Wed Jan 26 11:15:06 2011 -0600
@@ -60,7 +60,7 @@
{
public:
- Point(std::ostream& ofs, HeaderPtr header);
+ Point(std::ostream& ofs, boost::uint32_t& count, HeaderPtr header);
virtual ~Point();
// const liblas::Point& GetPoint() const { return m_point; }
@@ -85,6 +85,7 @@
std::vector<boost::uint8_t> m_blanks;
void setup();
+ boost::uint32_t& m_pointCount;
// void fill();
};
diff -r b71d99522ec2 -r b419fa13bed9 src/c_api.cpp
--- a/src/c_api.cpp Wed Jan 26 09:47:57 2011 -0600
+++ b/src/c_api.cpp Wed Jan 26 11:15:06 2011 -0600
@@ -90,7 +90,14 @@
#define compare_no_case(a,b,n) strncasecmp( (a), (b), (n) )
#endif
-
+#include <boost/lambda/lambda.hpp>
+
+bool IsReprojectionTransform(liblas::TransformPtr const& p)
+{
+ if (dynamic_cast<liblas::ReprojectionTransform*>(p.get()))
+ return true;
+ return false;
+}
LAS_C_START
@@ -393,21 +400,7 @@
return (LASHeaderH) new liblas::Header( header );
}
-LAS_DLL LASErrorEnum LASReader_SetSRS(LASHeaderH hReader, const LASSRSH hSRS) {
-
- VALIDATE_LAS_POINTER1(hReader, "LASReader_SetSRS", LE_Failure);
- VALIDATE_LAS_POINTER1(hSRS, "LASReader_SetSRS", LE_Failure);
-
- try {
- // ((liblas::Reader*) hReader)->SetSRS(*((liblas::SpatialReference*)hSRS));
- }
- catch (std::exception const& e) {
- LASError_PushError(LE_Failure, e.what(), "LASReader_SetSRS");
- return LE_Failure;
- }
-
- return LE_None;
-}
+
LAS_DLL LASErrorEnum LASReader_SetInputSRS(LASHeaderH hReader, const LASSRSH hSRS) {
@@ -415,7 +408,11 @@
VALIDATE_LAS_POINTER1(hSRS, "LASReader_SetInputSRS", LE_Failure);
try {
- // ((liblas::Reader*) hReader)->SetInputSRS(*((liblas::SpatialReference*)hSRS));
+ liblas::Reader* reader = ((liblas::Reader*) hReader);
+ liblas::Header h = reader->GetHeader();
+ liblas::SpatialReference* ref = ((liblas::SpatialReference*) hSRS);
+ h.SetSRS(*ref);
+ reader->SetHeader(h);
}
catch (std::exception const& e) {
LASError_PushError(LE_Failure, e.what(), "LASReader_SetInputSRS");
@@ -425,12 +422,27 @@
return LE_None;
}
+
LAS_DLL LASErrorEnum LASReader_SetOutputSRS(LASHeaderH hReader, const LASSRSH hSRS) {
VALIDATE_LAS_POINTER1(hReader, "LASReader_SetOutputSRS", LE_Failure);
VALIDATE_LAS_POINTER1(hSRS, "LASReader_SetOutputSRS", LE_Failure);
try {
+ liblas::Reader* reader = ((liblas::Reader*) hReader);
+ liblas::Header h = reader->GetHeader();
+ liblas::SpatialReference in_ref = h.GetSRS();
+ liblas::SpatialReference* out_ref = ((liblas::SpatialReference*) hSRS);
+ std::vector<liblas::TransformPtr> transforms = reader->GetTransforms();
+
+ transforms.erase( std::remove_if( transforms.begin(),
+ transforms.end(),
+ boost::bind( &IsReprojectionTransform, _1 ) ),
+ transforms.end());
+
+ liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, *out_ref, liblas::HeaderPtr(new liblas::Header(h))));
+ transforms.insert(transforms.begin(), srs_transform);
+
// ((liblas::Reader*) hReader)->SetOutputSRS(*((liblas::SpatialReference*)hSRS));
}
catch (std::exception const& e) {
@@ -441,6 +453,14 @@
return LE_None;
}
+LAS_DLL LASErrorEnum LASReader_SetSRS(LASHeaderH hReader, const LASSRSH hSRS) {
+
+ VALIDATE_LAS_POINTER1(hReader, "LASReader_SetSRS", LE_Failure);
+ VALIDATE_LAS_POINTER1(hSRS, "LASReader_SetSRS", LE_Failure);
+
+ return LASReader_SetOutputSRS(hReader, hSRS);
+}
+
LAS_DLL LASHeaderH LASHeader_Create(void) {
return (LASHeaderH) new liblas::Header();
}
@@ -1671,29 +1691,17 @@
}
-LAS_DLL LASErrorEnum LASWriter_SetSRS(LASWriterH hWriter, const LASSRSH hSRS) {
-
- VALIDATE_LAS_POINTER1(hWriter, "LASWriter_SetSRS", LE_Failure);
- VALIDATE_LAS_POINTER1(hSRS, "LASWriter_SetSRS", LE_Failure);
-
- try {
- // ((liblas::Writer*) hWriter)->SetSRS(*((liblas::SpatialReference*)hSRS));
- }
- catch (std::exception const& e) {
- LASError_PushError(LE_Failure, e.what(), "LASWriter_SetSRS");
- return LE_Failure;
- }
-
- return LE_None;
-}
-
LAS_DLL LASErrorEnum LASWriter_SetInputSRS(LASWriterH hWriter, const LASSRSH hSRS) {
VALIDATE_LAS_POINTER1(hWriter, "LASWriter_SetInputSRS", LE_Failure);
VALIDATE_LAS_POINTER1(hSRS, "LASWriter_SetInputSRS", LE_Failure);
try {
- // ((liblas::Writer*) hWriter)->SetInputSRS(*((liblas::SpatialReference*)hSRS));
+ liblas::Writer* writer = ((liblas::Writer*) hWriter);
+ liblas::Header h = writer->GetHeader();
+ liblas::SpatialReference* srs = ((liblas::SpatialReference*) hSRS);
+ h.SetSRS(*srs);
+ writer->SetHeader(h);
}
catch (std::exception const& e) {
LASError_PushError(LE_Failure, e.what(), "LASWriter_SetInputSRS");
@@ -1709,7 +1717,19 @@
VALIDATE_LAS_POINTER1(hSRS, "LASWriter_SetOutputSRS", LE_Failure);
try {
- // ((liblas::Writer*) hWriter)->SetOutputSRS(*((liblas::SpatialReference*)hSRS));
+ liblas::Writer* writer = ((liblas::Writer*) hWriter);
+ liblas::Header h = writer->GetHeader();
+ liblas::SpatialReference in_ref = h.GetSRS();
+ liblas::SpatialReference* out_ref = ((liblas::SpatialReference*) hSRS);
+ std::vector<liblas::TransformPtr> transforms = writer->GetTransforms();
+
+ transforms.erase( std::remove_if( transforms.begin(),
+ transforms.end(),
+ boost::bind( &IsReprojectionTransform, _1 ) ),
+ transforms.end());
+
+ liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, *out_ref, liblas::HeaderPtr(new liblas::Header(h))));
+ transforms.insert(transforms.begin(), srs_transform);
}
catch (std::exception const& e) {
LASError_PushError(LE_Failure, e.what(), "LASWriter_SetOutputSRS");
@@ -1719,6 +1739,14 @@
return LE_None;
}
+LAS_DLL LASErrorEnum LASWriter_SetSRS(LASWriterH hWriter, const LASSRSH hSRS) {
+
+ VALIDATE_LAS_POINTER1(hWriter, "LASWriter_SetSRS", LE_Failure);
+ VALIDATE_LAS_POINTER1(hSRS, "LASWriter_SetSRS", LE_Failure);
+
+ return LASWriter_SetOutputSRS(hWriter, hSRS);
+}
+
LAS_DLL LASHeaderH LASWriter_GetHeader(const LASWriterH hWriter)
{
VALIDATE_LAS_POINTER1(hWriter, "LASWriter_GetHeader", NULL);
diff -r b71d99522ec2 -r b419fa13bed9 src/detail/writer/header.cpp
--- a/src/detail/writer/header.cpp Wed Jan 26 09:47:57 2011 -0600
+++ b/src/detail/writer/header.cpp Wed Jan 26 11:15:06 2011 -0600
@@ -64,9 +64,10 @@
namespace liblas { namespace detail { namespace writer {
-Header::Header(std::ostream& ofs, liblas::Header const& header)
+Header::Header(std::ostream& ofs, boost::uint32_t& count, liblas::Header const& header)
: m_ofs(ofs)
, m_header(header)
+ , m_pointCount(count)
{
}
@@ -115,7 +116,10 @@
throw std::runtime_error(oss.str());
}
- m_header.SetPointRecordsCount(count);
+ m_pointCount = static_cast<uint32_t>(count);
+
+ } else {
+ m_pointCount = m_header.GetPointRecordsCount();
}
// Position to the beginning of the file to start writing the header
@@ -307,7 +311,7 @@
}
// If we already have points, we're going to put it at the end of the file.
// If we don't have any points, we're going to leave it where it is.
- if (m_header.GetPointRecordsCount() != 0)
+ if (m_pointCount != 0)
{
m_ofs.seekp(0, std::ios::end);
}
diff -r b71d99522ec2 -r b419fa13bed9 src/detail/writer/point.cpp
--- a/src/detail/writer/point.cpp Wed Jan 26 09:47:57 2011 -0600
+++ b/src/detail/writer/point.cpp Wed Jan 26 11:15:06 2011 -0600
@@ -55,10 +55,11 @@
namespace liblas { namespace detail { namespace writer {
-Point::Point(std::ostream& ofs, HeaderPtr header)
+Point::Point(std::ostream& ofs, boost::uint32_t& count, HeaderPtr header)
: m_ofs(ofs)
, m_header(header)
, m_format(header->GetSchema())
+ , m_pointCount(count)
{
setup();
}
@@ -90,8 +91,8 @@
std::vector<boost::uint8_t> const& data = point.GetData();
detail::write_n(m_ofs, data.front(), m_header->GetDataRecordLength());
-
- m_header->SetPointRecordsCount(m_header->GetPointRecordsCount() + 1);
+
+ m_pointCount++;
// write in our extra data that the user set on the
// point up to the header's specified DataRecordLength
diff -r b71d99522ec2 -r b419fa13bed9 src/detail/writer/writer.cpp
--- a/src/detail/writer/writer.cpp Wed Jan 26 09:47:57 2011 -0600
+++ b/src/detail/writer/writer.cpp Wed Jan 26 11:15:06 2011 -0600
@@ -54,16 +54,18 @@
namespace liblas { namespace detail {
WriterImpl::WriterImpl(std::ostream& ofs) :
- m_ofs(ofs),
- m_point_writer(PointWriterPtr( )),
- m_header_writer(HeaderWriterPtr())
+ m_ofs(ofs)
+ , m_point_writer(PointWriterPtr( ))
+ , m_header_writer(HeaderWriterPtr())
+ , m_header(HeaderPtr())
+ , m_pointCount(0)
{
}
void WriterImpl::WriteHeader()
{
- m_header_writer = HeaderWriterPtr(new writer::Header(m_ofs, *m_header) );
+ m_header_writer = HeaderWriterPtr(new writer::Header(m_ofs, m_pointCount, *m_header) );
m_header_writer->write();
@@ -72,8 +74,8 @@
More information about the Liblas-commits
mailing list