Skip to content

Commit

Permalink
more pdal metadata VLR WIP -- a test too
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Mar 8, 2017
1 parent 0b7700c commit d97a978
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 12 deletions.
12 changes: 11 additions & 1 deletion io/LasReader.cpp
Expand Up @@ -360,12 +360,22 @@ void LasReader::extractHeaderMetadata(MetadataNode& forward, MetadataNode& m)
m_header.pointCount(), "This field contains the total "
"number of point records within the file.");

// PDAL metadata VLR
LasVLR *vlr = m_header.findVlr("PDAL", 12);
if (vlr)
{
const char *pos = vlr->data();
size_t size = vlr->dataLen();
m.addWithType("pdal", std::string(pos, size), "json", "PDAL Processing Metadata");
m.addWithType("pdal_metadata", std::string(pos, size), "json", "PDAL Processing Metadata");
}
//
// PDAL pipeline VLR
vlr = m_header.findVlr("PDAL", 13);
if (vlr)
{
const char *pos = vlr->data();
size_t size = vlr->dataLen();
m.addWithType("pdal_pipeline", std::string(pos, size), "json", "PDAL Processing Pipeline");
}

}
Expand Down
31 changes: 21 additions & 10 deletions io/LasWriter.cpp
Expand Up @@ -244,6 +244,9 @@ void LasWriter::fillForwardList()
void LasWriter::readyTable(PointTableRef table)
{
m_forwardMetadata = table.privateMetadata("lasforward");
MetadataNode m = table.metadata();
if(m_writePDALMetadata)
setPDALVLRs(m);
setExtraBytesVlr();
}

Expand All @@ -265,9 +268,6 @@ void LasWriter::prepOutput(std::ostream *outStream, const SpatialReference& srs)
{


MetadataNode m = getMetadata();
if(m_writePDALMetadata)
setPDALVlrFromMetadata(m);

// Use stage SRS if provided.
m_srs = getSpatialReference().empty() ? srs : getSpatialReference();
Expand Down Expand Up @@ -349,18 +349,29 @@ MetadataNode LasWriter::findVlrMetadata(MetadataNode node,
return node.find(pred);
}

void LasWriter::setPDALVlrFromMetadata(MetadataNode& forward)
void LasWriter::setPDALVLRs(MetadataNode& forward)
{
std::ostringstream ostr;
Utils::toJSON(getMetadata(), ostr);

Utils::toJSON(forward, ostr);
std::string json = ostr.str();
std::vector<uint8_t> data;//(LasVLR::MAX_DATA_SIZE, 0);
data.resize(json.size());
std::copy(json.begin(), json.end(), data.begin());

auto store = [this](std::string json, int recordId, std::string description)
{
std::vector<uint8_t> data;
data.resize(json.size());
std::copy(json.begin(), json.end(), data.begin());
addVlr("PDAL", recordId, description, data);


};

store(ostr.str(), 12, "PDAL metadata");
ostr.str("");

PipelineWriter::writePipeline(this, ostr);

store(ostr.str(), 13, "PDAL pipeline");

addVlr("PDAL", 12, "pdal metadata", data);

}
/// Set VLRs from metadata for forwarded info.
Expand Down
2 changes: 1 addition & 1 deletion io/LasWriter.hpp
Expand Up @@ -151,7 +151,7 @@ class PDAL_DLL LasWriter : public FlexWriter
void writeLasZipBuf(char *data, size_t pointLen, point_count_t numPts);
void writeLazPerfBuf(char *data, size_t pointLen, point_count_t numPts);
void setVlrsFromMetadata(MetadataNode& forward);
void setPDALVlrFromMetadata(MetadataNode& m);
void setPDALVLRs(MetadataNode& m);
MetadataNode findVlrMetadata(MetadataNode node, uint16_t recordId,
const std::string& userId);
void setExtraBytesVlr();
Expand Down
40 changes: 40 additions & 0 deletions test/unit/io/LasWriterTest.cpp
Expand Up @@ -716,6 +716,46 @@ TEST(LasWriterTest, fix1063_1064_1065)
EXPECT_EQ(ref.getWKT(), wkt);
}

TEST(LasWriterTest, pdal_metadata)
{
PointTable table;

std::string infile(Support::datapath("las/1.2-with-color.las"));
std::string outfile(Support::temppath("simple.las"));

// remove file from earlier run, if needed
FileUtils::deleteFile(outfile);

Options readerOpts;
readerOpts.add("filename", infile);

Options writerOpts;
writerOpts.add("pdal_metadata", true);
writerOpts.add("filename", outfile);

LasReader reader;
reader.setOptions(readerOpts);

LasWriter writer;
writer.setOptions(writerOpts);
writer.setInput(reader);
writer.prepare(table);
writer.execute(table);

PointTable t2;
Options readerOpts2;
readerOpts2.add("filename", outfile);
LasReader reader2;
reader2.setOptions(readerOpts2);

reader2.prepare(t2);
reader2.execute(t2);

EXPECT_EQ(reader2.getMetadata().children("pdal_metadata").size(), 1UL);
EXPECT_EQ(reader2.getMetadata().children("pdal_pipeline").size(), 1UL);

}

/**
namespace
{
Expand Down

0 comments on commit d97a978

Please sign in to comment.