26 #ifndef __TERRALIB_POSTGIS_INTERNAL_UTILS_H    27 #define __TERRALIB_POSTGIS_INTERNAL_UTILS_H    30 #include "../common/ByteSwapUtils.h"    31 #include "../common/Globals.h"    32 #include "../common/StringUtils.h"    33 #include "../dataaccess/Enums.h"    34 #include "../datatype/ArrayProperty.h"    35 #include "../datatype/Date.h"    36 #include "../datatype/DateTimeProperty.h"    37 #include "../datatype/NumericProperty.h"    38 #include "../datatype/SimpleProperty.h"    39 #include "../datatype/StringProperty.h"    40 #include "../datatype/TimeDuration.h"    41 #include "../datatype/TimeInstant.h"    42 #include "../datatype/TimeInstantTZ.h"    43 #include "../geometry/Envelope.h"    44 #include "../geometry/Geometry.h"    45 #include "../geometry/GeometryProperty.h"    46 #include "../raster/RasterProperty.h"    55 #include <boost/date_time/time_zone_base.hpp>    70   namespace core { 
class URI; }
   146       if(strcmp(t, 
"btree") == 0)
   150       else if(strcmp(t, 
"gist") == 0)
   154       else if(strcmp(t, 
"gin") == 0)
   174       std::string enve(str);
   175       size_t st = enve.find(
",");
   176       if(st != std::string::npos)
   177         enve.replace(st, 1, 
";");
   178       double dval = atof(
"1,2");
   182         while(st != std::string::npos)
   184           enve.replace(st, 1, 
",");
   188       const char* enveStr = enve.c_str();
   193       mbr->
m_llx = atof(enveStr);
   195       while(*enveStr != 
' ')
   200       mbr->
m_lly = atof(enveStr);
   202       while(*enveStr != 
';')
   207       mbr->
m_urx = atof(enveStr);
   209       while(*enveStr != 
' ')
   214       mbr->
m_ury = atof(enveStr);
   230       output += 
"ST_MakeEnvelope(";
   290       julian = y * 365 - 32167;
   291       julian += y / 4 - century + century / 4;
   292       julian += 7834 * m / 256 + d;
   307     inline void Julian2Date(
const int jd, 
int* year, 
int* month, 
int* day)
   309       unsigned int julian = 0;
   310       unsigned int quad = 0;
   311       unsigned int extra = 0;
   316       quad = julian / 146097;
   317       extra = (julian - quad * 146097) * 4 + 3;
   318       julian += 60 + quad * 3 + extra / 146097;
   319       quad = julian / 1461;
   320       julian -= quad * 1461;
   321       y = julian * 4 / 1461;
   322       julian = ((y != 0) ? ((julian + 305) % 365) : ((julian + 306) % 366)) + 123;
   325       quad = julian * 2141 / 65536;
   326       *day = julian - 7834 * quad / 256;
   327       *month = (quad + 10) % 12 + 1;
   348       int year, month, day;
   351       te::dt::DateTime* result = 
new te::dt::Date(static_cast<unsigned short>(year), static_cast<unsigned short>(month), static_cast<unsigned short>(day));
   367       int hour =  (int)(tval / 3600000000UL);
   368       boost::int64_t timeval = tval - hour * (boost::int64_t)3600000000UL;
   369       int min = (int)(timeval / 60000000);
   370       timeval -= min * (boost::int64_t)60000000;
   371       int sec = (int)(timeval / 1000000);
   372       timeval -= sec * (boost::int64_t)1000000;
   373       int fsec = (int) timeval;
   375       boost::posix_time::time_duration td(hour, min, sec, fsec);
   382       int hour =  (int)(tval / 3600000000UL);
   383       boost::int64_t timeval = tval - hour * (boost::int64_t)3600000000UL;
   384       int min = (int)(timeval / 60000000);
   385       timeval -= min * (boost::int64_t)60000000;
   386       int sec = (int)(timeval / 1000000);
   387       timeval -= sec * (boost::int64_t)1000000;
   388       int fsec = (int) timeval;
   390       boost::posix_time::time_duration td(hour, min, sec, fsec);
   392       sprintf(buf, 
"%d", z);
   393       std::string sz = 
