Skip to content

Commit

Permalink
support skipping header lines with an option in readers.text
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Mar 9, 2018
1 parent 0cd6591 commit b744a2f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/stages/readers.text.rst
Expand Up @@ -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]

Expand Down
6 changes: 6 additions & 0 deletions io/TextReader.cpp
Expand Up @@ -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())
Expand All @@ -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);
}


Expand Down
1 change: 1 addition & 0 deletions io/TextReader.hpp
Expand Up @@ -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

0 comments on commit b744a2f

Please sign in to comment.