te::pgis Namespace Reference

Namespace for the TerraLib PostGIS driver implementation. More...

Classes

struct  Array
 Auxiliary structure used to decode Array data types. More...
 
class  ConnectedDataSet
 Implementation of a connected dataset for the PostGIS driver. More...
 
class  Connection
 A class that implements a connection to a PostgreSQL database. More...
 
class  ConnectionPool
 This class implements a connection pool for the PostGIS driver. More...
 
class  DataSet
 Implementation of a dataset for the PostGIS driver. More...
 
class  DataSource
 The PostGIS driver. More...
 
class  EWKBReader
 An utility class for reading a PostGIS EWKB. More...
 
class  EWKBWriter
 An utility class for writing a PostGIS EWKB. More...
 
class  Globals
 An static class with global definitions. More...
 
struct  Numeric
 Auxiliary structure used to decode Numeric data types. More...
 
class  PreparedQuery
 A class that implements a prepared query for PostgreSQL data access driver. More...
 
class  SQLVisitor
 A visitor for building an SQL statement using PostGIS dialect. More...
 
class  Transactor
 The transactor class for the PostGIS driver. More...
 
struct  VersionInfo
 A data structure for holding version information. More...
 

Typedefs

typedef boost::shared_ptr< TransactorTransactorPtr
 

Functions

te::da::DataSourceBuild (const te::core::URI &uri)
 
void Convert2OGCWKBType (unsigned int &gType)
 It converts the PostGIS geometry type to a pure OGC WKB code. More...
 
void Convert2PostGIS (const te::gm::Envelope *e, int srid, std::string &output)
 It converts the envelope into a PostGIS BOX3D. More...
 
void Convert2PostGIS (PGconn *conn, const te::gm::Geometry *g, std::string &output)
 It converts the geometry into a PostGIS geometry. More...
 
void Convert2PostGISWKBType (unsigned int &gType)
 
te::dt::PropertyConvert2TerraLib (unsigned int attNum, const char *attName, unsigned int attType, bool attNotNull, const char *fmt, bool attHasDefault, const char *attDefValue, unsigned int pgisGeomTypeOid, unsigned int pgisRasterTypeOid)
 It creates a PropertyType from a PostgreSQL attribute description. More...
 
te::dt::PropertyConvert2TerraLib (unsigned int attNum, const char *attName, unsigned int attType, bool attNotNull, const char *fmt, bool attHasDefault, const char *attDefValue, int ndims, unsigned int pgisGeomTypeOid, unsigned int pgisRasterTypeOid)
 It creates a PropertyType from a PostgreSQL attribute description. More...
 
void Convert2TerraLib (PGresult *result, unsigned int pgisGeomTypeOid, unsigned int pgisRasterTypeOid, std::vector< int > &teTypes)
 It creates a data set type from a PostGIS internal result. More...
 
int Date2Julian (int y, int m, const int d)
 It returns a julian date (in seconds) from a gregorian date. More...
 
te::da::FKActionType GetAction (char a)
 It converts the PostgreSQL foreign key modifier to a TerraLib data type. More...
 
std::string GetBindableUpdateSQL (const std::vector< te::dt::Property * > &properties)
 Given a list of properties it constructs a string with bindable parameters that can be used inside an update query. More...
 
std::string GetBindableWhereSQL (const std::vector< te::dt::Property * > &properties, const std::size_t offset=0)
 Given a list of properties it creates an AND connected expression with bindable parameters ($n). More...
 
std::string GetBoxSpatialRelation (te::gm::SpatialRelation rel)
 It converts the spatial relationship to PostGIS dialect. More...
 
te::gm::EnvelopeGetEnvelope (const char *str)
 It converts the pgType to a valid TerraLib data type. More...
 
const std::string & GetGeometryName (te::gm::GeomType t)
 It returns the geometry names as usual for PostGIS. More...
 
te::da::IndexType GetIndexType (const char *t)
 It converts the PostgreSQL index string to a TerraLib index type. More...
 
std::string GetLoadDataRow (const te::da::DataSetType *dt, te::da::DataSet *d, PGconn *conn)
 
std::string GetSpatialRelation (te::gm::SpatialRelation rel)
 It converts the spatial relationship to PostGIS dialect. More...
 
std::string GetSQLBindValues (std::size_t nproperties)
 