"OFF";
   397       boost::local_time::time_zone_ptr zp(
new boost::local_time::posix_time_zone(sz));
   399       boost::posix_time::ptime pt(boost::gregorian::date(2000, 01, 01), td);
   400       boost::local_time::local_date_time tz(pt, zp);
   418       boost::int64_t dateval;
   419       boost::int64_t timeval = ival; 
   422       dateval = timeval / 86400000000LL;
   424         timeval -= dateval * 86400000000LL;  
   428           timeval += 86400000000LL;
   442       boost::int64_t dateval;
   443       boost::int64_t timeval = ival;
   446       dateval = timeval / 86400000000LL;
   448         timeval -= dateval * 86400000000LL;
   452           timeval += 86400000000LL;
   487                                                   bool attNotNull, 
const char* fmt,
   488                                                   bool attHasDefault, 
const char* attDefValue,
   489                                                   unsigned int pgisGeomTypeOid,
   490                                                   unsigned int pgisRasterTypeOid)
   495       std::string* defaultValue = (attHasDefault ? 
new std::string(attDefValue) : 
nullptr);
   496       std::string name = std::string(attName);
   498       if(attType == pgisGeomTypeOid)
   500       else if(attType == pgisRasterTypeOid)
   512           if (defaultValue != 0 && defaultValue->find(
"nextval(") == 0)
   522           if(defaultValue != 0 && defaultValue->find(
"nextval(") == 0)
   539             unsigned int precision = (fmt && (*(fmt + 7) != 
'\0') ? atoi(fmt + 8) : 0);
   540             const char* sprecision = fmt ? strstr(fmt,
",") : 0;
   541             unsigned int scale = (sprecision ? atoi(sprecision + 1) : 0);
   549             unsigned int size = fmt ? atoi(fmt + 18) : 0;
   588             unsigned int size = (fmt && (*(fmt + 9) != 
'\0') ? atoi(fmt + 10) : 0);
   624                                                   bool attNotNull, 
const char* fmt,
   625                                                   bool attHasDefault, 
const char* attDefValue,
   626                                                   int ndims, 
unsigned int pgisGeomTypeOid,
   627                                                   unsigned int pgisRasterTypeOid)
   631                                 attHasDefault, attDefValue,
   632                                 pgisGeomTypeOid, pgisRasterTypeOid);
   634       std::string* defaultValue = (attHasDefault ? 
new std::string(attDefValue) : 0);
   635       std::string name = std::string(attName);
   639       for(
int i = 0; i < ndims - 1; ++i)
   642       std::unique_ptr<te::dt::ArrayProperty> at(
new te::dt::ArrayProperty(name, arrayElementProperty, attNotNull, defaultValue, attNum));
   649             if(arrayElementProperty)
   652               at->setElementType(p);
   659             if(arrayElementProperty)
   662               at->setElementType(p);
   669             if(arrayElementProperty)
   672               at->setElementType(p);
   679             if(arrayElementProperty)
   682               at->setElementType(p);
   691             if(arrayElementProperty)
   694               at->setElementType(p);
   703             if(arrayElementProperty)
   706               at->setElementType(p);
   713             if(arrayElementProperty)
   716               at->setElementType(p);
   723             if(arrayElementProperty)
   726               at->setElementType(p);
   733             if(arrayElementProperty)
   736               at->setElementType(p);
   744             if(arrayElementProperty)
   747               at->setElementType(p);
   754             if(arrayElementProperty)
   757               at->setElementType(p);
   764             if(arrayElementProperty)
   767               at->setElementType(p);
   774             if(arrayElementProperty)
   777               at->setElementType(p);
   784             if(arrayElementProperty)
   787               at->setElementType(p);
   794             if(arrayElementProperty)
   797               at->setElementType(p);
   804             if(arrayElementProperty)
   807               at->setElementType(p);
   814             if(arrayElementProperty)
   817               at->setElementType(p);
   822             return Convert2TerraLib(attNum, attName, attType, attNotNull, fmt, attHasDefault, attDefValue, pgisGeomTypeOid, pgisRasterTypeOid);
   840           return "ST_Intersects";
   843           return "ST_Disjoint";
   849           return "ST_Overlaps";
   858           return "ST_Contains";
   864           return "ST_CoveredBy";
   920                           unsigned int pgisGeomTypeOid,
   921                           unsigned int pgisRasterTypeOid,
   922                           std::vector<int>& teTypes);
   934       if(gType & 0xF0000000)  
   938           gType = (gType & 0x0FFFFFFF) | 0xBB8;
   942           gType = (gType & 0x0FFFFFFF) | 0x3E8;
   946           gType = (gType & 0x0FFFFFFF) | 0x7D0;
   950           gType = (gType & 0x0FFFFFFF);
   958                         const std::string* defaultSchema,
   959                         std::string& schemaName,
   960                         std::string& tableName);
   964       if((gType & 0xF00) == 0xB00)    
   969       else if((gType & 0x0F00) == 0x300)
   974       else if((gType & 0xF00) == 0x700)
   989     std::string 
