Skip to content

Commit

Permalink
Merge pull request #1483 from gadomski/text-reader-strip-whitespace-d…
Browse files Browse the repository at this point in the history
…imensions

Strip whitespace from dimension names in text reader
  • Loading branch information
abellgithub authored Feb 1, 2017
2 parents 5edf404 + 2e4f96c commit 6fe945d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions io/TextReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void TextReader::addDimensions(PointLayoutPtr layout)
{
for (auto name : m_dimNames)
{
name.erase(name.find_last_not_of(" \n\r\t") + 1);
Dimension::Id id = layout->registerOrAssignDim(name,
Dimension::Type::Double);
if (Utils::contains(m_dims, id))
Expand Down
1 change: 1 addition & 0 deletions test/data/text/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
intensity.txt text eol=crlf
11 changes: 11 additions & 0 deletions test/data/text/intensity.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
X,Y,Z,Intensity
289814.15,4320978.61,170.76,0
289814.64,4320978.84,170.76,1
289815.12,4320979.06,170.75,2
289815.60,4320979.28,170.74,3
289816.08,4320979.50,170.68,4
289816.56,4320979.71,170.66,5
289817.03,4320979.92,170.63,6
289817.53,4320980.16,170.62,7
289818.01,4320980.38,170.61,8
289818.50,4320980.59,170.58,9
20 changes: 19 additions & 1 deletion test/unit/io/TextReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,23 @@ TEST(TextReaderTest, badheader)
TEST(TextReaderTest, s1)
{
compareTextLasStreaming(Support::datapath("text/utm17_1.txt"),
Support::datapath("las/utm17.las"));
Support::datapath("las/utm17.las"));
}

TEST(TextReaderTest, strip_whitespace_from_dimension_names)
{
TextReader reader;
Options options;
options.add("filename", Support::datapath("text/intensity.txt"));
reader.setOptions(options);

PointTable table;
reader.prepare(table);
PointViewSet pointViewSet = reader.execute(table);
PointViewPtr pointViewPtr = *pointViewSet.begin();

for (PointId i = 0; i < pointViewPtr->size(); ++i) {
EXPECT_EQ(
i, pointViewPtr->getFieldAs<uint16_t>(Dimension::Id::Intensity, i));
}
}

0 comments on commit 6fe945d

Please sign in to comment.