std::string GetSQLValue (const te::dt::Property *p, std::size_t propertyPos, te::da::DataSet *d, PGconn *conn)
 
std::string GetSQLValues (const te::da::DataSetType *dt, te::da::DataSet *d, PGconn *conn)
 
te::dt::DateTimeInternal2Date (const long dDate)
 It returns a DateTime type from a date loaded by PostgreSQL. More...
 
te::dt::DateTimeInternal2Time (boost::int64_t tval)
 It returns a DateTime type from a time loaded by PostgreSQL. More...
 
te::dt::DateTimeInternal2TimeStamp (boost::int64_t ival)
 It returns a DateTime type from a timestamp loaded by PostgreSQL. More...
 
te::dt::DateTimeInternal2TimeStampTZ (boost::int64_t ival, int z)
 
te::dt::DateTimeInternal2TimeTZ (boost::int64_t tval, int z)
 
void Julian2Date (const int jd, int *year, int *month, int *day)
 It returns a gregorian date from a julian date (in seconds). More...
 
std::string MakeConnectionStr (const te::core::URI &connInfo)
 
void ScapeString (PGconn *conn, const std::string &s, std::string &output)
 It escapes a string for use within an SQL command. More...
 
bool SetColumnDef (std::string &s, const te::dt::Property *p, bool justDataType=false)
 It writes the PostgreSQL column definition to the output string. More...
 
void SplitTableName (const std::string &fullName, const std::string *defaultSchema, std::string &schemaName, std::string &tableName)
 

Detailed Description

Namespace for the TerraLib PostGIS driver implementation.

Typedef Documentation

typedef boost::shared_ptr<Transactor> te::pgis::TransactorPtr

Definition at line 475 of file Transactor.h.

Function Documentation

te::da::DataSource* te::pgis::Build ( const te::core::URI uri)
void te::pgis::Convert2OGCWKBType ( unsigned int &  gType)
inline

It converts the PostGIS geometry type to a pure OGC WKB code.

This function will turn off the PostGIS flags and will turn on the right bits for OGC WKB type.

Parameters
gTypeA value that can have some flags set by PostGIS.

Definition at line 930 of file Utils.h.

References TE_EWKB_M_OFFSET, TE_EWKB_Z_OFFSET, and TE_EWKB_ZM_OFFSET.

void te::pgis::Convert2PostGIS ( const te::gm::Envelope e,
int  srid,
std::string &  output 
)
inline

It converts the envelope into a PostGIS BOX3D.

Parameters
eThe envelope to be converted.
sridThe envelope coordinates SRS.
outputThe string to output the result.

Definition at line 228 of file Utils.h.

References te::common::Convert2String(), te::gm::Envelope::m_llx, te::gm::Envelope::m_lly, te::gm::Envelope::m_urx, and te::gm::Envelope::m_ury.

void te::pgis::Convert2PostGIS ( PGconn conn,
const te::gm::Geometry g,
std::string &  output 
)

It converts the geometry into a PostGIS geometry.

Parameters
connThe connection to be used with bytearray.
gThe geometry to be converted.
outputThe string to output the result.
void te::pgis::Convert2PostGISWKBType ( unsigned int &  gType)
inline

Definition at line 960 of file Utils.h.

References TE_EWKB_M_OFFSET, TE_EWKB_Z_OFFSET, and TE_EWKB_ZM_OFFSET.

te::dt::Property* te::pgis::Convert2TerraLib ( unsigned int  attNum,
const char *  attName,
unsigned int  attType,
bool  attNotNull,
const char *  fmt,
bool  attHasDefault,
const char *  attDefValue,
unsigned int  pgisGeomTypeOid,
unsigned int  pgisRasterTypeOid 
)
inline

It creates a PropertyType from a PostgreSQL attribute description.

Parameters
attNumThe column number (a number in the range [1, num-columns]).
attNameThe column name.
attTypeThe column type
attLenThe column size (depends on column type).
attNotNullIf the column is not null.
fmtColumn formats: Numeric(20, 30), VARCHAR(30), CHAR(10).
attHasDefaultTrue if the column has a default value.
attDefValueThe default value expression if attHasDefValue is true otherwise this has no meaning.
pgisGeomTypeOidThe oid of PostGIS geometry type.
Returns
The TerraLib equivalent datatype.
Note
The caller of this function will take the ownership of the returned PropertyType.
This method is valid just for types different from Array. For array types, see the method below (Convert2TerraLib) where the dimension info must be available.

