Skip to content

Commit

Permalink
don't do fancy non-working magic to try to calculate a point count fo…
Browse files Browse the repository at this point in the history
…r files in append mode #48
  • Loading branch information
hobu committed Jul 21, 2014
1 parent 05d9d9c commit eb35d1a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
25 changes: 2 additions & 23 deletions src/detail/writer/header.cpp
Expand Up @@ -100,35 +100,14 @@ void Header::write()
// If we are in append mode, we are not touching *any* VLRs.
if (bAppendMode)
{
// We're opened in append mode

if (!m_header.Compressed())
{
ios::off_type points = end - static_cast<ios::off_type>(m_header.GetDataOffset());
ios::off_type count = points / static_cast<ios::off_type>(m_header.GetDataRecordLength());

if (points < 0) {
std::ostringstream oss;
oss << "The header's data offset, " << m_header.GetDataOffset()
<<", is much larger than the size of the file, " << end
<<", and something is amiss. Did you use the right header"
<<" offset value?";
throw std::runtime_error(oss.str());
}

m_pointCount = static_cast<uint32_t>(count);

} else {
m_pointCount = m_header.GetPointRecordsCount();
}
// Believe the header
m_pointCount = m_header.GetPointRecordsCount();

// Position to the beginning of the file to start writing the header
m_ofs.seekp(0, ios::beg);

}
else
{

// Rewrite the georeference VLR entries if they exist
m_header.DeleteVLRs("liblas", 2112);
m_header.SetGeoreference();
Expand Down
4 changes: 2 additions & 2 deletions src/detail/writer/writer.cpp
Expand Up @@ -77,7 +77,7 @@ void WriterImpl::UpdatePointCount(boost::uint32_t count)
boost::uint32_t out = m_pointCount;

if ( count != 0 ) { out = count; }

m_header->SetPointRecordsCount(out);

if (!m_ofs.good() ) return;
Expand All @@ -102,7 +102,7 @@ WriterImpl::~WriterImpl()
// care if we weren't able to write it.
try
{
UpdatePointCount(0);
UpdatePointCount(m_pointCount);

} catch (std::runtime_error const&)
{
Expand Down

0 comments on commit eb35d1a

Please sign in to comment.