From 43caeb901214d07fccea37b21962aa74e5dd7709 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Mon, 23 Oct 2023 11:51:26 +0300 Subject: [PATCH] add an option to read input data from a text file to tile command (#29) * add an option to read input data from a text file to tile command * use parseSimple() o instead of parse() as we don't need validation of mandatory parameters * update README --- README.md | 6 ++++++ src/tile/tile.cpp | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37a5f3d..f0776ad 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,12 @@ Creates tiles from input data. For example to get tiles sized 100x100: pdal_wrench tile --length=100 --output=/data/tiles data1.las data2.las data3.las ``` +This tool can also read input data from a text file (one file per line) + +``` +pdal_wrench tile --length=100 --output=/data/tiles --input-file-list=my_list.txt +``` + ## thin Creates a thinned version of the point cloud by only keeping every N-th point (`every-nth` mode) or keep points based on their distance (`sample` mode). diff --git a/src/tile/tile.cpp b/src/tile/tile.cpp index f4a3f70..cbd85ed 100644 --- a/src/tile/tile.cpp +++ b/src/tile/tile.cpp @@ -124,6 +124,7 @@ struct BaseInfo int max_threads; std::string outputFormat; // las or laz (for now) bool buildVpc = false; + std::string inputFileList; // file list with input files } opts; pdal::BOX3D trueBounds; @@ -434,6 +435,7 @@ void addArgs(pdal::ProgramArgs& programArgs, BaseInfo::Options& options, pdal::A { programArgs.add("output,o", "Output directory/filename", options.outputDir); programArgs.add("files,i", "Input files/directory", options.inputFiles).setPositional(); + programArgs.add("input-file-list", "Read input files from a text file", options.inputFileList); programArgs.add("length,l", "Tile length", options.tileLength, 1000.); tempArg = &(programArgs.add("temp_dir", "Temp directory", options.tempDir)); programArgs.add("output-format", "Output format (las/laz)", options.outputFormat); @@ -461,7 +463,7 @@ bool handleOptions(pdal::StringList& arglist, BaseInfo::Options& options) addArgs(programArgs, options, tempArg, threadsArg); try { - programArgs.parse(arglist); + programArgs.parseSimple(arglist); } catch (const pdal::arg_error& err) { @@ -498,6 +500,22 @@ bool handleOptions(pdal::StringList& arglist, BaseInfo::Options& options) throw FatalError("Unknown output format: " + options.outputFormat); } + if (!options.inputFileList.empty()) + { + std::ifstream inputFile(options.inputFileList); + std::string line; + if(!inputFile) + { + throw FatalError("Failed to open input file list: " + options.inputFileList); + } + + while (std::getline(inputFile, line)) + { + options.inputFiles.push_back(line); + } + } + + return true; }