Skip to content

Commit

Permalink
support pathlib.Path as option types for 'filename' #148 (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu authored Aug 7, 2023
1 parent 73b4690 commit dfdc448
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pdal/libpdalpython.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>
#include <pybind11/stl/filesystem.h>
#include <iostream>

#include <pdal/pdal_config.hpp>
Expand Down Expand Up @@ -108,6 +109,16 @@ namespace pdal {
return dims;
};

std::string getReaderDriver(std::filesystem::path const& p)
{
return StageFactory::inferReaderDriver(p.string());
}

std::string getWriterDriver(std::filesystem::path const& p)
{
return StageFactory::inferWriterDriver(p.string());
}

using pdal::python::PipelineExecutor;
using pdal::python::StreamableExecutor;

Expand Down Expand Up @@ -286,8 +297,8 @@ namespace pdal {
m.def("getDrivers", &getDrivers);
m.def("getOptions", &getOptions);
m.def("getDimensions", &getDimensions);
m.def("infer_reader_driver", &StageFactory::inferReaderDriver);
m.def("infer_writer_driver", &StageFactory::inferWriterDriver);
m.def("infer_reader_driver", &getReaderDriver);
m.def("infer_writer_driver", &getWriterDriver);
};

}; // namespace pdal
4 changes: 4 additions & 0 deletions pdal/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, Container, Dict, Iterator, List, Optional, Sequence, Union, cast

import numpy as np
import pathlib

try:
from meshio import Mesh
Expand Down Expand Up @@ -142,6 +143,9 @@ def toJSON(self) -> str:
for stage in stages:
stage2tag[stage] = stage.tag or _generate_tag(stage, stage2tag.values())
options = stage.options
for option in options:
if isinstance(options[option], pathlib.Path):
options[option] = str(options[option])
options["tag"] = stage2tag[stage]
options["type"] = stage.type
inputs = _get_input_tags(stage, stage2tag)
Expand Down
9 changes: 9 additions & 0 deletions test/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

import pdal
import pathlib

DATADIRECTORY = os.path.join(os.path.dirname(__file__), "data")

Expand Down Expand Up @@ -487,6 +488,14 @@ def test_meshio(self, filename):
assert len(triangles) == 134
assert triangles[0][0] == 29

def test_pathlib(self):
"""Can we build a pipeline using pathlib.Path as the filenames"""
path = pathlib.Path("test/data/autzen-utm.las")
read = pdal.Reader(path)
pipeline = read.pipeline()
pipeline.execute()


class TestDataFrame:

@pytest.mark.skipif(
Expand Down

0 comments on commit dfdc448

Please sign in to comment.