Definition at line 486 of file Utils.h.

References te::dt::BOOLEAN_TYPE, te::dt::BYTE_ARRAY_TYPE, te::dt::CHAR_TYPE, te::dt::DATE, te::dt::DOUBLE_TYPE, te::dt::FIXED_STRING, te::dt::FLOAT_TYPE, te::dt::INT16_TYPE, te::dt::INT32_TYPE, te::dt::INT64_TYPE, PG_BOOL_TYPE, PG_BYTEA_TYPE, PG_CHAR_TYPE, PG_CHARACTER_TYPE, PG_DATE_TYPE, PG_FLOAT4_TYPE, PG_FLOAT8_TYPE, PG_INT2_TYPE, PG_INT4_TYPE, PG_INT8_TYPE, PG_NAME_TYPE, PG_NUMERIC_TYPE, PG_OID_TYPE, PG_TEXT_TYPE, PG_TIME_TYPE, PG_TIMESTAMP_TYPE, PG_TIMESTAMPTZ_TYPE, PG_TIMETZ_TYPE, PG_VARCHAR_TYPE, te::dt::SimpleProperty::setAutoNumber(), te::dt::STRING, te::dt::TIME_DURATION, te::dt::TIME_INSTANT, te::dt::UNKNOWN_TYPE, and te::dt::VAR_STRING.

Referenced by Convert2TerraLib().

te::dt::Property* te::pgis::Convert2TerraLib ( unsigned int  attNum,
const char *  attName,
unsigned int  attType,
bool  attNotNull,
const char *  fmt,
bool  attHasDefault,
const char *  attDefValue,
int  ndims,
unsigned int  pgisGeomTypeOid,
unsigned int  pgisRasterTypeOid 
)
inline

It creates a PropertyType from a PostgreSQL attribute description.

Parameters
attNumThe column number.
attNameThe column name.
attTypeThe column type.
attNotNullIf the column is not null.
fmtColumn formats: Numeric(20, 30), VARCHAR(30), CHAR(10).
attHasDefaultTrue, if the column has a default value.
attDefValueThe default value expression, if attHasDefValue is true; otherwise, it has no meaning.
ndimsIf different of 0, it indicates an array type.
pgisGeomTypeOidThe oid of the PostGIS geometry type.
Returns
The TerraLib equivalent PropertyType.
Note
The caller of this method will take the ownership of the returned PropertyType.
This method may be used for array types also.

Definition at line 621 of file Utils.h.

References Convert2TerraLib(), PG__INT2_VECTOR_TYPE, PG_BOOL_ARRAY_TYPE, PG_BOOL_TYPE, PG_BYTEA_ARRAY_TYPE, PG_BYTEA_TYPE, PG_CHAR_ARRAY_TYPE, PG_CHAR_TYPE, PG_CHARACTER_ARRAY_TYPE, PG_CHARACTER_TYPE, PG_DATE_ARRAY_TYPE, PG_DATE_TYPE, PG_FLOAT4_ARRAY_TYPE, PG_FLOAT4_TYPE, PG_FLOAT8_ARRAY_TYPE, PG_FLOAT8_TYPE, PG_INT2_ARRAY_TYPE, PG_INT2_TYPE, PG_INT2_VECTOR_TYPE, PG_INT4_ARRAY_TYPE, PG_INT4_TYPE, PG_INT8_ARRAY_TYPE, PG_INT8_TYPE, PG_NAME_ARRAY_TYPE, PG_NUMERIC_ARRAY_TYPE, PG_NUMERIC_TYPE, PG_OID_ARRAY_TYPE, PG_OID_VECTOR_TYPE, PG_TEXT_ARRAY_TYPE, PG_TEXT_TYPE, PG_TIME_ARRAY_TYPE, PG_TIME_TYPE, PG_TIMESTAMP_ARRAY_TYPE, PG_TIMESTAMP_TYPE, PG_TIMESTAMPTZ_ARRAY_TYPE, PG_TIMESTAMPTZ_TYPE, PG_TIMETZ_ARRAY_TYPE, PG_TIMETZ_TYPE, PG_VARCHAR_ARRAY_TYPE, PG_VARCHAR_TYPE, and te::dt::ArrayProperty::setElementType().

