TEST(LasReaderTest, IgnoreVLRs) { PointTable table; Options readOps; readOps.add("filename", Support::datapath("las/lots_of_vlr.las")); readOps.add("ignore_vlr", "Merrick"); LasReader reader; reader.setOptions(readOps); reader.prepare(table); PointViewSet viewSet = reader.execute(table); // First two VLRs are SRS info, the other 388 would be // Merrick ones that we want to ignore/remove MetadataNode root = reader.getMetadata(); for (size_t i = 2; i < 390; ++i) { std::string name("vlr_"); name += std::to_string(i); MetadataNode m = root.findChild(name); EXPECT_FALSE(!m.empty()) << "No node " << i; m = m.findChild("data"); EXPECT_FALSE(!m.empty()) << "No value for node " << i; } }
MetadataNode findChild(std::string s) const { auto splitString = [](std::string& s) -> std::string { std::string val; size_t pos = s.find(':'); if (pos == std::string::npos) { val = s; s.clear(); } else { val = s.substr(0, pos); s = (pos == s.size() - 1) ? "" : s.substr(pos + 1); } return val; }; if (s.empty()) return *this; std::string lname = splitString(s); auto nodes = children(lname); for (auto ai = nodes.begin(); ai != nodes.end(); ++ai) { MetadataNode& n = *ai; MetadataNode child = n.findChild(s); if (!child.empty()) return child; } return MetadataNode(); }
TEST(LasReaderTest, test_vlr) { PointTable table; Options ops1; ops1.add("filename", Support::datapath("las/lots_of_vlr.las")); LasReader reader; reader.setOptions(ops1); reader.prepare(table); reader.execute(table); MetadataNode root = reader.getMetadata(); for (size_t i = 0; i < 390; ++i) { std::string name("vlr_"); name += std::to_string(i); MetadataNode m = root.findChild(name); EXPECT_TRUE(!m.empty()) << "No node " << i; m = m.findChild("data"); EXPECT_TRUE(!m.empty()) << "No value for node " << i; } }
MetadataNode find(PREDICATE p) const { if (p(*this)) return *this; auto nodes = children(); for (auto ai = nodes.begin(); ai != nodes.end(); ++ai) { MetadataNode n = ai->find(p); if (!n.empty()) return n; } return MetadataNode(); }
void Stage::setSpatialReference(MetadataNode& m, const SpatialReference& spatialRef) { m_spatialReference = spatialRef; auto pred = [](MetadataNode m){ return m.name() == "spatialreference"; }; MetadataNode spatialNode = m.findChild(pred); if (spatialNode.empty()) { m.add(spatialRef.toMetadata()); m.add("spatialreference", spatialRef.getWKT(), "SRS of this stage"); m.add("comp_spatialreference", spatialRef.getWKT(), "SRS of this stage"); } }
void Stage::setSpatialReference(MetadataNode& m, const SpatialReference& spatialRef) { m_spatialReference = spatialRef; auto pred = [](MetadataNode m){ return m.name() == "spatialreference"; }; MetadataNode spatialNode = m.findChild(pred); if (spatialNode.empty()) { m.add(Utils::toMetadata(spatialRef)); m.add("spatialreference", spatialRef.getWKT(SpatialReference::eHorizontalOnly, false), "SRS of this stage"); m.add("comp_spatialreference", spatialRef.getWKT(SpatialReference::eCompoundOK, false), "SRS of this stage"); } }
/// Set VLRs from metadata for forwarded info, or from option-provided data /// otherwise. void LasWriter::setVlrsFromMetadata() { std::vector<uint8_t> data; for (auto oi = m_optionInfos.begin(); oi != m_optionInfos.end(); ++oi) { VlrOptionInfo& vlrInfo = *oi; if (vlrInfo.m_name == "FORWARD") { MetadataNode m = findVlrMetadata(m_metadata, vlrInfo.m_recordId, vlrInfo.m_userId); if (m.empty()) continue; data = Utils::base64_decode(m.value()); } else data = Utils::base64_decode(vlrInfo.m_value); addVlr(vlrInfo.m_userId, vlrInfo.m_recordId, vlrInfo.m_description, data); } }