GetBindableWhereSQL(
const std::vector<te::dt::Property*>& properties, 
const std::size_t offset = 0);
  1011 #endif  // __TERRALIB_POSTGIS_INTERNAL_UTILS_H void setAutoNumber(bool a)
It tells if the property is an autonumber or not. 
 
std::string MakeConnectionStr(const te::core::URI &connInfo)
 
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code. 
 
void SplitTableName(const std::string &fullName, const std::string *defaultSchema, std::string &schemaName, std::string &tableName)
 
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...
 
#define PG_OID_ARRAY_TYPE
 
void ScapeString(PGconn *conn, const std::string &s, std::string &output)
It escapes a string for use within an SQL command. 
 
#define PG_TIME_ARRAY_TYPE
 
An atomic property like an integer or double. 
 
te::dt::DateTime * Internal2TimeTZ(boost::int64_t tval, int z)
 
te::dt::DateTime * Internal2Date(const long dDate)
It returns a DateTime type from a date loaded by PostgreSQL. 
 
A class that models the description of a dataset. 
 
FKActionType
Type of action performed on the foreign key data. 
 
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)...
 
#define PG__INT2_VECTOR_TYPE
 
#define PG_CHAR_ARRAY_TYPE
 
struct pg_result PGresult
 
#define PG_BYTEA_ARRAY_TYPE
 
te::dt::DateTime * Internal2TimeStampTZ(boost::int64_t ival, int z)
 
double m_urx
Upper right corner x-coordinate. 
 
SpatialRelation
Spatial relations between geometric objects. 
 
te::dt::DateTime * Internal2TimeStamp(boost::int64_t ival)
It returns a DateTime type from a timestamp loaded by PostgreSQL. 
 
#define PG_TEXT_ARRAY_TYPE
 
te::gm::Envelope * GetEnvelope(const char *str)
It converts the pgType to a valid TerraLib data type. 
 
#define PG_FLOAT4_ARRAY_TYPE
 
#define PG_INT2_ARRAY_TYPE
 
std::string GetLoadDataRow(const te::da::DataSetType *dt, te::da::DataSet *d, PGconn *conn)
 
#define PG_TIMETZ_ARRAY_TYPE
 
#define PG_TIMESTAMPTZ_ARRAY_TYPE
 
It models a property definition. 
 
A class to represent time instant. 
 
std::string GetSQLValues(const te::da::DataSetType *dt, te::da::DataSet *d, PGconn *conn)
 
