Skip to content

Commit 9f63ea7

Browse files
authored
implement QuickInfo support (#109)
1 parent 50ec016 commit 9f63ea7

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

pdal/PyPipeline.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "PyArray.hpp"
3636
#include "PyPipeline.hpp"
37+
#include <pdal/util/Utils.hpp>
3738

3839
#ifndef _WIN32
3940
#include <dlfcn.h>
@@ -132,6 +133,74 @@ std::string PipelineExecutor::getSchema() const
132133
}
133134

134135

136+
MetadataNode computePreview(Stage* stage)
137+
{
138+
if (!stage)
139+
throw pdal_error("no valid stage in QuickInfo");
140+
141+
QuickInfo qi = stage->preview();
142+
if (!qi.valid())
143+
throw pdal_error("No summary data available for stage '" + stage->getName()+"'" );
144+
145+
std::stringstream strm;
146+
MetadataNode summary(stage->getName());
147+
summary.add("num_points", qi.m_pointCount);
148+
if (qi.m_srs.valid())
149+
{
150+
MetadataNode srs = qi.m_srs.toMetadata();
151+
summary.add(srs);
152+
}
153+
if (qi.m_bounds.valid())
154+
{
155+
MetadataNode bounds = Utils::toMetadata(qi.m_bounds);
156+
summary.add(bounds.clone("bounds"));
157+
}
158+
159+
std::string dims;
160+
auto di = qi.m_dimNames.begin();
161+
while (di != qi.m_dimNames.end())
162+
{
163+
dims += *di;
164+
++di;
165+
if (di != qi.m_dimNames.end())
166+
dims += ", ";
167+
}
168+
if (dims.size())
169+
summary.add("dimensions", dims);
170+
pdal::Utils::toJSON(summary, strm);
171+
return summary;
172+
173+
}
174+
175+
176+
std::string PipelineExecutor::getQuickInfo() const
177+
{
178+
179+
Stage* stage(nullptr);
180+
std::vector<Stage *> stages = m_manager.stages();
181+
std::vector<Stage *> previewStages;
182+
183+
for (auto const& s: stages)
184+
{
185+
auto n = s->getName();
186+
auto v = pdal::Utils::split2(n,'.');
187+
if (v.size() > 0)
188+
if (pdal::Utils::iequals(v[0], "readers"))
189+
previewStages.push_back(s);
190+
}
191+
192+
MetadataNode summary;
193+
for (auto const& stage: previewStages)
194+
{
195+
MetadataNode n = computePreview(stage);
196+
summary.add(n);
197+
}
198+
199+
std::stringstream strm;
200+
pdal::Utils::toJSON(summary, strm);
201+
return strm.str();
202+
}
203+
135204
void PipelineExecutor::addArrayReaders(std::vector<std::shared_ptr<Array>> arrays)
136205
{
137206
// Make the symbols in pdal_base global so that they're accessible

pdal/PyPipeline.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class PDAL_DLL PipelineExecutor {
5959
const PointViewSet& views() const;
6060
std::string getPipeline() const;
6161
std::string getMetadata() const;
62+
std::string getQuickInfo() const;
6263
std::string getSchema() const;
6364
std::string getLog() const { return m_logStream.str(); }
6465

pdal/libpdalpython.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ namespace pdal {
9595

9696
std::string getPipeline() { return getExecutor()->getPipeline(); }
9797

98+
std::string getQuickInfo() { return getExecutor()->getQuickInfo(); }
99+
98100
std::string getMetadata() { return getExecutor()->getMetadata(); }
99101

100102
py::object getSchema() {
@@ -161,6 +163,7 @@ namespace pdal {
161163
.def_property_readonly("log", &Pipeline::getLog)
162164
.def_property_readonly("schema", &Pipeline::getSchema)
163165
.def_property_readonly("pipeline", &Pipeline::getPipeline)
166+
.def_property_readonly("quickinfo", &Pipeline::getQuickInfo)
164167
.def_property_readonly("metadata", &Pipeline::getMetadata)
165168
.def_property_readonly("arrays", &Pipeline::getArrays)
166169
.def_property_readonly("meshes", &Pipeline::getMeshes)

test/test_pipeline.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ def test_only_readers(self):
362362
assert count2 == 2 * count1
363363
np.testing.assert_array_equal(np.concatenate([array1, array1]), array2)
364364

365+
def test_quickinfo(self):
366+
r = pdal.Reader("test/data/autzen-utm.las")
367+
p = r.pipeline()
368+
info = json.loads(p.quickinfo)
369+
assert 'readers.las' in info.keys()
370+
assert info['readers.las']['num_points'] == 1065
365371

366372
class TestArrayLoad:
367373
def test_merged_arrays(self):

0 commit comments

Comments
 (0)