Skip to content

Commit

Permalink
Make --stdin work on kernels.tindex.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Jan 30, 2018
1 parent 073445e commit 2cb5e84
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kernels/TIndexKernel.cpp
Expand Up @@ -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",
Expand Down Expand Up @@ -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.");
Expand Down
62 changes: 62 additions & 0 deletions test/unit/apps/TIndexTest.cpp
Expand Up @@ -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);
}

0 comments on commit 2cb5e84

Please sign in to comment.