Skip to content

Commit fc6ece6

Browse files
authored
Interface updates (#115)
* Interface updates * Make pipeline.metadata return an object instead of string * Make pipeline.quickinfo return an object instead of a string * Add iterator.metadata to return PointTable metadata * update tests
1 parent f4a1feb commit fc6ece6

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

pdal/StreamableExecutor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class StreamableExecutor : public PipelineExecutor
8484
int prefetch);
8585
~StreamableExecutor();
8686

87+
MetadataNode getMetadata() { return m_table.metadata(); }
8788
PyArrayObject* executeNext();
8889

8990
private:

pdal/libpdalpython.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ namespace pdal {
129129
return py::reinterpret_steal<py::array>((PyObject*)arr);
130130
}
131131

132+
py::object getMetadata() {
133+
py::object json = py::module_::import("json");
134+
135+
std::stringstream strm;
136+
MetadataNode root = (StreamableExecutor::getMetadata()).clone("metadata");
137+
pdal::Utils::toJSON(root, strm);
138+
139+
py::str pystring(strm.str());
140+
pystring.attr("strip");
141+
142+
py::object j;
143+
j = json.attr("loads")(pystring);
144+
145+
return j;
146+
147+
}
148+
132149
};
133150

134151
class Pipeline {
@@ -162,9 +179,23 @@ namespace pdal {
162179

163180
std::string getPipeline() { return getExecutor()->getPipeline(); }
164181

165-
std::string getQuickInfo() { return getExecutor()->getQuickInfo(); }
182+
py::object getQuickInfo() {
183+
py::gil_scoped_acquire acquire;
184+
py::object json = py::module_::import("json");
166185

167-
std::string getMetadata() { return getExecutor()->getMetadata(); }
186+
py::str pystring(getExecutor()->getQuickInfo());
187+
pystring.attr("strip");
188+
189+
py::object j;
190+
j = json.attr("loads")(pystring);
191+
192+
return j;
193+
194+
}
195+
196+
py::object getMetadata() {
197+
return py::module_::import("json").attr("loads")(getExecutor()->getMetadata());
198+
}
168199

169200
py::object getSchema() {
170201
return py::module_::import("json").attr("loads")(getExecutor()->getSchema());

test/test_pipeline.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ def test_metadata(self, filename):
114114
assert "Pipeline has not been executed" in str(info.value)
115115

116116
r.execute()
117-
j = json.loads(r.metadata)
118-
assert j["metadata"]["readers.las"]["count"] == 1065
117+
assert r.metadata["metadata"]["readers.las"]["count"] == 1065
119118

120119
@pytest.mark.parametrize("filename", ["sort.json", "sort.py"])
121120
def test_schema(self, filename):
@@ -361,7 +360,7 @@ def test_only_readers(self):
361360
def test_quickinfo(self):
362361
r = pdal.Reader("test/data/autzen-utm.las")
363362
p = r.pipeline()
364-
info = json.loads(p.quickinfo)
363+
info = p.quickinfo
365364
assert 'readers.las' in info.keys()
366365
assert info['readers.las']['num_points'] == 1065
367366

0 commit comments

Comments
 (0)