void te::pgis::Convert2TerraLib ( PGresult result,
unsigned int  pgisGeomTypeOid,
unsigned int  pgisRasterTypeOid,
std::vector< int > &  teTypes 
)

It creates a data set type from a PostGIS internal result.

Parameters
resultA PostGIS internal result.
pgisGeomTypeOidThe oid of PostGIS geometry type.
Returns
The data set type created.
int te::pgis::Date2Julian ( int  y,
int  m,
const int  d 
)
inline

It returns a julian date (in seconds) from a gregorian date.

It returns a julian date (in seconds) from a gregorian date. Internally, postgresql stores julian dates.

Parameters
yA year of a gregorian date.
mA month of a gregorian date.
dA day of a gregorian date.
Returns
a julian date in seconds from the informed gregorian date.

Definition at line 273 of file Utils.h.

te::da::FKActionType te::pgis::GetAction ( char  a)
inline

It converts the PostgreSQL foreign key modifier to a TerraLib data type.

  • a: NO_ACTION
  • r: RESTRICT
  • c: CASCADE
  • n: SET_NULL
  • d: SET_DEFAULT
Parameters
aPostgreSQL foreign key modifier type.

The equivalent TerraLib foreign key modifier type.

Definition at line 116 of file Utils.h.

References te::da::CASCADE, te::da::NO_ACTION, te::da::RESTRICT, te::da::SET_DEFAULT, and te::da::SET_NULL.

std::string te::pgis::GetBindableUpdateSQL ( const std::vector< te::dt::Property * > &  properties)

Given a list of properties it constructs a string with bindable parameters that can be used inside an update query.

Parameters
propertiesA vector with property names that will be used to create the expression.
Returns
A comma (',') connected expression with bindable parameters ($1) that can be used in an UPDATE query.
std::string te::pgis::GetBindableWhereSQL ( const std::vector< te::dt::Property * > &  properties,
const std::size_t  offset = 0 
)

Given a list of properties it creates an AND connected expression with bindable parameters ($n).

Parameters
itBeginThe start property.
itEndThe mark of end of properties.
Returns
An AND connected expression with bindable parameters ($n) that can be used in WHERE expressions.
std::string te::pgis::GetBoxSpatialRelation ( te::gm::SpatialRelation  rel)
inline

It converts the spatial relationship to PostGIS dialect.

Parameters
relThe spatial relationship.
Returns
The PostGIS relationship name.

Definition at line 879 of file Utils.h.

References te::gm::CONTAINS, te::gm::COVEREDBY, te::gm::COVERS, te::gm::EQUALS, te::gm::INTERSECTS, te::gm::OVERLAPS, and te::gm::WITHIN.

te::gm::Envelope* te::pgis::GetEnvelope ( const char *  str)
inline

It converts the pgType to a valid TerraLib data type.

Parameters
colsAn array with column numbers.
dtThe DataSetType to look for the property.
Returns
The next.

Definition at line 172 of file Utils.h.

References te::gm::Envelope::m_llx, te::gm::Envelope::m_lly, te::gm::Envelope::m_urx, and te::gm::Envelope::m_ury.

const std::string& te::pgis::GetGeometryName ( te::gm::GeomType  t)

It returns the geometry names as usual for PostGIS.

Parameters
tThe TerraLib geometry type.
Returns
The geometry names as usual for PostGIS.
te::da::IndexType te::pgis::GetIndexType ( const char *  t)
inline

It converts the PostgreSQL index string to a TerraLib index type.

  • btree: BTreeType
  • gist: RTreeType
  • gin: BTreeType
  • hash: HashType
Parameters
tPostgreSQL index name (A NULL terminated string).

The equivalent TerraLib foreign key modifier type.

Definition at line 144 of file Utils.h.

References te::da::B_TREE_TYPE, te::da::HASH_TYPE, and te::da::R_TREE_TYPE.

std::string te::pgis::GetLoadDataRow ( const te::da::DataSetType dt,
te::da::DataSet d,
PGconn conn 
)
std::string te::pgis::GetSpatialRelation ( te::gm::SpatialRelation  rel)
inline

It converts the spatial relationship to PostGIS dialect.

Parameters
relThe spatial relationship.
Returns
The PostGIS relationship name.

Definition at line 833 of file Utils.h.

