Ejemplo n.º 1
0
void LasWriter::prepared(PointTableRef table)
{
    FlexWriter::validateFilename(table);

    PointLayoutPtr layout = table.layout();

    // If we've asked for all dimensions, add to extraDims all dimensions
    // in the layout that aren't already destined for LAS output.
    if (m_extraDims.size() == 1 && m_extraDims[0].m_name == "all")
    {
        m_extraDims.clear();
        Dimension::IdList ids = m_lasHeader.usedDims();
        DimTypeList dimTypes = layout->dimTypes();
        for (auto& dt : dimTypes)
        {
            if (!Utils::contains(ids, dt.m_id))
                m_extraDims.push_back(
                    ExtraDim(layout->dimName(dt.m_id), dt.m_type));
        }
    }

    m_extraByteLen = 0;
    for (auto& dim : m_extraDims)
    {
        dim.m_dimType.m_id = table.layout()->findDim(dim.m_name);
        if (dim.m_dimType.m_id == Dimension::Id::Unknown)
        {
            std::ostringstream oss;
            oss << "Dimension '" << dim.m_name << "' specified in "
                "'extra_dim' option not found.";
            throw pdal_error(oss.str());
        }
        m_extraByteLen += Dimension::size(dim.m_dimType.m_type);
    }
}
Ejemplo n.º 2
0
void AttributeFilter::ready(PointTableRef table)
{
    m_gdal_debug = std::shared_ptr<pdal::gdal::Debug>(
        new pdal::gdal::Debug(isDebug(), log()));

    for (auto& dim_par : m_dimensions)
    {
        Dimension::Id::Enum t = table.layout()->findDim(dim_par.first);
        dim_par.second.dim = t;

        if (dim_par.second.isogr)
        {

            OGRDSPtr ds = OGRDSPtr(OGROpen(dim_par.second.datasource.c_str(), 0, 0), OGRDataSourceDeleter());
            if (!ds)
            {
                std::ostringstream oss;
                oss << "Unable to open data source '" << dim_par.second.datasource <<"'";
                throw pdal_error(oss.str());
            }
            dim_par.second.ds = ds;
        }

    }
}
Ejemplo n.º 3
0
void LocateFilter::prepared(PointTableRef table)
{
    PointLayoutPtr layout(table.layout());
    m_dimId = layout->findDim(m_dimName);
    if (m_dimId == Dimension::Id::Unknown)
        throwError("Invalid dimension '" + m_dimName + "'.");
}
Ejemplo n.º 4
0
void ColorizationFilter::ready(PointTableRef table)
{
    m_forward_transform.assign(0.0);
    m_inverse_transform.assign(0.0);

    log()->get(LogLevel::Debug) << "Using " << m_rasterFilename <<
        " for raster" << std::endl;
    m_ds = GDALOpen(m_rasterFilename.c_str(), GA_ReadOnly);
    if (m_ds == NULL)
        throw pdal_error("Unable to open GDAL datasource!");

    if (GDALGetGeoTransform(m_ds, &(m_forward_transform.front())) != CE_None)
        throw pdal_error("unable to fetch forward geotransform for raster!");

    if (!GDALInvGeoTransform(&(m_forward_transform.front()),
        &(m_inverse_transform.front())))
        throw pdal_error("unable to fetch inverse geotransform for raster!");

    for (auto bi = m_bands.begin(); bi != m_bands.end(); ++bi)
    {
        if (bi->m_dim == Dimension::Id::Unknown)
            bi->m_dim = table.layout()->findDim(bi->m_name);
        if (bi->m_dim == Dimension::Id::Unknown)
            throw pdal_error((std::string)"Can't colorize - no dimension " +
                bi->m_name);
    }
}
Ejemplo n.º 5
0
// Build the list of dimensions for the output schema.
// Placing this here allows validation of dimensions before execution begins.
void DbWriter::prepared(PointTableRef table)
{
    using namespace Dimension;

    PointLayoutPtr layout = table.layout();

    if (m_outputDims.empty())
    {
        for (auto& dimType : layout->dimTypes())
            m_dbDims.push_back(XMLDim(dimType, layout->dimName(dimType.m_id)));
        return;
    }

    DimTypeList dims;
    for (std::string& s : m_outputDims)
    {
        DimType dt = layout->findDimType(s);
        if (dt.m_id == Id::Unknown)
        {
            std::ostringstream oss;
            oss << "Invalid dimension '" << s << "' specified for "
                "'output_dims' option.";
            throw pdal_error(oss.str());
        }
        m_dbDims.push_back(XMLDim(dt, layout->dimName(dt.m_id)));
    }
}
Ejemplo n.º 6
0
// Deferring write until this time allows both points and faces from multiple
// point views to be written.
void PlyWriter::done(PointTableRef table)
{
    for (auto& v : m_views)
    {
        PointRef point(*v, 0);
        for (PointId idx = 0; idx < v->size(); ++idx)
        {
            point.setPointId(idx);
            writePoint(point, table.layout());
        }
    }
    if (m_faces)
    {
        PointId offset = 0;
        for (auto& v : m_views)
        {
            TriangularMesh *mesh = v->mesh();
            if (mesh)
            {
                for (size_t id = 0; id < mesh->size(); ++id)
                {
                    const Triangle& t = (*mesh)[id];
                    writeTriangle(t, offset);
                }
            }
            offset += v->size();
        }
    }
    Utils::closeFile(m_stream);
    m_stream = nullptr;
    getMetadata().addList("filename", m_filename);
}
Ejemplo n.º 7
0
void GroupByFilter::prepared(PointTableRef table)
{
    PointLayoutPtr layout(table.layout());
    m_dimId = layout->findDim(m_dimName);
    if (m_dimId == Dimension::Id::Unknown)
        throwError("Invalid dimension name '" + m_dimName + "'.");
    // also need to check that we have a dimension with discrete values
}
Ejemplo n.º 8
0
 void GeoWaveWriter::ready(PointTableRef table)
 {
     // get a list of all the dimensions & their types
     Dimension::IdList all = table.layout()->dims();
     for (auto di = all.begin(); di != all.end(); ++di)
         if (!Utils::contains(m_dims, *di))
             m_dims.push_back(*di);
 }
