27 #include "../common/Exception.h"
28 #include "../common/Globals.h"
29 #include "../common/Translator.h"
30 #include "../dataaccess/dataset/DataSetType.h"
31 #include "../dataaccess/utils/Utils.h"
32 #include "../datatype/ArrayProperty.h"
33 #include "../datatype/DateTime.h"
34 #include "../datatype/DateTimeProperty.h"
35 #include "../datatype/NumericProperty.h"
36 #include "../datatype/Property.h"
37 #include "../datatype/SimpleProperty.h"
38 #include "../datatype/StringProperty.h"
39 #include "../geometry/Envelope.h"
40 #include "../geometry/Geometry.h"
41 #include "../geometry/GeometryProperty.h"
42 #include "../geometry/WKBReader.h"
43 #include "../srs/Config.h"
47 #include <ogrsf_frmts.h>
48 #include <ogr_spatialref.h>
51 #include <boost/algorithm/string.hpp>
52 #include <boost/filesystem.hpp>
56 int wkbSize = ogrGeom->WkbSize();
58 unsigned char* wkbArray =
new unsigned char[wkbSize];
60 ogrGeom->exportToWkb(wkbNDR, wkbArray);
83 char* wkbArray =
new char[size];
89 OGRGeometry* ogrGeom = 0;
91 OGRErr result = OGRGeometryFactory::createFromWkb((
unsigned char*)wkbArray, srs, &ogrGeom, static_cast<int>(size));
95 if(result == OGRERR_NONE)
98 if(result == OGRERR_NOT_ENOUGH_DATA)
101 if(result == OGRERR_UNSUPPORTED_GEOMETRY_TYPE)
104 if(result == OGRERR_CORRUPT_DATA)
117 OGREnvelope* envOGR =
new OGREnvelope();
118 envOGR->MinX = env->
m_llx;
119 envOGR->MinY = env->
m_lly;
120 envOGR->MaxX = env->
m_urx;
121 envOGR->MaxY = env->
m_ury;
130 if(osrs->AutoIdentifyEPSG() != OGRERR_UNSUPPORTED_SRS)
131 return atoi(osrs->GetAuthorityCode(0));
134 std::string straux(osrs->GetRoot()->GetChild(0)->GetValue());
136 if (!boost::find_first(straux,
"SIRGAS"))
139 if (osrs->IsGeographic())
143 if (boost::find_first(straux,
"UTM "))
145 double centralm = osrs->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,-1);
148 int zone = (int)(centralm/6 + 31);
150 double fsnorth = osrs->GetProjParm(SRS_PP_FALSE_NORTHING,-1);
153 else if (fsnorth == 0)
161 OGRSpatialReference* osrs =
new OGRSpatialReference();
163 OGRErr error = osrs->importFromEPSG(srid);
165 if(error != OGRERR_NONE)
175 int nFields = featDef->GetFieldCount();
177 for(
int i = 0; i < nFields; i++)
179 OGRFieldDefn* fieldDef = featDef->GetFieldDefn(i);
184 OGRwkbGeometryType ogrGeomType = featDef->GetGeomType();
186 if(ogrGeomType != wkbNone)
190 dt->
add(geomPropertyType);
207 OGRFeatureDefn* featDef =
new OGRFeatureDefn(dt->
getName().c_str());
210 for(
unsigned int i = 0; i < props.size(); i++)
229 std::string name = fieldDef->GetNameRef();
230 switch(fieldDef->GetType())
244 if(fieldDef->GetWidth() == 0)
292 OGRFieldDefn* fieldDef =
new OGRFieldDefn(p->
getName().c_str(), OFTInteger);
305 fieldDef->SetType(OFTIntegerList);
307 fieldDef->SetType(OFTStringList);
309 fieldDef->SetType(OFTRealList);
316 fieldDef->SetType(OFTString);
317 fieldDef->SetWidth(static_cast<int>(static_cast<te::dt::StringProperty*>(p)->size()));
321 fieldDef->SetType(OFTReal);
325 fieldDef->SetType(OFTReal);
326 fieldDef->SetPrecision(static_cast<te::dt::NumericProperty*>(p)->getScale());
330 fieldDef->SetType(OFTBinary);
338 fieldDef->SetType(OFTDate);
340 fieldDef->SetType(OFTTime);
342 fieldDef->SetType(OFTDateTime);
371 case wkbMultiLineString:
374 case wkbMultiPolygon:
377 case wkbGeometryCollection:
386 case wkbLineString25D:
392 case wkbMultiPoint25D:
395 case wkbMultiLineString25D:
398 case wkbMultiPolygon25D:
401 case wkbGeometryCollection25D:
423 return wkbLineString;
429 return wkbMultiPoint;
432 return wkbMultiLineString;
435 return wkbMultiPolygon;
438 return wkbGeometryCollection;
444 return wkbLineString25D;
447 return wkbPolygon25D;
450 return wkbMultiPoint25D;
453 return wkbMultiLineString25D;
456 return wkbMultiPolygon25D;
459 return wkbGeometryCollection25D;
468 boost::filesystem::path mpath(path.c_str());
470 std::string ext = mpath.extension().string();
472 if(ext ==
".shp" || ext ==
".SHP")
473 return std::string(
"ESRI Shapefile");
475 if(ext ==
".mif" || ext ==
".MIF")
476 return std::string(
"Mapinfo File");
478 if(ext ==
".kml" || ext ==
".KML")
479 return std::string(
"KML");
481 if(ext ==
".geojson" || ext ==
".GEOJSON")
482 return std::string(
"GeoJSON");
484 if(ext ==
".gml" || ext ==
".GML")
485 return std::string(
"GML");
487 if(ext ==
".dxf" || ext ==
".DXF")
488 return std::string(
"DXF");
490 if(ext ==
".dgn" || ext ==
".DGN")
491 return std::string(
"DGN");
499 std::vector<std::string> drivernames;
501 int ndrivers = OGRSFDriverRegistrar::GetRegistrar()->GetDriverCount();
503 for (
int i = 0; i < ndrivers; ++i)
505 OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriver(i);
506 if (filterCreate && !driver->TestCapability(ODrCCreateDataSource))
508 drivernames.push_back(driver->GetName());
516 std::map<std::string, std::string>::const_iterator it = connInfo.find(
"URI");
518 if(it != connInfo.end())
521 it = connInfo.find(
"SOURCE");
523 if(it != connInfo.end())
532 std::size_t pos = sql.find(
"AND Intersection");
535 if(pos == std::string::npos)
536 pos = sql.find(
"WHERE Intersection");
538 if(pos == std::string::npos)
541 std::string newQuery;
543 std::size_t pos2 = sql.find(
"))", pos);
544 newQuery = sql.substr(0, pos);
545 newQuery += sql.substr(pos2 + 2);
void setTitle(const std::string &title)
It sets a human descriptive title for the DataSetType.
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Utility functions for the data access module.
TEOGREXPORT OGRGeometry * Convert2OGR(const te::gm::Geometry *teGeom)
It converts the TerraLib Geometry to OGR Geometry.
An atomic property like an integer or double.
bool hasGeom() const
It returns true if the DataSetType has at least one geometry property; otherwise, it returns false...
void getWkb(char *wkb, te::common::MachineByteOrder byteOrder) const
It serializes the geometry to a WKB representation into the specified buffer.
A class that models the description of a dataset.
double m_urx
Upper right corner x-coordinate.
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
#define TE_TR(message)
It marks a string in order to get translated.
TEOGREXPORT std::string RemoveSpatialSql(const std::string &sql)
std::size_t getWkbSize() const
It returns the size required by a WKB representation for this geometric object.
TEOGREXPORT std::vector< std::string > GetOGRDrivers(bool filterCreate=false)
It returns the list of OGR Drivers available.
It models a property definition.
std::string GetDriverName(const std::string &path)
It tries extract the driver name used by OGR Library based on the given path.
double m_llx
Lower left corner x-coordinate.
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
An Envelope defines a 2D rectangular region.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
TEOGREXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
double m_lly
Lower left corner y-coordinate.
TEOGREXPORT std::string GetOGRConnectionInfo(const std::map< std::string, std::string > &connInfo)
int getType() const
It returns the property data type.
void add(Constraint *c)
It adds a new constraint.
Property * getElementType() const
It returns the type of array elements.
The type for variable-length multidimensional arrays.
double m_ury
Upper right corner y-coordinate.
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.
void setCharEncoding(const te::common::CharEncoding &ce)
It sets the string property character encoding.
#define TE_SRS_SIRGAS2000
DateTimeType
The subtype of date and time type.
DateTimeType getSubType() const
It returns the date time property sub type.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEOGREXPORT OGRSpatialReference * Convert2OGRProjection(int srid)
It converts the TerraLib Projection to OGR Projection.
TEOGREXPORT int Convert2TerraLibProjection(OGRSpatialReference *osrs)
It converts the OGR Projection to TerraLib Projection.
static Geometry * read(const char *wkb)
It returns a valid geometry from a given WKB.
const std::string & getName() const
It returns the property name.