Beispiel #1
0
// Test auto scale/offset for streaming mode.
TEST(LasWriterTest, issue1940)
{
    StageFactory f;

    Stage& r = *(f.createStage("readers.faux"));
    Options ro;
    ro.add("mode", "constant");
    ro.add("bounds", "([55,55],[55,55],[55,55])");
    ro.add("count", 20);
    r.addOptions(ro);

    LasWriter w;
    Options wo;
    //LogPtr log(new Log("TEST", &std::clog));
    //log->setLevel((LogLevel)5);
    //w.setLog(log);
    wo.add("filename", Support::temppath("out.las"));
    wo.add("scale_x", "auto");
    wo.add("offset_y", "auto");
    w.addOptions(wo);
    w.setInput(r);

    FixedPointTable t(100);
    w.prepare(t);
    w.execute(t);

    LasTester tester;
    LasHeader *h = tester.header(w);
    EXPECT_DOUBLE_EQ(h->offsetX(), 0);
    EXPECT_DOUBLE_EQ(h->offsetY(), 55);
    EXPECT_DOUBLE_EQ(h->scaleX(), 1.0);
    EXPECT_DOUBLE_EQ(h->scaleY(), .01);
}
Beispiel #2
0
Options LasWriter::getDefaultOptions()
{
    Options options;

    options.add("filename", "", "Name of the file for LAS/LAZ output.");
    options.add("compression", false, "Do we LASzip-compress the data?");
    options.add("format", 3, "Point format to write");
    options.add("major_version", 1, "LAS Major version");
    options.add("minor_version", 2, "LAS Minor version");
    options.add("creation_doy", 0, "Day of Year for file");
    options.add("creation_year", 2011, "4-digit year value for file");

    LasHeader header;
    options.add("system_id", header.getSystemIdentifier(),
        "System ID for this file");
    options.add("software_id", GetDefaultSoftwareId(),
        "Software ID for this file");
    options.add("filesource_id", 0, "File Source ID for this file");
    options.add("forward_metadata", false, "forward metadata into "
        "the file as necessary");
    options.add("extra_dims", "", "Extra dimensions not part of the LAS "
        "point format to be added to each point.");

    return options;
}
Beispiel #3
0
bool NitfWrap::verifyLas(ILeStream& in, BOX3D& bounds, bool& compressed)
{
    LasHeader h;

    try
    {
        in >> h;
    }
    catch (pdal_error&)
    {
        return false;
    }
    compressed = h.compressed();
    bounds = h.getBounds();
    gdal::reprojectBounds(bounds, h.srs().getWKT(), "EPSG:4326");
    return true;
}
Beispiel #4
0
TEST(LasWriterTest, metadata_options)
{
    Options ops;

    Option metadataOp("metadata", "");

    Options metadataOps;
    metadataOps.add("format", 4);
    metadataOps.add("software_id", "MySoftwareId");
    metadataOps.add("system_id", "FORWARD");
    metadataOps.add("minor_version", "forward");
    metadataOp.setOptions(metadataOps);
    ops.add(metadataOp);
    ops.add("filename", Support::temppath("wontgetwritten"));

    LasWriter writer;
    writer.setOptions(ops);

    PointTable table;
    writer.prepare(table);

    MetadataNode m = writer.getMetadata();
    m.add("minor_version", 56);

    uint8_t format =
        (uint8_t)LasTester::headerVal<unsigned>(writer, "format");
    EXPECT_EQ(format, 4u);
    std::string softwareId =
        LasTester::headerVal<std::string>(writer, "software_id");
    EXPECT_EQ(softwareId, "MySoftwareId");
    std::string systemId =
        LasTester::headerVal<std::string>(writer, "system_id");

    // Since the option specifies forward and there is not associated
    // metadata, the value should be the default.
    LasHeader header;
    EXPECT_EQ(systemId, header.getSystemIdentifier());

    // In this case, we should have metadata to override the default.
    uint8_t minorVersion =
        (uint8_t)LasTester::headerVal<unsigned>(writer, "minor_version");
    EXPECT_EQ(minorVersion, 56u);
}
Beispiel #5
0
// Get header info from options and store in map for processing with
// metadata.
void LasWriter::getHeaderOptions(const Options &options)
{
    typedef boost::optional<std::string> OpString;
    auto metaOptionValue = [this, options](const std::string& name,
        const::std::string& defVal)
    {
        std::string value;
        OpString opValue = options.getMetadataOption<std::string>(name);
        if (opValue)
        {
            value = *opValue;
            // The reassignment makes sure the case is correct.
            if (boost::iequals(value, "FORWARD"))
            {
                value = "FORWARD";
                value += defVal;
            }
        }
        else
            value = options.getValueOrDefault(name, defVal);
        m_headerVals[name] = value;
    };

    std::time_t now;
    std::time(&now);
    std::tm* ptm = std::gmtime(&now);
    uint16_t year = ptm->tm_year + 1900;
    uint16_t doy = ptm->tm_yday;

    metaOptionValue("format", "3");
    metaOptionValue("minor_version", "2");
    metaOptionValue("creation_year", std::to_string(year));
    metaOptionValue("creation_doy", std::to_string(doy));
    metaOptionValue("software_id", GetDefaultSoftwareId());
    LasHeader header;
    metaOptionValue("system_id", header.getSystemIdentifier());
    metaOptionValue("project_id",
        boost::lexical_cast<std::string>(boost::uuids::uuid()));
    metaOptionValue("global_encoding", "0");
    metaOptionValue("filesource_id", "0");
}
Beispiel #6
0
TEST(LasWriterTest, extra_dims)
{
    Options readerOps;

    readerOps.add("filename", Support::datapath("las/1.2-with-color.las"));
    LasReader reader;
    reader.setOptions(readerOps);

    Options writerOps;
    writerOps.add("extra_dims", "Red=int32, Blue = int16, Green = int32_t");
    writerOps.add("filename", Support::temppath("simple.las"));
    LasWriter writer;
    writer.setInput(reader);
    writer.setOptions(writerOps);

    PointTable table;
    writer.prepare(table);
    PointViewSet viewSet = writer.execute(table);

    LasTester tester;
    LasHeader *header = tester.header(writer);
    EXPECT_EQ(header->pointLen(), header->basePointLen() + 10);
    PointViewPtr pb = *viewSet.begin();

    uint16_t colors[][3] = {
        { 68, 77, 88 },
        { 92, 100, 110 },
        { 79, 87, 87 },
        { 100, 102, 116 },
        { 162, 114, 145 },
        { 163, 137, 155 },
        { 154, 131, 144 },
        { 104, 111, 126 },
        { 164, 136, 156 },
        { 72, 87, 82 },
        { 117, 117, 136 }
    };

    Options reader2Ops;
    reader2Ops.add("filename", Support::temppath("simple.las"));
    reader2Ops.add("extra_dims", "R1 =int32, B1= int16 ,G1=int32_t");

    LasReader reader2;
    reader2.setOptions(reader2Ops);

    PointTable readTable;
    reader2.prepare(readTable);
    viewSet = reader2.execute(readTable);
    pb = *viewSet.begin();
    Dimension::Id r1 = readTable.layout()->findDim("R1");
    EXPECT_TRUE(r1 != Dimension::Id::Unknown);
    Dimension::Id b1 = readTable.layout()->findDim("B1");
    EXPECT_TRUE(b1 != Dimension::Id::Unknown);
    Dimension::Id g1 = readTable.layout()->findDim("G1");
    EXPECT_TRUE(g1 != Dimension::Id::Unknown);
    EXPECT_EQ(pb->size(), (size_t)1065);
    size_t j = 0;
    for (PointId i = 0; i < pb->size(); i += 100)
    {
        EXPECT_EQ(pb->getFieldAs<int16_t>(r1, i), colors[j][0]);
        EXPECT_EQ(pb->getFieldAs<int16_t>(g1, i), colors[j][1]);
        EXPECT_EQ(pb->getFieldAs<int16_t>(b1, i), colors[j][2]);
        j++;
    }
}
Beispiel #7
0
TEST(LasReaderTest, header)
{
    PointTable table;
    Options ops;
    ops.add("filename", Support::datapath("las/simple.las"));

    LasReader reader;
    reader.setOptions(ops);

    reader.prepare(table);
    // This tests the copy ctor, too.
    LasHeader h = reader.header();

    EXPECT_EQ(h.fileSignature(), "LASF");
    EXPECT_EQ(h.fileSourceId(), 0);
    EXPECT_TRUE(h.projectId().isNull());
    EXPECT_EQ(h.versionMajor(), 1);
    EXPECT_EQ(h.versionMinor(), 2);
    EXPECT_EQ(h.creationDOY(), 0);
    EXPECT_EQ(h.creationYear(), 0);
    EXPECT_EQ(h.vlrOffset(), 227);
    EXPECT_EQ(h.pointFormat(), 3);
    EXPECT_EQ(h.pointCount(), 1065u);
    EXPECT_DOUBLE_EQ(h.scaleX(), .01);
    EXPECT_DOUBLE_EQ(h.scaleY(), .01);
    EXPECT_DOUBLE_EQ(h.scaleZ(), .01);
    EXPECT_DOUBLE_EQ(h.offsetX(), 0);
    EXPECT_DOUBLE_EQ(h.offsetY(), 0);
    EXPECT_DOUBLE_EQ(h.offsetZ(), 0);
    EXPECT_DOUBLE_EQ(h.maxX(), 638982.55);
    EXPECT_DOUBLE_EQ(h.maxY(), 853535.43);
    EXPECT_DOUBLE_EQ(h.maxZ(), 586.38);
    EXPECT_DOUBLE_EQ(h.minX(), 635619.85);
    EXPECT_DOUBLE_EQ(h.minY(), 848899.70);
    EXPECT_DOUBLE_EQ(h.minZ(), 406.59);
    EXPECT_EQ(h.compressed(), false);
    EXPECT_EQ(h.compressionInfo(), "");
    EXPECT_EQ(h.pointCountByReturn(0), 925u);
    EXPECT_EQ(h.pointCountByReturn(1), 114u);
    EXPECT_EQ(h.pointCountByReturn(2), 21u);
    EXPECT_EQ(h.pointCountByReturn(3), 5u);
    EXPECT_EQ(h.pointCountByReturn(4), 0u);
}