Skip to content

Commit

Permalink
provide --fast-boundary method for pdal tindex to just use the bbox o…
Browse files Browse the repository at this point in the history
…f the file instead of hexbin boundary
  • Loading branch information
hobu committed Jun 7, 2015
1 parent 7d581fb commit 43cdf30
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
74 changes: 65 additions & 9 deletions kernels/tindex/TIndexKernel.cpp
Expand Up @@ -47,6 +47,7 @@
#include <pdal/KernelFactory.hpp>
#include <pdal/util/FileUtils.hpp>
#include <merge/MergeFilter.hpp>
#include <pdal/PDALUtils.hpp>

#include <cpl_string.h>

Expand Down Expand Up @@ -87,6 +88,7 @@ TIndexKernel::TIndexKernel()
, m_merge(false)
, m_dataset(NULL)
, m_layer(NULL)
, m_fastBoundary(false)

{
m_log.setLeader("pdal tindex");
Expand All @@ -105,6 +107,8 @@ void TIndexKernel::addSwitches()
"OGR-readable/writeable tile index output")
("filespec", po::value<std::string>(&m_filespec),
"Build: Pattern of files to index. Merge: Output filename")
("fast-boundary", po::value<bool>(&m_fastBoundary)->zero_tokens()->implicit_value(true),
"use extend instead of exact boundary")
("lyr_name", po::value<std::string>(&m_layerName),
"OGR layer name to write into datasource")
("tindex_name", po::value<std::string>(&m_tileIndexColumnName)->
Expand All @@ -113,6 +117,8 @@ void TIndexKernel::addSwitches()
default_value("ESRI Shapefile"), "OGR driver name to use ")
("t_srs", po::value<std::string>(&m_tgtSrsString)->
default_value("EPSG:4326"), "Target SRS of tile index")
("a_srs", po::value<std::string>(&m_assignSrsString)->
default_value("EPSG:4326"), "Assign SRS of tile with no SRS to this value")
("geometry", po::value<std::string>(&m_filterGeom),
"Geometry to filter points when merging.")
("write_absolute_path", po::value<bool>(&m_absPath)->
Expand Down Expand Up @@ -501,6 +507,7 @@ TIndexKernel::FileInfo TIndexKernel::getFileInfo(KernelFactory& factory,
InfoKernel *info = static_cast<InfoKernel *>(app.get());

info->doShowAll(true);
info->doComputeBoundary(!m_fastBoundary);
info->prepare(filename);

MetadataNode metadata;
Expand All @@ -513,7 +520,54 @@ TIndexKernel::FileInfo TIndexKernel::getFileInfo(KernelFactory& factory,
}

fileInfo.m_filename = filename;
fileInfo.m_boundary = metadata.findChild("boundary:boundary").value();
if (!m_fastBoundary)
fileInfo.m_boundary = metadata.findChild("boundary:boundary").value();
else
{
auto findNode = [](MetadataNode m,
const std::string name, const std::string val)
{
auto findNameVal = [name, val](MetadataNode m)
{ return (m.name() == name && m.value() == val); };

return m.find(findNameVal);
};
std::ostringstream polygon;
polygon.precision(10);
polygon.setf(std::ios::fixed);
polygon << "POLYGON ((";

MetadataNode stats = metadata.findChild("stats");
std::vector<MetadataNode> children = stats.children();
std::string minx, miny, minz;
std::string maxx, maxy, maxz;
for (auto mi = children.begin(); mi != children.end(); ++mi)
{

if (findNode(*mi, "name", "X").valid())
{
minx = mi->findChild("minimum").value();
maxx = mi->findChild("maximum").value();
}
if (findNode(*mi, "name", "Y").valid())
{
miny = mi->findChild("minimum").value();
maxy = mi->findChild("maximum").value();
}
}

polygon << minx << " " << miny;
polygon << ", " << maxx << " " << miny;
polygon << ", " << maxy << " " << maxy;
polygon << ", " << maxy << " " << minx;
polygon << ", " << minx << " " << miny;
polygon << "))";

fileInfo.m_boundary = polygon.str();



}
fileInfo.m_srs = metadata.findChild("summary:spatial_reference").value();

FileUtils::fileTimes(filename, &fileInfo.m_ctime, &fileInfo.m_mtime);
Expand Down Expand Up @@ -632,14 +686,14 @@ TIndexKernel::FieldIndexes TIndexKernel::getFields()
indexes.m_ctime = OGR_FD_GetFieldIndex(fDefn, "created");
indexes.m_mtime = OGR_FD_GetFieldIndex(fDefn, "modified");

/* Load in memory existing file names in SHP */
int nExistingFiles = (int)OGR_L_GetFeatureCount(m_layer, FALSE);
for (auto i = 0; i < nExistingFiles; i++)
{
OGRFeatureH hFeature = OGR_L_GetNextFeature(m_layer);
m_files.push_back(OGR_F_GetFieldAsString(hFeature, indexes.m_filename));
OGR_F_Destroy(hFeature);
}
// /* Load in memory existing file names in SHP */
// int nExistingFiles = (int)OGR_L_GetFeatureCount(m_layer, FALSE);
// for (auto i = 0; i < nExistingFiles; i++)
// {
// OGRFeatureH hFeature = OGR_L_GetNextFeature(m_layer);
// m_files.push_back(OGR_F_GetFieldAsString(hFeature, indexes.m_filename));
// OGR_F_Destroy(hFeature);
// }
return indexes;
}

Expand All @@ -655,6 +709,8 @@ Geometry TIndexKernel::prepareGeometry(const FileInfo& fileInfo)
fileInfo.m_filename << "'.";
throw pdal_error(oss.str());
}
if (srcSrs.empty())
srcSrs = SpatialRef(m_assignSrsString);

SpatialRef tgtSrs(m_tgtSrsString);
if (!tgtSrs)
Expand Down
2 changes: 2 additions & 0 deletions kernels/tindex/TIndexKernel.hpp
Expand Up @@ -111,6 +111,8 @@ class PDAL_DLL TIndexKernel : public Kernel
void *m_dataset;
void *m_layer;
std::string m_tgtSrsString;
std::string m_assignSrsString;
bool m_fastBoundary;
};

} // namespace pdal
Expand Down

0 comments on commit 43cdf30

Please sign in to comment.