Skip to content

Commit

Permalink
Merge pull request #12 from hobu/metadata
Browse files Browse the repository at this point in the history
Metadata
  • Loading branch information
abellgithub authored Nov 13, 2020
2 parents c498ab5 + 1a959b5 commit fd8a617
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 18 deletions.
62 changes: 53 additions & 9 deletions bu/BuPyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ void BuPyramid::readBaseInfo()
if (c == '\n')
{
if (firstnl)
{
// Remove trailing newline.
s.resize(s.size() - 1);
return s;
}
else
firstnl = true;
}
Expand All @@ -113,17 +117,19 @@ void BuPyramid::readBaseInfo()
ss >> m_b.bounds.maxx >> m_b.bounds.maxy >> m_b.bounds.maxz;

ss.str(nextblock(in));
ss.clear();
ss >> m_b.trueBounds.minx >> m_b.trueBounds.miny >> m_b.trueBounds.minz;
ss >> m_b.trueBounds.maxx >> m_b.trueBounds.maxy >> m_b.trueBounds.maxz;

ss.str(nextblock(in));
ss >> m_b.srs;
std::cerr << "SRS = " << m_b.srs << "!\n";
std::string srs = nextblock(in);
if (srs != "NONE")
m_b.srs.set(srs);

if (!in)
throw "Couldn't read info file.";

ss.str(nextblock(in));
ss.clear();
m_b.pointSize = 0;
while (true)
{
Expand All @@ -136,7 +142,8 @@ void BuPyramid::readBaseInfo()
m_b.pointSize += pdal::Dimension::size(fdi.type);
m_b.dimInfo.push_back(fdi);
}
std::cerr << "Point size = " << m_b.pointSize << "!\n";
if (m_b.pointSize == 0)
throw "Couldn't read info file.";
}


Expand All @@ -153,6 +160,20 @@ void BuPyramid::createDirs()

void BuPyramid::writeInfo()
{
auto escapeQuotes = [](const std::string& in)
{
std::string out;
for (std::size_t i(0); i < in.size(); ++i)
{
if (in[i] == '"' && ((i && in[i - 1] != '\\') || !i))
{
out.push_back('\\');
}
out.push_back(in[i]);
}
return out;
};

auto typeString = [](pdal::Dimension::BaseType b)
{
using namespace pdal::Dimension;
Expand All @@ -174,12 +195,16 @@ void BuPyramid::writeInfo()

out << "{\n";

pdal::BOX3D& b = m_b.bounds;
out << "\"bounds\": [" <<
m_b.bounds.minx << ", " << m_b.bounds.miny << ", " << m_b.bounds.minz << ", " <<
m_b.bounds.maxx << ", " << m_b.bounds.maxy << ", " << m_b.bounds.maxz << "],\n";
b.minx << ", " << b.miny << ", " << b.minz << ", " <<
b.maxx << ", " << b.maxy << ", " << b.maxz << "],\n";

pdal::BOX3D& tb = m_b.trueBounds;
out << "\"boundsConforming\": [" <<
m_b.bounds.minx << ", " << m_b.bounds.miny << ", " << m_b.bounds.minz << ", " <<
m_b.bounds.maxx << ", " << m_b.bounds.maxy << ", " << m_b.bounds.maxz << "],\n";
tb.minx << ", " << tb.miny << ", " << tb.minz << ", " <<
tb.maxx << ", " << tb.maxy << ", " << tb.maxz << "],\n";

out << "\"dataType\": \"laszip\",\n";
out << "\"hierarchyType\": \"json\",\n";
out << "\"points\": " << m_manager.totalPoints() << ",\n";
Expand All @@ -193,14 +218,22 @@ void BuPyramid::writeInfo()
out << "\t{";
out << "\"name\": \"" << fdi.name << "\", ";
out << "\"type\": \"" << typeString(pdal::Dimension::base(fdi.type)) << "\", ";
if (fdi.name == "X" || fdi.name == "Y" || fdi.name == "Z")
out << "\"scale\": .01, \"offset\": 0, ";
out << "\"size\": " << pdal::Dimension::size(fdi.type) << " ";
out << "}";
if (di + 1 != m_b.dimInfo.end())
out << ",";
out << "\n";
}
out << "],\n";
out << "\"srs\": {}\n";
out << "\"srs\": {\n";
if (m_b.srs.valid())
{
out << "\"" << pdal::Utils::escapeJSON(escapeQuotes(m_b.srs.getWKT())) << "\"\n";
}
out << "}\n";

out << "}\n";
}

