Skip to content

Commit

Permalink
Allow array pipelines without the encapsulating object. (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
connormanning authored and abellgithub committed Oct 3, 2018
1 parent 8f1eee4 commit e546cc6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
8 changes: 5 additions & 3 deletions doc/pipeline.rst
Expand Up @@ -33,10 +33,12 @@ a pipeline provides useful advantages for more complex things:
Introduction
--------------------------------------------------------------------------------

A PDAL processing pipeline is represented in JSON. The structure may either:

A JSON object represents a PDAL processing pipeline. The structure is always a
JSON object, with the primary object called ``pipeline`` being an array of
inferred or explicit PDAL :ref:`stage_object` representations.
- a JSON object, with a key called ``pipeline`` whose value is an array of
inferred or explicit PDAL :ref:`stage_object` representations.
- a JSON array, being the array described above without being encapsulated by a
JSON object.

Simple Example
................................................................................
Expand Down
14 changes: 11 additions & 3 deletions pdal/PipelineReaderJSON.cpp
Expand Up @@ -148,10 +148,18 @@ void PipelineReaderJSON::readPipeline(std::istream& input)
throw pdal_error(err);
}

Json::Value& subtree = root["pipeline"];
if (!subtree)
if (root.isObject() && root.isMember("pipeline"))
{
parsePipeline(root["pipeline"]);
}
else if (root.isArray())
{
parsePipeline(root);
}
else
{
throw pdal_error("JSON pipeline: Root element is not a Pipeline");
parsePipeline(subtree);
}
}


Expand Down
5 changes: 5 additions & 0 deletions test/data/pipeline/array-pipeline.json.in
@@ -0,0 +1,5 @@
[
"@CMAKE_SOURCE_DIR@/test/data/autzen/autzen-thin.las",
"@CMAKE_SOURCE_DIR@/test/temp/array-pipeline.las"
]

29 changes: 29 additions & 0 deletions test/unit/PipelineManagerTest.cpp
Expand Up @@ -157,6 +157,35 @@ TEST(PipelineManagerTest, InputGlobbing)
FileUtils::deleteFile(Support::temppath("globbed.las"));
}

TEST(PipelineManagerTest, arrayPipeline)
{
std::string cmd = Support::binpath(Support::exename("pdal") +
" pipeline");

std::string file(Support::configuredpath("pipeline/array-pipeline.json"));

std::string output;
int stat = Utils::run_shell_command(cmd + " " + file, output);
EXPECT_EQ(stat, 0);

StageFactory f;
Stage *r = f.createStage("readers.las");

Options o;
o.add("filename", Support::temppath("array-pipeline.las"));
r->setOptions(o);

PointTable t;
r->prepare(t);
PointViewSet s = r->execute(t);
EXPECT_EQ(s.size(), 1U);
PointViewPtr v = *(s.begin());

EXPECT_EQ(v->size(), 10653U);

FileUtils::deleteFile(Support::temppath("array-pipeline.las"));
}

TEST(PipelineManagerTest, replace)
{
PipelineManager mgr;
Expand Down

0 comments on commit e546cc6

Please sign in to comment.