Skip to content

Commit

Permalink
Delete SRS VLRs from lists before adding new ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Nov 13, 2015
1 parent ae8cfc1 commit 9a9b358
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 17 deletions.
5 changes: 4 additions & 1 deletion filters/reprojection/ReprojectionFilter.cpp
Expand Up @@ -94,7 +94,6 @@ void ReprojectionFilter::processOptions(const Options& options)
try
{
m_inSRS = options.getValueOrThrow<pdal::SpatialReference>("in_srs");
std::cerr << "Read SRS = " << m_inSRS << "!\n";
m_inferInputSRS = false;
}
catch (std::invalid_argument)
Expand Down Expand Up @@ -143,6 +142,8 @@ void ReprojectionFilter::createTransform(PointView *view)
}
}

if (m_in_ref_ptr)
OSRDestroySpatialReference(m_in_ref_ptr);
m_in_ref_ptr = OSRNewSpatialReference(0);

int result =
Expand All @@ -157,6 +158,8 @@ void ReprojectionFilter::createTransform(PointView *view)
"in the source file.";
throw pdal_error(oss.str());
}
if (m_transform_ptr)
OCTDestroyCoordinateTransformation(m_transform_ptr);
m_transform_ptr = OCTNewCoordinateTransformation(m_in_ref_ptr,
m_out_ref_ptr);
if (!m_transform_ptr)
Expand Down
25 changes: 25 additions & 0 deletions include/pdal/util/Algorithm.hpp
Expand Up @@ -39,11 +39,36 @@
namespace pdal
{

namespace Utils
{

template<typename CONTAINER, typename VALUE>
bool contains(const CONTAINER& cont, const VALUE& val)
{
return std::find(cont.begin(), cont.end(), val) != cont.end();
}


template<typename KEY, typename VALUE>
bool contains(const std::map<KEY, VALUE>& c, const KEY& v)
{
return c.find(v) != c.end();
}


template<typename TYPE, typename VALUE>
void remove(std::vector<TYPE>& v, const VALUE& val)
{
v.erase(std::remove(v.begin(), v.end(), val), v.end());
}


template<typename TYPE, typename PREDICATE>
void remove_if(std::vector<TYPE>& v, PREDICATE p)
{
v.erase(std::remove_if(v.begin(), v.end(), p), v.end());
}

} // namespace Utils
} // namespace pdal

8 changes: 0 additions & 8 deletions include/pdal/util/Utils.hpp
Expand Up @@ -292,14 +292,6 @@ namespace Utils
std::string typeidName()
{ return Utils::demangle(typeid(T).name()); }

template<typename KEY, typename VALUE>
bool contains(const std::map<KEY, VALUE>& c, const KEY& v)
{ return c.find(v) != c.end(); }

template<typename COLLECTION, typename VALUE>
bool contains(const COLLECTION& c, const VALUE& v)
{ return (std::find(c.begin(), c.end(), v) != c.end()); }

struct RedirectStream
{
std::ofstream *m_out;
Expand Down
7 changes: 4 additions & 3 deletions io/las/LasError.hpp
Expand Up @@ -35,7 +35,7 @@

#include <vector>

#include <pdal/util/Utils.hpp>
#include <pdal/util/Algorithm.hpp>
#include <pdal/Log.hpp>

namespace pdal
Expand All @@ -59,8 +59,9 @@ class LasError
if (!Utils::contains(warned, returnNum))
{
warned.push_back(returnNum);
m_log->get(LogLevel::Warning) << m_filename << ": Found invalid value of '" <<
returnNum << "' for point's return number.\n";
m_log->get(LogLevel::Warning) << m_filename <<
": Found invalid value of '" << returnNum <<
"' for point's return number.\n";
}
}

