Skip to content

Commit

Permalink
Allow a count to be provided as part of pdal info --query.
Browse files Browse the repository at this point in the history
Close #922
  • Loading branch information
abellgithub committed Jun 25, 2015
1 parent aa558c9 commit 5075b6e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
5 changes: 3 additions & 2 deletions doc/apps.rst
Expand Up @@ -208,8 +208,9 @@ Dumps information about a point cloud file, such as:
--point [-p] arg Display points for particular points. Points can be specified in
a range or list: 4-10, 15, 255-300.
--query arg Add a listing of points based on the distance from the provided
location.
--query "25.34,35.123" or --query "11532.23 -10e23 1.234"
location. The number of points returned can be limited by
providing an optional count.
--query "25.34,35.123/3" or --query "11532.23 -10e23 1.234/10"
--stats Display the minimum, maximum, average and count of each
dimension.
--boundary Compute a hexagonal boundary that contains all points.
Expand Down
35 changes: 31 additions & 4 deletions kernels/info/InfoKernel.cpp
Expand Up @@ -113,6 +113,9 @@ void InfoKernel::validateSwitches()
m_needPoints = true;
}

if (m_pointIndexes.size() && m_queryPoint.size())
throw pdal_error("--point option incompatible with --query option.");

if (m_showSummary && functions > 1)
throw pdal_error("--summary option incompatible with other "
"specified options.");
Expand Down Expand Up @@ -142,7 +145,9 @@ void InfoKernel::addSwitches()
"dump the schema")
("point,p", po::value<std::string >(&m_pointIndexes), "point to dump")
("query", po::value< std::string>(&m_queryPoint),
"A 2d or 3d point query point")
"Return points in order of distance from the specified "
"location (2D or 3D)\n"
"--query Xcoord,Ycoord[,Zcoord][/count]")
("stats",
po::value<bool>(&m_showStats)->zero_tokens()->implicit_value(true),
"dump stats on all points (reads entire dataset)")
Expand Down Expand Up @@ -345,6 +350,7 @@ MetadataNode InfoKernel::run(const std::string& filename)
return root;
}


void InfoKernel::dump(MetadataNode& root)
{
if (m_showSchema)
Expand Down Expand Up @@ -396,9 +402,30 @@ void InfoKernel::dump(MetadataNode& root)

MetadataNode InfoKernel::dumpQuery(PointViewPtr inView) const
{
int count;
std::string location;

// See if there's a provided point count.
StringList parts = Utils::split2(m_queryPoint, '/');
if (parts.size() == 2)
{
location = parts[0];
count = atoi(parts[1].c_str());
}
else if (parts.size() == 1)
{
location = parts[0];
count = inView->size();
}
else
count = 0;
if (count == 0)
throw pdal_error("Invalid location specificiation. "
"--query=\"X,Y[/count]\"");

auto seps = [](char c){ return (c == ',' || c == '|' || c == ' '); };

std::vector<std::string> tokens = Utils::split2(m_queryPoint, seps);
std::vector<std::string> tokens = Utils::split2(location, seps);
std::vector<double> values;
for (auto ti = tokens.begin(); ti != tokens.end(); ++ti)
values.push_back(boost::lexical_cast<double>(*ti));
Expand All @@ -413,13 +440,13 @@ MetadataNode InfoKernel::dumpQuery(PointViewPtr inView) const
{
KD3Index kdi(*inView);
kdi.build();
ids = kdi.neighbors(values[0], values[1], values[2], inView->size());
ids = kdi.neighbors(values[0], values[1], values[2], count);
}
else
{
KD2Index kdi(*inView);
kdi.build();
ids = kdi.neighbors(values[0], values[1], inView->size());
ids = kdi.neighbors(values[0], values[1], count);
}

for (auto i = ids.begin(); i != ids.end(); ++i)
Expand Down

0 comments on commit 5075b6e

Please sign in to comment.