Skip to content

Commit

Permalink
Working writer for pgpointcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Ramsey committed May 13, 2013
1 parent 39a6bf7 commit 6bf31f7
Show file tree
Hide file tree
Showing 4 changed files with 406 additions and 722 deletions.
78 changes: 37 additions & 41 deletions include/pdal/drivers/pgpointcloud/Writer.hpp
Expand Up @@ -52,20 +52,17 @@ namespace pgpointcloud
class PDAL_DLL Writer : public pdal::Writer
{
public:
SET_STAGE_NAME("drivers.pgpointcloud.writer", "Database Writer")
SET_STAGE_NAME("drivers.pgpointcloud.writer", "PostgresSQL Pointcloud Database Writer")

Writer(Stage& prevStage, const Options&);
~Writer();

virtual void initialize();
static Options getDefaultOptions();



protected:
virtual void writeBegin(boost::uint64_t targetNumPointsToWrite);
virtual void writeBufferBegin(PointBuffer const&);

virtual boost::uint32_t writeBuffer(const PointBuffer&);
virtual void writeEnd(boost::uint64_t actualNumPointsWritten);

Expand All @@ -74,53 +71,52 @@ class PDAL_DLL Writer : public pdal::Writer
Writer& operator=(const Writer&); // not implemented
Writer(const Writer&); // not implemented

void CreateBlockTable(std::string const& name, boost::uint32_t srid);
void CreateCloudTable(std::string const& name, boost::uint32_t srid);
bool CheckTableExists(std::string const& name);
void DeleteBlockTable(std::string const& cloud_table_name,
std::string const& cloud_column_name,
std::string const& block_table_name);
void DeleteCloudTable(std::string const& cloud_table_name,
std::string const& cloud_column_name);
void CreateIndexes(std::string const& table_name,
std::string const& spatial_column_name,
bool is3d,
bool isBlockTable=true);
void CreateSDOEntry(std::string const& block_table,
boost::uint32_t srid,
pdal::Bounds<double> bounds,
bool is3d);
Schema getPackedSchema( Schema const& schema) const;
bool IsValidGeometryWKT(std::string const& wkt) const;
std::string loadGeometryWKT(std::string const& filename_or_wkt) const;
void CreateCloud(Schema const& buffer_schema);

void PackPointData( PointBuffer const& buffer,
boost::uint8_t** point_data,
boost::uint32_t& point_data_len,
boost::uint32_t& schema_byte_size);
bool CheckPointCloudExists();
bool CheckPostGISExists();
Schema PackSchema(Schema const& schema) const;
boost::uint32_t SetupSchema(Schema const& buffer_schema, boost::uint32_t srid);

void CreateTable(std::string const& schema_name,
std::string const& table_name,
std::string const& column_name,
boost::uint32_t pcid);

void DeleteTable(std::string const& schema_name,
std::string const& table_name);

void CreateIndex(std::string const& schema_name,
std::string const& table_name,
std::string const& column_name);

void PackPointData(PointBuffer const& buffer,
boost::uint8_t** point_data,
boost::uint32_t& point_data_len,
boost::uint32_t& schema_byte_size);

bool WriteBlock(PointBuffer const& buffer);

#ifdef PDAL_HAVE_SOCI
::soci::session* m_session;
::soci::statement* m_block_statement;
#else
void* m_session;
#endif

DatabaseType m_type;
bool m_doCreateIndex;
pdal::Bounds<double> m_bounds; // Bounds of the entire point cloud
const pdal::Schema &m_pdal_schema;
std::string m_schema_name;
std::string m_table_name;
std::string m_column_name;
CompressionType m_patch_compression_type;
boost::uint32_t m_patch_capacity;
boost::uint32_t m_srid;
boost::uint32_t m_pcid;
bool m_have_postgis;
bool m_create_index;
bool m_overwrite;


// lose this
bool m_sdo_pc_is_initialized;
std::ostringstream m_block_insert_query;
std::ostringstream m_block_bytes;
std::string m_block_data;
std::string m_extent;
std::string m_bbox;
boost::int32_t m_obj_id;
boost::int32_t m_block_id;
boost::uint32_t m_srid;
boost::int64_t m_num_points;
};

}
Expand Down
111 changes: 40 additions & 71 deletions include/pdal/drivers/pgpointcloud/common.hpp
Expand Up @@ -57,85 +57,54 @@ namespace drivers
namespace pgpointcloud
{

class soci_driver_error : public pdal_error
{
public:
soci_driver_error(std::string const& msg)
: pdal_error(msg)
{}
};

class connection_failed : public soci_driver_error
{
public:
connection_failed(std::string const& msg)
: soci_driver_error(msg)
{}
};

class buffer_too_small : public soci_driver_error
{
public:
buffer_too_small(std::string const& msg)
: soci_driver_error(msg)
{}
};


enum DatabaseType
{
DATABASE_POSTGRESQL,
DATABASE_ORACLE,
DATABASE_UNKNOWN = 128
};

enum QueryType
{
QUERY_CLOUD = 0,
QUERY_BLOCKS_PLUS_CLOUD_VIEW,
QUERY_UNKNOWN = 512
};


inline DatabaseType getDatabaseConnectionType(std::string const& connection_type)
class soci_driver_error : public pdal_error
{
DatabaseType output;
public:
soci_driver_error(std::string const& msg)
: pdal_error(msg)
{}
};

if (boost::iequals(connection_type, "oracle"))
output = DATABASE_ORACLE;
else if (boost::iequals(connection_type, "postgresql"))
output = DATABASE_POSTGRESQL;
class connection_failed : public soci_driver_error
{
public:
connection_failed(std::string const& msg)
: soci_driver_error(msg)
{}
};

class buffer_too_small : public soci_driver_error
{
public:
buffer_too_small(std::string const& msg)
: soci_driver_error(msg)
{}
};


enum CompressionType
{
COMPRESSION_NONE = 0,
COMPRESSION_GHT = 1,
COMPRESSION_DIMENSIONAL = 2
};


inline CompressionType getCompressionType(std::string const& compression_type)
{
CompressionType output;

if (boost::iequals(compression_type, "dimensional"))
output = COMPRESSION_DIMENSIONAL;
else if (boost::iequals(compression_type, "ght"))
output = COMPRESSION_GHT;
else
output = DATABASE_UNKNOWN;
output = COMPRESSION_NONE;

return output;

}

inline ::soci::session* connectToDataBase(std::string const& connection, DatabaseType dtype)
{
::soci::session* output(0);
if (dtype == DATABASE_UNKNOWN)
{
std::stringstream oss;
oss << "Database connection type '" << dtype << "' is unknown or not configured";
throw soci_driver_error(oss.str());
}

try
{
if (dtype == DATABASE_POSTGRESQL)
output = new ::soci::session(::soci::postgresql, connection);

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

return output;
}

}
}
Expand Down
4 changes: 4 additions & 0 deletions src/StageFactory.cpp
Expand Up @@ -81,6 +81,8 @@
#ifndef USE_PDAL_PLUGIN_SOCI
#include <pdal/drivers/soci/Reader.hpp>
#include <pdal/drivers/soci/Writer.hpp>
/* #include <pdal/drivers/pgpointcloud/Reader.hpp> */
#include <pdal/drivers/pgpointcloud/Writer.hpp>
#endif
#endif

Expand Down Expand Up @@ -197,6 +199,7 @@ MAKE_WRITER_CREATOR(P2GWriter, pdal::drivers::p2g::Writer)

#ifdef PDAL_HAVE_SOCI
#ifndef USE_PDAL_PLUGIN_SOCI
MAKE_WRITER_CREATOR(PgPcWriter, pdal::drivers::pgpointcloud::Writer)
MAKE_WRITER_CREATOR(SociWriter, pdal::drivers::soci::Writer)
#endif
#endif
Expand Down Expand Up @@ -482,6 +485,7 @@ void StageFactory::registerKnownWriters()
#ifdef PDAL_HAVE_SOCI
#ifndef USE_PDAL_PLUGIN_SOCI
REGISTER_WRITER(SociWriter, pdal::drivers::soci::Writer);
REGISTER_WRITER(PgPcWriter, pdal::drivers::pgpointcloud::Writer);
#endif
#endif

Expand Down

0 comments on commit 6bf31f7

Please sign in to comment.