From b744a2fcde3d595f9b27c3c9a00fb92795000815 Mon Sep 17 00:00:00 2001 From: Howard Butler Date: Fri, 9 Mar 2018 13:22:35 -0600 Subject: [PATCH] support skipping header lines with an option in readers.text --- doc/stages/readers.text.rst | 3 +++ io/TextReader.cpp | 6 ++++++ io/TextReader.hpp | 1 + 3 files changed, 10 insertions(+) diff --git a/doc/stages/readers.text.rst b/doc/stages/readers.text.rst index a182934018..7da37d6f2c 100644 --- a/doc/stages/readers.text.rst +++ b/doc/stages/readers.text.rst @@ -79,6 +79,9 @@ header_insert String to use as the file header. All lines in the file as assumed to be records containing point data. +header_skip + Number of lines to skip before reading header + count Maximum number of points to read [Optional] diff --git a/io/TextReader.cpp b/io/TextReader.cpp index 4294637f42..f5d7794bca 100644 --- a/io/TextReader.cpp +++ b/io/TextReader.cpp @@ -131,7 +131,12 @@ void TextReader::initialize(PointTableRef table) if (!m_istream) throwError("Unable to open text file '" + m_filename + "'."); + std::string header; + + // Skip any lines requested + for (uint32_t i = 0; i < m_headerSkip; ++i) + std::getline(*m_istream, header); if (m_headerInsert.size()) header = m_headerInsert; else if (m_headerOverride.size()) @@ -155,6 +160,7 @@ void TextReader::addArgs(ProgramArgs& args) "the first line in the file.", m_headerOverride); args.add("header_insert", "Use this string as the header line. All " "lines of the file are treated as data.", m_headerInsert); + args.add("header_skip", "Use number to skip lines before starting reading. " , m_headerSkip, 0u); } diff --git a/io/TextReader.hpp b/io/TextReader.hpp index d4ca328f12..b56565895e 100644 --- a/io/TextReader.hpp +++ b/io/TextReader.hpp @@ -143,6 +143,7 @@ class PDAL_DLL TextReader : public Reader, public Streamable size_t m_line; std::string m_headerOverride; std::string m_headerInsert; + uint32_t m_headerSkip; }; } // namespace pdal