Пример #1
0
void Kernel::setCommonOptions(Options &options)
{
    options.add("debug", m_isDebug);
    options.add("verbose", m_verboseLevel);
    options.add("visualize", m_visualize);

    boost::char_separator<char> sep(",| ");

    if (m_variablesMap.count("scale"))
    {
        std::vector<double> scales;
        tokenizer scale_tokens(m_scales, sep);
        for (auto t = scale_tokens.begin(); t != scale_tokens.end(); ++t)
            scales.push_back(boost::lexical_cast<double>(*t));
        if (scales.size())
        {
            if (scales.size() <= 1)
            {
                options.add<double >("scale_x", scales[0]);
            }
            else if (scales.size() <= 2)
            {
                options.add<double >("scale_x", scales[0]);
                options.add<double >("scale_y", scales[1]);
            }
            else if (scales.size() <= 3)
            {
                options.add<double >("scale_x", scales[0]);
                options.add<double >("scale_y", scales[1]);
                options.add<double >("scale_z", scales[2]);
            }
        }
    }

    if (m_variablesMap.count("offset"))
    {
        std::vector<double> offsets;
        tokenizer offset_tokens(m_offsets, sep);
        for (auto t = offset_tokens.begin(); t != offset_tokens.end(); ++t)
            offsets.push_back(boost::lexical_cast<double>(*t));
        if (offsets.size())
        {
            if (offsets.size() <= 1)
            {
                options.add<double >("offset_x", offsets[0]);
            }
            else if (offsets.size() <= 2)
            {
                options.add<double >("offset_x", offsets[0]);
                options.add<double >("offset_y", offsets[1]);
            }
            else if (offsets.size() <= 3)
            {
                options.add<double >("offset_x", offsets[0]);
                options.add<double >("offset_y", offsets[1]);
                options.add<double >("offset_z", offsets[2]);
            }
        }
    }
}
Пример #2
0
Stage* Translate::makeReader(Options readerOptions)
{

    if (isDebug())
    {
        readerOptions.add<bool>("debug", true);
        boost::uint32_t verbosity(getVerboseLevel());
        if (!verbosity)
            verbosity = 1;
        
        readerOptions.add<boost::uint32_t>("verbose", verbosity);
        readerOptions.add<std::string>("log", "STDERR");
    }


    Stage* reader_stage = AppSupport::makeReader(readerOptions);
    
    Stage* final_stage(0);
    if (!m_bounds.empty() || !m_wkt.empty() || !m_output_srs.empty())
    {
        Stage* next_stage = reader_stage;
        
        Stage* crop_stage(0);
        Stage* reprojection_stage(0);

        if (!m_output_srs.empty())
        {
            readerOptions.add<std::string >("out_srs", m_output_srs.getWKT());

            boost::char_separator<char> sep(SEPARATORS);
            std::vector<double> offsets;
            tokenizer off_tokens(m_offsets, sep);
            for (tokenizer::iterator t = off_tokens.begin(); t != off_tokens.end(); ++t) {
                offsets.push_back(boost::lexical_cast<double>(*t));
            }

            std::vector<double> scales;
            tokenizer scale_tokens(m_scales, sep);
            for (tokenizer::iterator t = scale_tokens.begin(); t != scale_tokens.end(); ++t) {
                scales.push_back(boost::lexical_cast<double>(*t));
            }
            
            if (scales.size())
            {
                if (scales.size() <= 1)
                {
                    readerOptions.add<double >("scale_x", scales[0]);
                    
                }
                else if (scales.size() <= 2)
                {
                    readerOptions.add<double >("scale_x", scales[0]);
                    readerOptions.add<double >("scale_y", scales[1]);
                }
                else if (scales.size() <= 3)
                {
                    readerOptions.add<double >("scale_x", scales[0]);
                    readerOptions.add<double >("scale_y", scales[1]);
                    readerOptions.add<double >("scale_z", scales[2]);
                }
            }

            if (offsets.size())
            {
                if (offsets.size() <= 1)
                {
                    readerOptions.add<double >("offset_x", offsets[0]);
                    
                }
                else if (offsets.size() <= 2)
                {
                    readerOptions.add<double >("offset_x", offsets[0]);
                    readerOptions.add<double >("offset_y", offsets[1]);
                }
                else if (offsets.size() <= 3)
                {
                    readerOptions.add<double >("offset_x", offsets[0]);
                    readerOptions.add<double >("offset_y", offsets[1]);
                    readerOptions.add<double >("offset_z", offsets[2]);
                }
            }
            reprojection_stage = new pdal::filters::InPlaceReprojection(*next_stage, readerOptions);
            next_stage = reprojection_stage;
        }
        
        if (!m_bounds.empty() && m_wkt.empty())
        {
            readerOptions.add<pdal::Bounds<double> >("bounds", m_bounds);
            crop_stage = new pdal::filters::Crop(*next_stage, readerOptions);
            next_stage = crop_stage;
        } 
        else if (m_bounds.empty() && !m_wkt.empty())
        {
            std::istream* wkt_stream;
            try
            {
                wkt_stream = FileUtils::openFile(m_wkt);
                std::stringstream buffer;
                buffer << wkt_stream->rdbuf();

                m_wkt = buffer.str();
                FileUtils::closeFile(wkt_stream);
                
            } catch (pdal::pdal_error const&)
            {
                // If we couldn't open the file given in m_wkt because it 
                // was likely actually wkt, leave it alone
            }
            readerOptions.add<std::string >("polygon", m_wkt);
            crop_stage = new pdal::filters::Crop(*next_stage, readerOptions);
            next_stage = crop_stage;
        }
        
        final_stage = next_stage;
    }

    if (final_stage == 0) 
        final_stage = reader_stage;
    
    return final_stage;    

}