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"
54 #include <boost/date_time/time_zone_base.hpp>
143 if(strcmp(t,
"btree") == 0)
147 else if(strcmp(t,
"gist") == 0)
151 else if(strcmp(t,
"gin") == 0)
171 std::string enve(str);
172 size_t st = enve.find(
",");
173 if(st != std::string::npos)
174 enve.replace(st, 1,
";");
175 double dval = atof(
"1,2");
179 while(st != std::string::npos)
181 enve.replace(st, 1,
",");
185 const char* enveStr = enve.c_str();
190 mbr->
m_llx = atof(enveStr);
192 while(*enveStr !=
' ')
197 mbr->
m_lly = atof(enveStr);
199 while(*enveStr !=
';')
204 mbr->
m_urx = atof(enveStr);
206 while(*enveStr !=
' ')
211 mbr->
m_ury = atof(enveStr);
227 output +=
"ST_MakeEnvelope(";
287 julian = y * 365 - 32167;
288 julian += y / 4 - century + century / 4;
289 julian += 7834 * m / 256 + d;
304 inline void Julian2Date(
const int jd,
int* year,
int* month,
int* day)
306 unsigned int julian = 0;
307 unsigned int quad = 0;
308 unsigned int extra = 0;
313 quad = julian / 146097;
314 extra = (julian - quad * 146097) * 4 + 3;
315 julian += 60 + quad * 3 + extra / 146097;
316 quad = julian / 1461;
317 julian -= quad * 1461;
318 y = julian * 4 / 1461;
319 julian = ((y != 0) ? ((julian + 305) % 365) : ((julian + 306) % 366)) + 123;
322 quad = julian * 2141 / 65536;
323 *day = julian - 7834 * quad / 256;
324 *month = (quad + 10) % 12 + 1;
345 int year, month, day;
348 te::dt::DateTime* result =
new te::dt::Date(static_cast<unsigned short>(year), static_cast<unsigned short>(month), static_cast<unsigned short>(day));
364 int hour = (int)(tval / 3600000000UL);
365 boost::int64_t timeval = tval - hour * (boost::int64_t)3600000000UL;
366 int min = (int)(timeval / 60000000);
367 timeval -= min * (boost::int64_t)60000000;
368 int sec = (int)(timeval / 1000000);
369 timeval -= sec * (boost::int64_t)1000000;
370 int fsec = (int) timeval;
372 boost::posix_time::time_duration td(hour, min, sec, fsec);
379 int hour = (int)(tval / 3600000000UL);
380 boost::int64_t timeval = tval - hour * (boost::int64_t)3600000000UL;
381 int min = (int)(timeval / 60000000);
382 timeval -= min * (boost::int64_t)60000000;
383 int sec = (int)(timeval / 1000000);
384 timeval -= sec * (boost::int64_t)1000000;
385 int fsec = (int) timeval;
387 boost::posix_time::time_duration td(hour, min, sec, fsec);
389 sprintf(buf,
"%d", z);
390 std::string sz =
"OFF";
394 boost::local_time::time_zone_ptr zp(
new boost::local_time::posix_time_zone(sz));
396 boost::posix_time::ptime pt(boost::gregorian::date(2000, 01, 01), td);
397 boost::local_time::local_date_time tz(pt, zp);
415 boost::int64_t dateval;
416 boost::int64_t timeval = ival;
419 dateval = timeval / 86400000000LL;
421 timeval -= dateval * 86400000000LL;
425 timeval += 86400000000LL;
457 bool attNotNull,
const char* fmt,
458 bool attHasDefault,
const char* attDefValue,
459 unsigned int pgisGeomTypeOid,
460 unsigned int pgisRasterTypeOid)
465 std::string* defaultValue = (attHasDefault ?
new std::string(attDefValue) : 0);
466 std::string name = std::string(attName);
468 if(attType == pgisGeomTypeOid)
470 else if(attType == pgisRasterTypeOid)
482 if(defaultValue != 0 && defaultValue->find(
"nextval(") == 0)
491 if(defaultValue != 0 && defaultValue->find(
"nextval(") == 0)
507 unsigned int precision = (fmt && (*(fmt + 7) !=
'\0') ? atoi(fmt + 8) : 0);
508 const char* sprecision = fmt ? strstr(fmt,
",") : 0;
509 unsigned int scale = (sprecision ? atoi(sprecision + 1) : 0);
517 unsigned int size = fmt ? atoi(fmt + 18) : 0;
556 unsigned int size = (fmt && (*(fmt + 9) !=
'\0') ? atoi(fmt + 10) : 0);
592 bool attNotNull,
const char* fmt,
593 bool attHasDefault,
const char* attDefValue,
594 int ndims,
unsigned int pgisGeomTypeOid,
595 unsigned int pgisRasterTypeOid)
599 attHasDefault, attDefValue,
600 pgisGeomTypeOid, pgisRasterTypeOid);
602 std::string* defaultValue = (attHasDefault ?
new std::string(attDefValue) : 0);
603 std::string name = std::string(attName);
607 for(
int i = 0; i < ndims - 1; ++i)
617 if(arrayElementProperty)
627 if(arrayElementProperty)
637 if(arrayElementProperty)
647 if(arrayElementProperty)
659 if(arrayElementProperty)
671 if(arrayElementProperty)
681 if(arrayElementProperty)
691 if(arrayElementProperty)
701 if(arrayElementProperty)
712 if(arrayElementProperty)
722 if(arrayElementProperty)
732 if(arrayElementProperty)
742 if(arrayElementProperty)
752 if(arrayElementProperty)
762 if(arrayElementProperty)
772 if(arrayElementProperty)
782 if(arrayElementProperty)
790 return Convert2TerraLib(attNum, attName, attType, attNotNull, fmt, attHasDefault, attDefValue, pgisGeomTypeOid, pgisRasterTypeOid);
808 return "ST_Intersects";
811 return "ST_Disjoint";
817 return "ST_Overlaps";
826 return "ST_Contains";
832 return "ST_CoveredBy";
888 unsigned int pgisGeomTypeOid,
889 unsigned int pgisRasterTypeOid,
890 std::vector<int>& teTypes);
902 if(gType & 0xF0000000)
906 gType = (gType & 0x0FFFFFFF) | 0xBB8;
910 gType = (gType & 0x0FFFFFFF) | 0x3E8;
914 gType = (gType & 0x0FFFFFFF) | 0x7D0;
918 gType = (gType & 0x0FFFFFFF);
926 const std::string* defaultSchema,
927 std::string& schemaName,
928 std::string& tableName);
932 if((gType & 0xF00) == 0xB00)
937 else if((gType & 0x0F00) == 0x300)
942 else if((gType & 0xF00) == 0x700)
957 std::string
GetBindableWhereSQL(
const std::vector<te::dt::Property*>& properties,
const std::size_t offset = 0);
983 #endif // __TERRALIB_POSTGIS_INTERNAL_UTILS_H
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
std::string MakeConnectionStr(const std::map< std::string, std::string > &dsInfo)
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...
CharEncoding
Supported charsets (character encoding).
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
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.
const char * GetPGEncoding(te::common::CharEncoding encoding)
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.
#define PG_VARCHAR_ARRAY_TYPE
double m_lly
Lower left corner y-coordinate.
void setElementType(Property *t)
It sets the type of array elements.
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.
te::common::CharEncoding GetTeEncoding(const char *const encoding)
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
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)...