#define PG_TIMESTAMP_TYPE
 
int Date2Julian(int y, int m, const int d)
It returns a julian date (in seconds) from a gregorian date. 
 
The type for arbitrary precison numbers, like numeric(p, q). 
 
double m_llx
Lower left corner x-coordinate. 
 
bool SetColumnDef(std::string &s, const te::dt::Property *p, bool justDataType=false)
It writes the PostgreSQL column definition to the output string. 
 
An Envelope defines a 2D rectangular region. 
 
A base class for date data types. 
 
Configuration flags for the PostGIS Driver Implementation of TerraLib. 
 
void Convert2PostGIS(const te::gm::Envelope *e, int srid, std::string &output)
It converts the envelope into a PostGIS BOX3D. 
 
#define PG_NAME_ARRAY_TYPE
 
#define PG_CHARACTER_ARRAY_TYPE
 
#define PG_CHARACTER_TYPE
 
The type for string types: FIXED_STRING, VAR_STRING or STRING. 
 
#define PG_INT8_ARRAY_TYPE
 
#define TE_EWKB_ZM_OFFSET
 
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards. 
 
const boost::local_time::local_date_time & getTimeInstantTZ() const
It returns the boost time instant with time zone type. 
 
#define PG_VARCHAR_ARRAY_TYPE
 
double m_lly
Lower left corner y-coordinate. 
 
void setElementType(Property *t)
It sets the type of array elements. 
 
A class to store the proxy information that must be used to access data located in URIs...
 
void Julian2Date(const int jd, int *year, int *month, int *day)
It returns a gregorian date from a julian date (in seconds). 
 
const std::string & GetGeometryName(te::gm::GeomType t)
It returns the geometry names as usual for PostGIS. 
 
A dataset is the unit of information manipulated by the data access module of TerraLib. 
 
The type for variable-length multidimensional arrays. 
 
#define PG_INT2_VECTOR_TYPE
 
double m_ury
Upper right corner y-coordinate. 
 
std::string GetSpatialRelation(te::gm::SpatialRelation rel)
It converts the spatial relationship to PostGIS dialect. 
 
A class to represent time duration with nano-second/micro-second resolution. 
 
#define PG_DATE_ARRAY_TYPE
 
void Convert2OGCWKBType(unsigned int &gType)
It converts the PostGIS geometry type to a pure OGC WKB code. 
 
The type for date and time types: date, date period, date duration, time duration, time instant, time period, time instant with time zone or time period with time zone. 
 
te::dt::Property * 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)
It creates a PropertyType from a PostgreSQL attribute description. 
 
#define PG_INT4_ARRAY_TYPE
 
#define PG_OID_VECTOR_TYPE
 
std::string GetSQLValue(const te::dt::Property *p, std::size_t propertyPos, te::da::DataSet *d, PGconn *conn)
 
void Convert2PostGISWKBType(unsigned int &gType)
 
#define PG_NUMERIC_ARRAY_TYPE
 
std::string GetBoxSpatialRelation(te::gm::SpatialRelation rel)
It converts the spatial relationship to PostGIS dialect. 
 
te::da::IndexType GetIndexType(const char *t)
It converts the PostgreSQL index string to a TerraLib index type. 
 
te::dt::DateTime * Internal2Time(boost::int64_t tval)
It returns a DateTime type from a time loaded by PostgreSQL. 
 
te::da::FKActionType GetAction(char a)
It converts the PostgreSQL foreign key modifier to a TerraLib data type. 
 
#define PG_TIMESTAMP_ARRAY_TYPE
 
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string. 
 
#define PG_FLOAT8_ARRAY_TYPE
 
A class to represent time instant with time zone. 
 
#define PG_BOOL_ARRAY_TYPE
 
std::string GetSQLBindValues(std::size_t nproperties)
 
#define PG_TIMESTAMPTZ_TYPE
 
const boost::gregorian::date & getDate() const
It returns the internal boost date type.