示例#1
0
文件: Writer.cpp 项目: dakcarto/PDAL
void Writer::initialize()
{
    pdal::Writer::initialize();

    std::string connection = getOptions().getValueOrDefault<std::string>("connection", "");
    if (!connection.size())
    {
        throw sqlite_driver_error("unable to connect to database, no connection string was given!");
    }

    try
    {
        m_session = new ::soci::session(::soci::sqlite3, connection);
        log()->get(logDEBUG) << "Connected to database" << std::endl;

    }
    catch (::soci::soci_error const& e)
    {
        std::stringstream oss;
        oss << "Unable to connect to database with error '" << e.what() << "'";
        throw pdal_error(oss.str());
    }

    m_session->set_log_stream(&(log()->get(logDEBUG2)));
    return;
}
示例#2
0
void IteratorBase::readBlob(::soci::row& block,
                            boost::uint32_t howMany)
{
    boost::uint32_t nAmountRead = 0;

    std::stringstream hex_data;
    hex_data << block.get<std::string>("points");

    std::size_t trim = 2;
    std::string trimmed = hex_data.str().substr(trim, hex_data.str().size()-trim);
    std::vector<boost::uint8_t> binary_data = Utils::hex_string_to_binary(trimmed);


    unsigned char* data = (unsigned char*) &(binary_data.front());

    Schema const& oracle_schema = m_active_buffer->getSchema();

    boost::uint32_t howMuchWeRead = binary_data.size();
    boost::uint32_t howMuchTheBlobShouldBe = block.get<int>("num_points") * oracle_schema.getByteSize();
    if (howMuchWeRead != howMuchTheBlobShouldBe)
    {
        std::stringstream oss;
        oss << "Did not read the amount of binary data as expected -- read: " << howMuchWeRead << " should read: " << howMuchTheBlobShouldBe;
        throw sqlite_driver_error(oss.str());
    }
    boost::uint32_t howMuchToRead = howMany * oracle_schema.getByteSize();
    m_active_buffer->setDataStride(data, 0, howMuchToRead);

    m_active_buffer->setNumPoints(howMany);
}
示例#3
0
void IteratorBase::fillUserBuffer(PointBuffer& user_buffer)
{

    Schema const& user_schema = user_buffer.getSchema();
    schema::index_by_index const& idx = user_schema.getDimensions().get<schema::index>();

    boost::int32_t numUserSpace = user_buffer.getCapacity() - user_buffer.getNumPoints();
    if (numUserSpace < 0)
        throw pdal_error("We ran out of space!");

    boost::int32_t numOraclePoints = m_active_buffer->getNumPoints() - m_buffer_position;

    schema::index_by_index::size_type i(0);
    for (i = 0; i < idx.size(); ++i)
    {
        copyDatabaseData(*m_active_buffer,
                         user_buffer,
                         idx[i],
                         m_buffer_position,
                         user_buffer.getNumPoints(),
                         (std::min)(numOraclePoints,numUserSpace));

    }

    bool bSetPointSourceId = getReader().getOptions().getValueOrDefault<bool>("populate_pointsourceid", false);
    if (bSetPointSourceId)
    {
        Dimension const* point_source_field = &(user_buffer.getSchema().getDimensionOptional("PointSourceId").get());
        if (point_source_field)
        {
            for (boost::int32_t i = 0; i < numUserSpace; ++i)
            {
                if (i < 0)
                    throw sqlite_driver_error("point_source_field point index is less than 0!");
                user_buffer.setField(*point_source_field, i, m_active_cloud_id);
            }
        }
    }

    if (numOraclePoints > numUserSpace)
        m_buffer_position = m_buffer_position + numUserSpace;
    else if (numOraclePoints < numUserSpace)
        m_buffer_position = 0;

    boost::uint32_t howManyThisRead = (std::min)(numUserSpace, numOraclePoints);
    user_buffer.setNumPoints(howManyThisRead + user_buffer.getNumPoints());
}
示例#4
0
文件: Writer.cpp 项目: dakcarto/PDAL
void Writer::CreateCloudTable(std::string const& name, boost::uint32_t srid)
{
    std::ostringstream oss;


        ::soci::sqlite3_session_backend* backend = static_cast< ::soci::sqlite3_session_backend*>( m_session->get_backend());
        
        try
        {
            int did_enable = sqlite3_enable_load_extension(static_cast<sqlite_api::sqlite3*>(backend->conn_), 1);
        
            if (did_enable == SQLITE_ERROR)
                throw sqlite_driver_error("Unable to enable extensions on sqlite backend -- can't enable spatialite");

            oss << "SELECT load_extension('libspatialite.dylib')";
            m_session->once << oss.str();
            oss.str("");
        } catch (std::runtime_error&)
        {
            throw;
        }

        oss << "SELECT InitSpatialMetadata()";
        m_session->once << oss.str();
        oss.str("");


        std::string cloud_column = getOptions().getValueOrDefault<std::string>("cloud_column", "id");
        oss << "CREATE TABLE " << boost::to_lower_copy(name)
            << " (" << boost::to_lower_copy(cloud_column) << " INTEGER PRIMARY KEY AUTOINCREMENT,"
            << " schema TEXT,"
            << " block_table varchar(64)"
            << ")";

        m_session->once << oss.str();
        oss.str("");
        {
            bool is3d = getOptions().getValueOrDefault<bool>("is3d", false);
            boost::uint32_t nDim = 2 ;// is3d ? 3 : 2;

            oss << "SELECT AddGeometryColumn('" << boost::to_lower_copy(name)
                << "'," << "'extent'" << ","
                << srid << ", 'POLYGON', 'XY')";
            m_session->once << oss.str();
            oss.str("");
        }
}