// Make sure that we can forward the LAS_Spec/3 VLR TEST(LasWriterTest, forward_spec_3) { PointTable table; std::string infile(Support::datapath("las/spec_3.las")); std::string outfile(Support::temppath("out.las")); // remove file from earlier run, if needed FileUtils::deleteFile(outfile); Options readerOpts; readerOpts.add("filename", infile); Options writerOpts; writerOpts.add("forward", "all,vlr"); 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); auto pred = [](MetadataNode temp) { auto recPred = [](MetadataNode n) { return n.name() == "record_id" && n.value() == "3"; }; auto userPred = [](MetadataNode n) { return n.name() == "user_id" && n.value() == "LASF_Spec"; }; return Utils::startsWith(temp.name(), "vlr_") && !temp.findChild(recPred).empty() && !temp.findChild(userPred).empty(); }; MetadataNode root = reader2.getMetadata(); MetadataNodeList nodes = root.findChildren(pred); EXPECT_EQ(nodes.size(), 1u); }
TEST(LasWriterTest, pdal_add_vlr) { 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); std::string vlr( " [ { \"description\": \"A description under 32 bytes\", \"record_id\": 42, \"user_id\": \"hobu\", \"data\": \"dGhpcyBpcyBzb21lIHRleHQ=\" }, { \"description\": \"A description under 32 bytes\", \"record_id\": 43, \"user_id\": \"hobu\", \"data\": \"dGhpcyBpcyBzb21lIG1vcmUgdGV4dA==\" } ]"); Options writerOpts; writerOpts.add("vlrs", vlr); 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); MetadataNode forward = reader2.getMetadata(); auto pred = [](MetadataNode temp) { return Utils::startsWith(temp.name(), "vlr_"); }; MetadataNodeList nodes = forward.findChildren(pred); EXPECT_EQ(nodes.size(), 2UL); }
TEST(LasWriterTest, forwardvlr) { Options readerOps1; readerOps1.add("filename", Support::datapath("las/lots_of_vlr.las")); LasReader r1; r1.addOptions(readerOps1); std::string testfile = Support::temppath("tmp.las"); FileUtils::deleteFile(testfile); Options writerOps; writerOps.add("forward", "vlr"); writerOps.add("filename", testfile); LasWriter w; w.setInput(r1); w.addOptions(writerOps); PointTable t; w.prepare(t); w.execute(t); Options readerOps; readerOps.add("filename", testfile); LasReader r; r.setOptions(readerOps); PointTable t2; r.prepare(t2); r.execute(t2); MetadataNode forward = t2.privateMetadata("lasforward"); auto pred = [](MetadataNode temp) { return Utils::startsWith(temp.name(), "vlr_"); }; MetadataNodeList nodes = forward.findChildren(pred); EXPECT_EQ(nodes.size(), 388UL); }
/// Set VLRs from metadata for forwarded info. void LasWriter::setVlrsFromMetadata(MetadataNode& forward) { std::vector<uint8_t> data; if (!m_forwardVlrs) return; auto pred = [](MetadataNode n) { return Utils::startsWith(n.name(), "vlr_"); }; MetadataNodeList nodes = forward.findChildren(pred); for (auto& n : nodes) { const MetadataNode& userIdNode = n.findChild("user_id"); const MetadataNode& recordIdNode = n.findChild("record_id"); if (recordIdNode.valid() && userIdNode.valid()) { data = Utils::base64_decode(n.value()); uint16_t recordId = (uint16_t)std::stoi(recordIdNode.value()); addVlr(userIdNode.value(), recordId, n.description(), data); } } }