Expand Down
21 changes: 21 additions & 0 deletions io/las/LasWriter.cpp
Expand Up @@ -41,6 +41,7 @@
#include <pdal/Compression.hpp>
#include <pdal/PDALUtils.hpp>
#include <pdal/PointView.hpp>
#include <pdal/util/Algorithm.hpp>
#include <pdal/util/Inserter.hpp>
#include <pdal/util/OStream.hpp>
#include <pdal/util/Utils.hpp>
Expand Down Expand Up @@ -416,6 +417,13 @@ void LasWriter::setVlrsFromMetadata(MetadataNode& forward)
/// \param srs - Active spatial reference.
void LasWriter::setVlrsFromSpatialRef()
{
// Delete any existing spatial ref VLRs.
deleteVlr(TRANSFORM_USER_ID, GEOTIFF_DIRECTORY_RECORD_ID);
deleteVlr(TRANSFORM_USER_ID, GEOTIFF_DOUBLES_RECORD_ID);
deleteVlr(TRANSFORM_USER_ID, GEOTIFF_ASCII_RECORD_ID);
deleteVlr(TRANSFORM_USER_ID, WKT_RECORD_ID);
deleteVlr(LIBLAS_USER_ID, WKT_RECORD_ID);

VlrList vlrs;

#ifdef PDAL_HAVE_LIBGEOTIFF
Expand Down Expand Up @@ -522,6 +530,19 @@ void LasWriter::addVlr(const std::string& userId, uint16_t recordId,
}
}

/// Delete a VLR from the vlr list.
///
void LasWriter::deleteVlr(const std::string& userId, uint16_t recordId)
{
auto matches = [&userId, recordId](const VariableLengthRecord& vlr)
{
return vlr.matches(userId, recordId);
};

Utils::remove_if(m_vlrs, matches);
Utils::remove_if(m_eVlrs, matches);
}


template <typename T>
void LasWriter::handleHeaderForward(const std::string& s, T& headerVal,
Expand Down
1 change: 1 addition & 0 deletions io/las/LasWriter.hpp
Expand Up @@ -152,6 +152,7 @@ class PDAL_DLL LasWriter : public FlexWriter
void openCompression();
void addVlr(const std::string& userId, uint16_t recordId,
const std::string& description, std::vector<uint8_t>& data);
void deleteVlr(const std::string& userId, uint16_t recordId);
bool addGeotiffVlr(GeotiffSupport& geotiff, uint16_t recordId,
const std::string& description);
bool addWktVlr();
Expand Down
6 changes: 2 additions & 4 deletions io/text/TextWriter.cpp
Expand Up @@ -42,8 +42,6 @@
#include <iostream>
#include <map>

#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/erase.hpp>
#include <boost/tokenizer.hpp>

namespace pdal
Expand Down Expand Up @@ -100,7 +98,7 @@ void TextWriter::processOptions(const Options& ops)
throw pdal_error(out.str());
}
m_outputType = ops.getValueOrDefault<std::string>("format", "csv");
boost::to_upper(m_outputType);
m_outputType = Utils::toupper(m_outputType);
m_callback = ops.getValueOrDefault<std::string>("jscallback", "");
m_writeAllDims = ops.getValueOrDefault<bool>("keep_unspecified", true);
m_dimOrder = ops.getValueOrDefault<std::string>("order", "");
Expand Down Expand Up @@ -143,7 +141,7 @@ void TextWriter::ready(PointTableRef table)
{
Dimension::IdList all = table.layout()->dims();
for (auto di = all.begin(); di != all.end(); ++di)
if (!contains(m_dims, *di))
if (!Utils::contains(m_dims, *di))
m_dims.push_back(*di);
}

Expand Down
1 change: 1 addition & 0 deletions plugins/pgpointcloud/test/PgpointcloudWriterTest.cpp
Expand Up @@ -36,6 +36,7 @@

#include <pdal/Writer.hpp>
#include <pdal/StageFactory.hpp>
#include <pdal/util/Algorithm.hpp>

#include "Support.hpp"
#include "Pgtest-Support.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/PointLayout.cpp
Expand Up @@ -33,7 +33,7 @@
****************************************************************************/

#include <pdal/PointLayout.hpp>
#include <pdal/util/Utils.hpp>
#include <pdal/util/Algorithm.hpp>

namespace pdal
{
Expand Down

0 comments on commit 9a9b358

Please sign in to comment.