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) : 0);
   496       std::string name = std::string(attName);
   498       if(attType == pgisGeomTypeOid)
   500       else if(attType == pgisRasterTypeOid)
   512           if(defaultValue != 0 && defaultValue->find(
"nextval(") == 0)
   521           if(defaultValue != 0 && defaultValue->find(
"nextval(") == 0)
   537             unsigned int precision = (fmt && (*(fmt + 7) != 
'\0') ? atoi(fmt + 8) : 0);
   538             const char* sprecision = fmt ? strstr(fmt,
",") : 0;
   539             unsigned int scale = (sprecision ? atoi(sprecision + 1) : 0);
   547             unsigned int size = fmt ? atoi(fmt + 18) : 0;
   586             unsigned int size = (fmt && (*(fmt + 9) != 
'\0') ? atoi(fmt + 10) : 0);
   622                                                   bool attNotNull, 
const char* fmt,
   623                                                   bool attHasDefault, 
const char* attDefValue,
   624                                                   int ndims, 
unsigned int pgisGeomTypeOid,
   625                                                   unsigned int pgisRasterTypeOid)
   629                                 attHasDefault, attDefValue,
   630                                 pgisGeomTypeOid, pgisRasterTypeOid);
   632       std::string* defaultValue = (attHasDefault ? 
new std::string(attDefValue) : 0);
   633       std::string name = std::string(attName);
   637       for(
int i = 0; i < ndims - 1; ++i)
   647             if(arrayElementProperty)
   657             if(arrayElementProperty)
   667             if(arrayElementProperty)
   677             if(arrayElementProperty)
   689             if(arrayElementProperty)
   701             if(arrayElementProperty)
   711             if(arrayElementProperty)
   721             if(arrayElementProperty)
   731             if(arrayElementProperty)
   742             if(arrayElementProperty)
   752             if(arrayElementProperty)
   762             if(arrayElementProperty)
   772             if(arrayElementProperty)
   782             if(arrayElementProperty)
   792             if(arrayElementProperty)
   802             if(arrayElementProperty)
   812             if(arrayElementProperty)
   820             return Convert2TerraLib(attNum, attName, attType, attNotNull, fmt, attHasDefault, attDefValue, pgisGeomTypeOid, pgisRasterTypeOid);
   838           return "ST_Intersects";
   841           return "ST_Disjoint";
   847           return "ST_Overlaps";
   856           return "ST_Contains";
   862           return "ST_CoveredBy";
   918                           unsigned int pgisGeomTypeOid,
   919                           unsigned int pgisRasterTypeOid,
   920                           std::vector<int>& teTypes);
   932       if(gType & 0xF0000000)  
   936           gType = (gType & 0x0FFFFFFF) | 0xBB8;
   940           gType = (gType & 0x0FFFFFFF) | 0x3E8;
   944           gType = (gType & 0x0FFFFFFF) | 0x7D0;
   948           gType = (gType & 0x0FFFFFFF);
   956                         const std::string* defaultSchema,
   957                         std::string& schemaName,
   958                         std::string& tableName);
   962       if((gType & 0xF00) == 0xB00)    
   967       else if((gType & 0x0F00) == 0x300)
   972       else if((gType & 0xF00) == 0x700)
   987     std::string 
GetBindableWhereSQL(
const std::vector<te::dt::Property*>& properties, 
const std::size_t offset = 0);
  1009 #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)
 
#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. 
 
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...
 
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. 
 
#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. 
 
const boost::gregorian::date & getDate() const 
It returns the internal boost date type. 
 
An Envelope defines a 2D rectangular region. 
 
A base class for date data types. 
 
Configuration flags for the PostGIS Driver Implementation of TerraLib. 
 
#define PG_NAME_ARRAY_TYPE
 
#define PG_CHARACTER_ARRAY_TYPE
 
void Convert2PostGIS(PGconn *conn, const te::gm::Geometry *g, std::string &output)
It converts the geometry into a PostGIS geometry. 
 
const boost::local_time::local_date_time & getTimeInstantTZ() const 
It returns the boost time instant with time zone 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. 
 
#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 for representing an Uniform Resource Identifier (URI). 
 
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. 
 
#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
 
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)...