Expand Down Expand Up @@ -245,6 +278,17 @@ void BuPyramid::getInputFiles()
m_allFiles.erase(k);
};
}

/**
size_t sum = 0;
for (auto p : m_allFiles)
{
FileInfo& fi = p.second;
sum += fi.numPoints();
std::cerr << fi.filename() << "\t\t" << fi.numPoints() << "\t\t" << sum << "!\n";
}
exit(0);
**/
}


Expand Down
27 changes: 19 additions & 8 deletions epf/Epf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace epf
{

void writeMetadata(const std::string& outputDir, const Grid& grid,
const pdal::PointLayoutPtr& layout)
const std::string& srs, const pdal::PointLayoutPtr& layout)
{
std::ofstream out(outputDir + "/" + MetadataFilename);
pdal::BOX3D b = grid.processingBounds();
Expand All @@ -73,7 +73,7 @@ void writeMetadata(const std::string& outputDir, const Grid& grid,
out << b.maxx << " " << b.maxy << " " << b.maxz << "\n";
out << "\n";

out << "EPSG:4326" << "\n";
out << srs << "\n";
out << "\n";

for (Dimension::Id id : layout->dims())
Expand All @@ -83,7 +83,7 @@ void writeMetadata(const std::string& outputDir, const Grid& grid,

/// Epf

Epf::Epf() : m_pool(8)
Epf::Epf() : m_pool(8), m_srsFileInfo(nullptr)
{}

void Epf::addArgs(ProgramArgs& programArgs)
Expand Down Expand Up @@ -115,7 +115,10 @@ void Epf::run(const std::vector<std::string>& options)
throw Error("Output directory already contains EPT data.");

m_grid.setCubic(m_doCube);
std::vector<FileInfo> fileInfos = createFileInfo();

std::vector<FileInfo> fileInfos;
createFileInfo(fileInfos);

if (m_level != -1)
m_grid.resetLevel(m_level);

Expand Down Expand Up @@ -204,12 +207,12 @@ void Epf::run(const std::vector<std::string>& options)
m_pool.stop();
m_writer->stop();

writeMetadata(m_outputDir, m_grid, layout);
writeMetadata(m_outputDir, m_grid,
m_srsFileInfo ? m_srsFileInfo->srs.getWKT() : "NONE", layout);
}

std::vector<FileInfo> Epf::createFileInfo()
void Epf::createFileInfo(std::vector<FileInfo>& fileInfos)
{
std::vector<FileInfo> fileInfos;
std::vector<std::string> filenames;

// If any of the specified input files is a directory, get the names of the files
Expand Down Expand Up @@ -251,11 +254,19 @@ std::vector<FileInfo> Epf::createFileInfo()
fi.dimInfo.push_back(FileDimInfo(name));
fi.filename = filename;
fi.driver = driver;

if (m_srsFileInfo && m_srsFileInfo->srs != qi.m_srs)
{
std::cerr << "Files have mismatched SRS values. Using SRS from '" <<
m_srsFileInfo->filename << "'.\n";
}
fi.srs = qi.m_srs;
fileInfos.push_back(fi);
if (!m_srsFileInfo && qi.m_srs.valid())
m_srsFileInfo = &fileInfos.back();

m_grid.expand(qi.m_bounds, qi.m_pointCount);
}
return fileInfos;
}

} // namespace epf
Expand Down
4 changes: 3 additions & 1 deletion epf/Epf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <map>
#include <vector>

#include <pdal/SpatialReference.hpp>
#include <pdal/util/ThreadPool.hpp>

#include "EpfTypes.hpp"
Expand Down Expand Up @@ -46,7 +47,7 @@ class Epf

private:
void addArgs(pdal::ProgramArgs& programArgs);
std::vector<FileInfo> createFileInfo();
void createFileInfo(std::vector<FileInfo>& fileInfos);

std::vector<std::string> m_files;
std::string m_outputDir;
Expand All @@ -56,6 +57,7 @@ class Epf
size_t m_fileLimit;
int m_level;
bool m_doCube;
FileInfo *m_srsFileInfo;
};

} // namespace epf
Expand Down
2 changes: 2 additions & 0 deletions epf/EpfTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#pragma once

#include <pdal/Dimension.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/util/Bounds.hpp>

#include <cstdint>
Expand Down Expand Up @@ -47,6 +48,7 @@ struct FileInfo
DimInfoList dimInfo;
uint64_t numPoints;
pdal::BOX3D bounds;
pdal::SpatialReference srs;
};

} // namespace epf
Expand Down

0 comments on commit fd8a617

Please sign in to comment.