References te::gm::CONTAINS, te::gm::COVEREDBY, te::gm::COVERS, te::gm::CROSSES, te::gm::DISJOINT, te::gm::EQUALS, te::gm::INTERSECTS, te::gm::OVERLAPS, te::gm::TOUCHES, and te::gm::WITHIN.

std::string te::pgis::GetSQLBindValues ( std::size_t  nproperties)
std::string te::pgis::GetSQLValue ( const te::dt::Property p,
std::size_t  propertyPos,
te::da::DataSet d,
PGconn conn 
)
std::string te::pgis::GetSQLValues ( const te::da::DataSetType dt,
te::da::DataSet d,
PGconn conn 
)
te::dt::DateTime* te::pgis::Internal2Date ( const long  dDate)
inline

It returns a DateTime type from a date loaded by PostgreSQL.

It returns a DateTime type from a date loaded by PostgreSQL. Internelly, PostgreSQL stores julian dates in 4 bytes, so this function has to convert it to gregorian date. Besides that, PostgreSQL stores date as seconds before or after midnight 2000-01-01. Therefore, this function has to sum the number of seconds (2451545 seconds) between 01-01-01 00:00:00 and 01-01-2000 00:00:00 to the date.

Parameters
dDateA julian date in seconds loaded by PostgreSQL.
returnA gregorian date from the input julian date.

Definition at line 346 of file Utils.h.

References Julian2Date().

Referenced by Internal2TimeStamp(), and Internal2TimeStampTZ().

te::dt::DateTime* te::pgis::Internal2Time ( boost::int64_t  tval)
inline

It returns a DateTime type from a time loaded by PostgreSQL.

It returns a DateTime type from a time loaded by PostgreSQL. Internelly, PostgreSQL stores time as seconds.

Parameters
tvalThe amount of seconds loaded by PostgreSQL.
returnA time (hour, minute, second) from the input amount of seconds.

Definition at line 365 of file Utils.h.

Referenced by Internal2TimeStamp().

te::dt::DateTime* te::pgis::Internal2TimeStamp ( boost::int64_t  ival)
inline

It returns a DateTime type from a timestamp loaded by PostgreSQL.

It returns a DateTime type from a timestamp loaded by PostgreSQL. Internelly, PostgreSQL stores timestamp as seconds before or after midnight 2000-01-01.

Parameters
ivalThe timestamp, in seconds, loaded by PostgreSQL.
returnA time instant from the input timestamp.

Definition at line 416 of file Utils.h.

References Internal2Date(), and Internal2Time().

te::dt::DateTime* te::pgis::Internal2TimeStampTZ ( boost::int64_t  ival,
int  z 
)
inline
te::dt::DateTime* te::pgis::Internal2TimeTZ ( boost::int64_t  tval,
int  z 
)
inline

Definition at line 380 of file Utils.h.

Referenced by Internal2TimeStampTZ().

void te::pgis::Julian2Date ( const int  jd,
int *  year,
int *  month,
int *  day 
)
inline

It returns a gregorian date from a julian date (in seconds).

It returns a gregorian date from a julian date (in seconds).

Parameters
jdA julian date in seconds (INPUT).
yearThe year of a gregorian date that will be filled by this function (OUTPUT).
monthThe month of a gregorian date that will be filled by this function (OUTPUT).
dayThe day of a gregorian date that will be filled by this function (OUTPUT).

Definition at line 307 of file Utils.h.

Referenced by Internal2Date().

std::string te::pgis::MakeConnectionStr ( const te::core::URI connInfo)
void te::pgis::ScapeString ( PGconn conn,
const std::string &  s,
std::string &  output 
)

It escapes a string for use within an SQL command.

Parameters
connThe connection to be used with bytearray.
sThe string to be scapaded.
outputThe string to output the result.
bool te::pgis::SetColumnDef ( std::string &  s,
const te::dt::Property p,
bool  justDataType = false 
)

It writes the PostgreSQL column definition to the output string.

Parameters
sThe string to output the column definition.
pThe TerraLib propoerty type.
Returns
It returns true if the property type is an autonumber.
Exceptions
ExceptionIt throws an exception if the data type is not mapped to the PostgreSQL type system.
void te::pgis::SplitTableName ( const std::string &  fullName,
const std::string *  defaultSchema,
std::string &  schemaName,
std::string &  tableName 
)