Ejemplo n.º 9
0
void FerryFilter::ready(PointTableRef table)
{
    const PointLayoutPtr layout(table.layout());
    for (const auto& dim_par : m_name_map)
    {
        Dimension::Id f = layout->findDim(dim_par.first);
        Dimension::Id t = layout->findDim(dim_par.second);
        m_dimensions_map.insert(std::make_pair(f,t));
    }
}
Ejemplo n.º 10
0
void PlyWriter::ready(PointTableRef table)
{
    if (pointCount() > std::numeric_limits<uint32_t>::max())
        throwError("Can't write PLY file.  Only " +
            std::to_string(std::numeric_limits<uint32_t>::max()) +
            " points supported.");

    m_stream = Utils::createFile(m_filename, true);
    writeHeader(table.layout());
}
Ejemplo n.º 11
0
void FerryFilter::prepared(PointTableRef table)
{
    for (auto& info : m_dims)
    {
        info.m_fromId = table.layout()->findDim(info.m_fromName);
        if (info.m_fromId == Dimension::Id::Unknown && info.m_fromName.size())
            throwError("Can't ferry dimension '" + info.m_fromName + "'. "
                "Dimension doesn't exist.");
    }
}
Ejemplo n.º 12
0
void AttributeFilter::prepared(PointTableRef table)
{
    m_dim = table.layout()->findDim(m_dimName);
    if (m_dim == Dimension::Id::Unknown)
    {
        std::ostringstream oss;
        oss << getName() << ": Dimension '" << m_dimName << "' not found.";
        throw pdal_error(oss.str());
    }
}
Ejemplo n.º 13
0
Archivo: Stage.cpp Proyecto: jwend/PDAL
PointViewSet Stage::execute(PointTableRef table)
{



    //printf("called %s\n", this->classname());
    log()->setLevel(LogLevel::Enum::Debug);

    std::string cn(this->classname());
    log()->setLeader(cn + " Stage::execute");
    log()->get(LogLevel::Debug) << "Called by class " << std::endl;

    table.layout()->finalize();

    PointViewSet views;
    if (m_inputs.empty())
    {
        log()->get(LogLevel::Debug) << "if block, class" << std::endl;
        views.insert(PointViewPtr(new PointView(table)));
    }
    else
    {
        for (size_t i = 0; i < m_inputs.size(); ++i)
        {
            log()->get(LogLevel::Debug) << "block, class"
                    << "input number "<< i << std::endl;
            log()->get(LogLevel::Debug) << "if block, class" << std::endl;
            Stage *prev = m_inputs[i];
            PointViewSet temp = prev->execute(table);
            views.insert(temp.begin(), temp.end());
        }
    }

    PointViewSet outViews;
    std::vector<StageRunnerPtr> runners;

    ready(table);
    for (auto const& it : views)
    {
        log()->get(LogLevel::Debug) << "run, class" << std::endl;
        StageRunnerPtr runner(new StageRunner(this, it));
        runners.push_back(runner);
        runner->run();
    }
    for (auto const& it : runners)
    {
        log()->get(LogLevel::Debug) << "wait, class" << std::endl;
        StageRunnerPtr runner(it);
        PointViewSet temp = runner->wait();
        outViews.insert(temp.begin(), temp.end());
    }
    l_done(table);
    done(table);
    return outViews;
}
Ejemplo n.º 14
0
void FerryFilter::prepared(PointTableRef table)
{
    for (const auto& dims : m_name_map)
        if (table.layout()->findDim(dims.first) == Dimension::Id::Unknown)
        {
            std::ostringstream oss;
            oss << "Can't ferry dimension '" << dims.first << "'. "
                "Dimension doesn't exist.";
            throw pdal_error(oss.str());
        }
}
Ejemplo n.º 15
0
void PlyWriter::prepared(PointTableRef table)
{
    if (m_dimNames.size())
    {
        for (auto& name : m_dimNames)
        {
            auto id = table.layout()->findDim(name);
            if (id == Dimension::Id::Unknown)
                throwError("Unknown dimension '" + name + "' in provided "
                    "dimension list.");
            m_dims.push_back(id);
        }
    }
    else
    {
        m_dims = table.layout()->dims();
        for (auto dim : m_dims)
            m_dimNames.push_back(Utils::tolower(table.layout()->dimName(dim)));
    }
}
Ejemplo n.º 16
0
void MADFilter::prepared(PointTableRef table)
{
    PointLayoutPtr layout(table.layout());
    m_dimId = layout->findDim(m_dimName);
    if (m_dimId == Dimension::Id::Unknown)
    {
        std::ostringstream oss;
        oss << "Invalid dimension name in filters.mad 'dimension' "
            "option: '" << m_dimName << "'.";
        throw pdal_error(oss.str());
    }
}
Ejemplo n.º 17
0
void PlyWriter::done(PointTableRef table)
{
    if (!ply_add_element(m_ply, "vertex", m_pointCollector->size()))
    {
        std::stringstream ss;
        ss << "Could not add vertex element";
        throw pdal_error(ss.str());
    }
    auto dimensions = table.layout()->dims();
    for (auto dim : dimensions) {
        std::string name = Dimension::name(dim);
        e_ply_type plyType = getPlyType(Dimension::defaultType(dim));
        if (!ply_add_scalar_property(m_ply, name.c_str(), plyType))
        {
            std::stringstream ss;
            ss << "Could not add scalar property '" << name << "'";
            throw pdal_error(ss.str());
        }
    }
    if (!ply_add_comment(m_ply, "Generated by PDAL"))
    {
        std::stringstream ss;
        ss << "Could not add comment";
        throw pdal_error(ss.str());
    }
    if (!ply_write_header(m_ply))
    {
        std::stringstream ss;
        ss << "Could not write ply header";
        throw pdal_error(ss.str());
    }

    for (PointId index = 0; index < m_pointCollector->size(); ++index)
    {
        for (auto dim : dimensions)
        {
            double value = m_pointCollector->getFieldAs<double>(dim, index);
            if (!ply_write(m_ply, value))
            {
                std::stringstream ss;
                ss << "Error writing dimension '" << Dimension::name(dim) <<
                    "' of point number " << index;
                throw pdal_error(ss.str());
            }
        }
    }

    if (!ply_close(m_ply))
    {
        throw pdal_error("Error closing ply file");
    }
}
Ejemplo n.º 18
0
void E57Writer::ready(PointTableRef table)
{
    // Extracts dimensions that can be written
    auto dimensions = table.layout()->dims();
    m_dimensionsToWrite = {};
    for (auto pdaldim: dimensions)
    {
        std::string e57Dimension(pdal::e57plugin::pdalToE57(pdaldim));
        if (!e57Dimension.empty())
            m_dimensionsToWrite.push_back(e57Dimension);
    }
    setupWriter();
}
Ejemplo n.º 19
0
void RangeFilter::prepared(PointTableRef table)
{
    const PointLayoutPtr layout(table.layout());

    for (auto& r : m_range_list)
    {
        r.m_id = layout->findDim(r.m_name);
        if (r.m_id == Dimension::Id::Unknown)
            throwError("Invalid dimension name in 'limits' option: '" +
                r.m_name + "'.");
    }
    std::sort(m_range_list.begin(), m_range_list.end());
}
Ejemplo n.º 20
0
void LasWriter::prepared(PointTableRef table)
{
    FlexWriter::validateFilename(table);

    PointLayoutPtr layout = table.layout();

    // Make sure the dataformatID is set so that we can get the proper
    // dimensions being written as part of the standard LAS record.
    fillHeader();

    // If we've asked for all dimensions, add to extraDims all dimensions
    // in the layout that aren't already destined for LAS output.
    if (m_extraDims.size() == 1 && m_extraDims[0].m_name == "all")
    {
        m_extraDims.clear();
        Dimension::IdList ids = m_lasHeader.usedDims();
        DimTypeList dimTypes = layout->dimTypes();
        for (auto& dt : dimTypes)
        {
            if (!Utils::contains(ids, dt.m_id))
                m_extraDims.push_back(
                    ExtraDim(layout->dimName(dt.m_id), dt.m_type));
        }
    }

    m_extraByteLen = 0;
    for (auto& dim : m_extraDims)
    {
        dim.m_dimType.m_id = table.layout()->findDim(dim.m_name);
        if (dim.m_dimType.m_id == Dimension::Id::Unknown)
            throwError("Dimension '" + dim.m_name + "' specified in "
                "'extra_dim' option not found.");
        m_extraByteLen += Dimension::size(dim.m_dimType.m_type);
        log()->get(LogLevel::Info) << getName() << ": Writing dimension " <<
            dim.m_name <<
            "(" << Dimension::interpretationName(dim.m_dimType.m_type) <<
            ") " << " to LAS extra bytes." << std::endl;
    }
}
Ejemplo n.º 21
0
void Stage::prepare(PointTableRef table)
{
    for (size_t i = 0; i < m_inputs.size(); ++i)
    {
        Stage *prev = m_inputs[i];
        prev->prepare(table);
    }
    l_processOptions(m_options);
    processOptions(m_options);
    l_initialize(table);
    initialize(table);
    addDimensions(table.layout());
    prepared(table);
}
Ejemplo n.º 22
0
void PlyWriter::prepared(PointTableRef table)
{
    if (m_precisionArg->set() && m_format != Format::Ascii)
        throwError("Option 'precision' can only be set of the 'storage_mode' "
            "is ascii.");
    if (m_dimNames.size())
    {
        for (auto& name : m_dimNames)
        {
            auto id = table.layout()->findDim(name);
            if (id == Dimension::Id::Unknown)
                throwError("Unknown dimension '" + name + "' in provided "
                    "dimension list.");
            m_dims.push_back(id);
        }
    }
    else
    {
        m_dims = table.layout()->dims();
        for (auto dim : m_dims)
            m_dimNames.push_back(Utils::tolower(table.layout()->dimName(dim)));
    }
}
Ejemplo n.º 23
0
void TextWriter::ready(PointTableRef table)
{
    m_stream->precision(m_precision);
    *m_stream << std::fixed;

    typedef boost::tokenizer<boost::char_separator<char>> tokenizer;

    // Find the dimensions listed and put them on the id list.
    boost::char_separator<char> separator(",");
    boost::erase_all(m_dimOrder, " "); // Wipe off spaces
    tokenizer sdims(m_dimOrder, separator);
    for (tokenizer::iterator ti = sdims.begin(); ti != sdims.end(); ++ti)
    {
        Dimension::Id::Enum d = table.layout()->findDim(*ti);
        if (d == Dimension::Id::Unknown)
        {
            std::ostringstream oss;
            oss << "Dimension not found with name '" << *ti <<"'";
            throw pdal::dimension_not_found(oss.str());
        }
        m_dims.push_back(d);
    }
    // Add the rest of the dimensions to the list if we're doing that.
    // Yes, this isn't efficient when, but it's simple.
    if (m_dimOrder.empty() || m_writeAllDims)
    {
        Dimension::IdList all = table.layout()->dims();
        for (auto di = all.begin(); di != all.end(); ++di)
            if (!contains(m_dims, *di))
                m_dims.push_back(*di);
    }

    if (!m_writeHeader)
        log()->get(LogLevel::Debug) << "Not writing header" << std::endl;
    else
        writeHeader(table);
}
Ejemplo n.º 24
0
void StatsFilter::prepared(PointTableRef table)
{
    PointLayoutPtr layout(table.layout());
    std::unordered_map<std::string, Summary::EnumType> dims;
    std::ostream& out = log()->get(LogLevel::Warning);

    // Add dimensions to the list.
    if (m_dimNames.empty())
    {
        for (auto id : layout->dims())
            dims[layout->dimName(id)] = Summary::NoEnum;
    }
    else
    {
        for (auto& s : m_dimNames)
        {
            if (layout->findDim(s) == Dimension::Id::Unknown)
                out << "Dimension '" << s << "' listed in --dimensions "
                    "option does not exist.  Ignoring." << std::endl;
            else
                dims[s] = Summary::NoEnum;
        }
    }

    // Set the enumeration flag for those dimensions specified.
    for (auto& s : m_enums)
    {
        if (dims.find(s) == dims.end())
            out << "Dimension '" << s << "' listed in --enumerate option "
                "does not exist.  Ignoring." << std::endl;
        else
            dims[s] = Summary::Enumerate;
    }

    // Set the enumeration flag for those dimensions specified.
    for (auto& s : m_counts)
    {
        if (dims.find(s) == dims.end())
            out << "Dimension '" << s << "' listed in --count option "
                "does not exist.  Ignoring." << std::endl;
        else
            dims[s] = Summary::Count;
    }

    // Create the summary objects.
    for (auto& dv : dims)
        m_stats.insert(std::make_pair(layout->findDim(dv.first),
            Summary(dv.first, dv.second)));
}
Ejemplo n.º 25
0
void PlyWriter::ready(PointTableRef table)
{
    if (pointCount() > (std::numeric_limits<uint32_t>::max)())
        throwError("Can't write PLY file.  Only " +
            std::to_string((std::numeric_limits<uint32_t>::max)()) +
            " points supported.");

    m_stream = Utils::createFile(m_filename, true);
    if (m_format == Format::Ascii && m_precisionArg->set())
    {
        *m_stream << std::fixed;
        m_stream->precision(m_precision);
    }
    writeHeader(table.layout());
}
Ejemplo n.º 26
0
void Ilvis2Reader::ready(PointTableRef table)
{
    static const int HeaderSize = 2;
    std::string line;

    m_lineNum = 0;
    m_stream.open(m_filename);
    m_layout = table.layout();
    m_resample = false;
    for (size_t i = 0; i < HeaderSize; ++i)
    {
        std::getline(m_stream, line);
        m_lineNum++;
    }
}
Ejemplo n.º 27
0
void TextWriter::ready(PointTableRef table)
{
    m_stream->precision(m_precision);
    *m_stream << std::fixed;

    // Find the dimensions listed and put them on the id list.
    StringList dimNames = Utils::split2(m_dimOrder, ',');
    for (std::string dim : dimNames)
    {
        Utils::trim(dim);
        Dimension::Id d = table.layout()->findDim(dim);
        if (d == Dimension::Id::Unknown)
        {
            std::ostringstream oss;
            oss << getName() << ": Dimension not found with name '" <<
                dim << "'.";
            throw pdal_error(oss.str());
        }
        m_dims.push_back(d);
    }

    // Add the rest of the dimensions to the list if we're doing that.
    // Yes, this isn't efficient when, but it's simple.
    if (m_dimOrder.empty() || m_writeAllDims)
    {
        Dimension::IdList all = table.layout()->dims();
        for (auto di = all.begin(); di != all.end(); ++di)
            if (!Utils::contains(m_dims, *di))
                m_dims.push_back(*di);
    }

    if (!m_writeHeader)
        log()->get(LogLevel::Debug) << "Not writing header" << std::endl;
    else
        writeHeader(table);
}
Ejemplo n.º 28
0
void TextWriter::writeCSVHeader(PointTableRef table)
{
    const PointLayoutPtr layout(table.layout());
    for (auto di = m_dims.begin(); di != m_dims.end(); ++di)
    {
        if (di != m_dims.begin())
            *m_stream << m_delimiter;

        if (m_quoteHeader)
            *m_stream << "\"" << layout->dimName(*di) << "\"";
        else
            *m_stream << layout->dimName(*di);
    }
    *m_stream << m_newline;
}
Ejemplo n.º 29
0
void Stage::prepare(PointTableRef table)
{
    m_args.reset(new ProgramArgs);
    for (size_t i = 0; i < m_inputs.size(); ++i)
    {
        Stage *prev = m_inputs[i];
        prev->prepare(table);
    }
    handleOptions();
    pushLogLeader();
    l_initialize(table);
    initialize(table);
    addDimensions(table.layout());
    prepared(table);
    popLogLeader();
}
Ejemplo n.º 30
0
void LasWriter::prepared(PointTableRef table)
{
    m_extraByteLen = 0;
    for (auto& dim : m_extraDims)
    {
        dim.m_dimType.m_id = table.layout()->findDim(dim.m_name);
        if (dim.m_dimType.m_id == Dimension::Id::Unknown)
        {
            std::ostringstream oss;
            oss << "Dimension '" << dim.m_name << "' specified in "
                "'extra_dim' option not found.";
            throw pdal_error(oss.str());
        }
        m_extraByteLen += Dimension::size(dim.m_dimType.m_type);
    }
}