Skip to content

Commit

Permalink
Allow chained writers without tags.
Browse files Browse the repository at this point in the history
Close #2438
  • Loading branch information
abellgithub committed Jun 21, 2019
1 parent 6e4fa9e commit bd9c077
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 34 deletions.
13 changes: 8 additions & 5 deletions pdal/PipelineReaderJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void PipelineReaderJSON::parsePipeline(NL::json& tree)
for (Stage *ts : inputs)
s->setInput(*ts);
inputs.clear();
inputs.push_back(s);
}
else
{
Expand Down Expand Up @@ -145,9 +146,11 @@ void PipelineReaderJSON::readPipeline(std::istream& input)
}
catch (NL::json::parse_error& err)
{
throw pdal_error(
std::string("JSON pipeline: Unable to parse pipeline:\n") +
err.what());
std::string s(err.what());
auto pos = s.find("]");
if (pos != std::string::npos)
s = s.substr(pos + 1);
throw pdal_error("Pipeline:" + s);
}

auto it = root.find("pipeline");
Expand All @@ -156,7 +159,7 @@ void PipelineReaderJSON::readPipeline(std::istream& input)
else if (root.is_array())
parsePipeline(root);
else
throw pdal_error("JSON pipeline: Root element is not a pipeline.");
throw pdal_error("Pipeline: root element is not a pipeline.");
}


Expand All @@ -165,7 +168,7 @@ void PipelineReaderJSON::readPipeline(const std::string& filename)
std::istream* input = Utils::openFile(filename);
if (!input)
{
throw pdal_error("JSON pipeline: Unable to open stream for "
throw pdal_error("Pipeline: Unable to open stream for "
"file \"" + filename + "\"");
}

Expand Down
13 changes: 13 additions & 0 deletions test/data/pipeline/issue2438.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pipeline":[
"@CMAKE_SOURCE_DIR@/test/data/las/autzen_trim.las",
{
"filename" : "@CMAKE_SOURCE_DIR@/test/temp/out2438_1.las",
"type" : "writers.las"
},
{
"filename" : "@CMAKE_SOURCE_DIR@/test/temp/out2438_2.las",
"type" : "writers.las"
}
]
}
57 changes: 28 additions & 29 deletions test/unit/apps/TranslateTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,23 @@ TEST(TranslateTest, t2)
std::string in = Support::datapath("las/autzen_trim.las");
std::string out = Support::temppath("out.las");

std::string json = " \
{ \
\\\"pipeline\\\" : [ \
{ \\\"type\\\":\\\"filters.stats\\\" }, \
{ \\\"type\\\":\\\"filters.range\\\", \
\\\"limits\\\":\\\"Z[0:100]\\\" } \
] \
}";
std::string json = R"(
[
{
\"type\": \"filters.stats\"
},
{
\"type\": \"filters.range\",
\"limits\": \"Z[0:100]\"
}
]
)";

// Check that we work with just a bunch of filters.
EXPECT_EQ(runTranslate(in + " " + out + " --json=\"" + json + "\"",
output), 0);

// Check that we fail with no bad input file.
// Check that we fail with no input file.
FileUtils::deleteFile("foo.las");
EXPECT_NE(runTranslate("foo.las " + out + " --json=\"" + json + "\"",
output), 0);
Expand All @@ -102,32 +105,28 @@ TEST(TranslateTest, t2)
output), 0);

// Check that we work with no stages.
json = " \
{ \
\\\"pipeline\\\" : [ \
] \
}";
json = R"(
[]
)";
EXPECT_EQ(runTranslate(in + " " + out + " --json=\"" + json + "\"",
output), 0);

// Check that we work with only an input (not specified as such).
json = " \
{ \
\\\"pipeline\\\" : [ \
\\\"badinput.las\\\" \
] \
}";
json = R"(
[
\"badinput.las\"
]
)";
EXPECT_EQ(runTranslate(in + " " + out + " --json=\"" + json + "\"",
output), 0);

// Check that we work with an input and an output.
json = " \
{ \
\\\"pipeline\\\" : [ \
\\\"badinput.las\\\", \
\\\"badoutput.las\\\" \
] \
}";
json = R"(
[
\"badinput.las\",
\"badoutput.las\"
]
)";
EXPECT_EQ(runTranslate(in + " " + out + " --json=\"" + json + "\"",
output), 0);

Expand Down Expand Up @@ -157,7 +156,7 @@ TEST(TranslateTest, t2)
EXPECT_EQ(runTranslate(in + " " + out + " --json=\"" + json + "\"",
output), 0);

// Check that we fail with unchanined multiple writers.
// Check that we succeed with unchanined multiple writers.
json = " \
{ \
\\\"pipeline\\\" : [ \
Expand All @@ -168,7 +167,7 @@ TEST(TranslateTest, t2)
\\\"badoutput2.las\\\" \
] \
}";
EXPECT_NE(runTranslate(in + " " + out + " --json=\"" + json + "\"",
EXPECT_EQ(runTranslate(in + " " + out + " --json=\"" + json + "\"",
output), 0);

// Check that we can handle chained writers.
Expand Down
12 changes: 12 additions & 0 deletions test/unit/apps/pcpipelineTestJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,16 @@ TEST(json, issue_2159)
EXPECT_EQ(srs, SpatialReference("EPSG:4326"));
}

TEST(json, issue_2438)
{
std::string file1(Support::temppath("out2438_1.las"));
std::string file2(Support::temppath("out2438_1.las"));

FileUtils::deleteFile(file1);
FileUtils::deleteFile(file2);
run_pipeline("pipeline/issue2438.json");
EXPECT_TRUE(FileUtils::fileExists(file1));
EXPECT_TRUE(FileUtils::fileExists(file2));
}

} // namespace pdal

0 comments on commit bd9c077

Please sign in to comment.