diff --git a/kernels/TIndexKernel.cpp b/kernels/TIndexKernel.cpp index 6ee3c6af61..50c7d68538 100644 --- a/kernels/TIndexKernel.cpp +++ b/kernels/TIndexKernel.cpp @@ -87,7 +87,7 @@ void TIndexKernel::addSwitches(ProgramArgs& args) args.add("tindex", "OGR-readable/writeable tile index output", m_idxFilename).setPositional(); args.add("filespec", "Build: Pattern of files to index. " - "Merge: Output filename", m_filespec).setPositional(); + "Merge: Output filename", m_filespec).setOptionalPositional(); args.add("fast_boundary", "Use extent instead of exact boundary", m_fastBoundary); args.add("lyr_name", "OGR layer name to write into datasource", @@ -140,6 +140,9 @@ void TIndexKernel::validateSwitches(ProgramArgs& args) { if (m_filespec.empty() && !m_usestdin) throw pdal_error("No input pattern specified"); + if (m_filespec.size() && m_usestdin) + throw pdal_error("Can't specify both --filespec and --stdin " + "options."); if (args.set("polygon")) throw pdal_error("'polygon' option not supported when building " "index."); diff --git a/test/unit/apps/TIndexTest.cpp b/test/unit/apps/TIndexTest.cpp index 16310ba750..438755120b 100644 --- a/test/unit/apps/TIndexTest.cpp +++ b/test/unit/apps/TIndexTest.cpp @@ -82,3 +82,65 @@ TEST(TIndex, test1) EXPECT_NE(pos, std::string::npos); } +TEST(TIndex, test2) +{ + std::string inSpec(Support::datapath("tindex/*.txt")); + std::string outSpec(Support::temppath("tindex.out")); + + FileUtils::deleteDirectory(outSpec); + std::string cmd = Support::binpath("pdal") + " tindex --stdin " + + outSpec + " \"" + inSpec + "\" 2>&1"; + + std::string output; + Utils::run_shell_command(cmd, output); + std::string::size_type pos = output.find("Can't specify both"); + EXPECT_NE(pos, std::string::npos); + + cmd = Support::binpath("pdal") + " tindex --stdin " + + outSpec + " --filespec=\"" + inSpec + "\" 2>&1"; + Utils::run_shell_command(cmd, output); + pos = output.find("Can't specify both"); + EXPECT_NE(pos, std::string::npos); +} + +// Indentical to test1, but filespec input comes from find command. +TEST(TIndex, test3) +{ + std::string outSpec(Support::temppath("tindex.out")); + std::string outPoints(Support::temppath("points.txt")); + + std::string cmd = "find " + Support::datapath("tindex") + + " -name \"*.txt\" | " + Support::binpath("pdal") + " tindex --stdin " + + outSpec; + + FileUtils::deleteDirectory(outSpec); + + std::string output; + Utils::run_shell_command(cmd, output); + + cmd = Support::binpath("pdal") + " --verbose=info tindex --merge " + + outSpec + " " + outPoints + " --log=stdout " + "--bounds=\"([1.25, 3],[1.25, 3])\""; + + FileUtils::deleteFile(outPoints); + Utils::run_shell_command(cmd, output); + std::string::size_type pos = output.find("Merge filecount: 3"); + EXPECT_NE(pos, std::string::npos); + + cmd = Support::binpath("pdal") + " --verbose=info tindex --merge " + + outSpec + " " + outPoints + " --log=stdout " + "--bounds=\"([1.25, 2],[1.25, 2])\""; + FileUtils::deleteFile(outPoints); + Utils::run_shell_command(cmd, output); + pos = output.find("Merge filecount: 2"); + EXPECT_NE(pos, std::string::npos); + + cmd = Support::binpath("pdal") + " --verbose=info tindex --merge " + + outSpec + " " + outPoints + " --log=stdout " + "--bounds=\"([1.25, 1.75],[1.25, 1.75])\""; + FileUtils::deleteFile(outPoints); + Utils::run_shell_command(cmd, output); + pos = output.find("Merge filecount: 1"); + EXPECT_NE(pos, std::string::npos); +} +