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/SpatialReferenceSystemManager.h"
44 #include "../srs/Config.h"
48 #include <ogrsf_frmts.h>
49 #include <ogr_spatialref.h>
52 #include <boost/algorithm/string.hpp>
53 #include <boost/filesystem.hpp>
57 int wkbSize = ogrGeom->WkbSize();
59 unsigned char* wkbArray =
new unsigned char[wkbSize];
61 ogrGeom->exportToWkb(wkbNDR, wkbArray);
84 char* wkbArray =
new char[size];
90 OGRGeometry* ogrGeom = 0;
92 OGRErr result = OGRGeometryFactory::createFromWkb((
unsigned char*)wkbArray, srs, &ogrGeom, static_cast<int>(size));
96 if(result == OGRERR_NONE)
99 if(result == OGRERR_NOT_ENOUGH_DATA)
102 if(result == OGRERR_UNSUPPORTED_GEOMETRY_TYPE)
105 if(result == OGRERR_CORRUPT_DATA)
118 OGREnvelope* envOGR =
new OGREnvelope();
119 envOGR->MinX = env->
m_llx;
120 envOGR->MinY = env->
m_lly;
121 envOGR->MaxX = env->
m_urx;
122 envOGR->MaxY = env->
m_ury;
133 OGRErr ogrReturn = osrs->AutoIdentifyEPSG();
134 if( ogrReturn == OGRERR_NONE )
136 const char* srsAuth = osrs->GetAuthorityCode(0);
140 srid = atoi(srsAuth);
147 ogrReturn = osrs->exportToWkt( &wktPtr );
149 if( ogrReturn == OGRERR_NONE )
151 std::pair< std::string, unsigned int > customSRID;
152 std::string projRefStr( wktPtr );
160 srid = (int)customSRID.second;
170 char* proj4StrPtr = 0;
171 ogrReturn = osrs->exportToProj4( &proj4StrPtr );
173 if( ogrReturn == OGRERR_NONE )
175 std::pair< std::string, unsigned int > customSRID;
176 std::string projRefStr( proj4StrPtr );
178 OGRFree( proj4StrPtr );
184 srid = (int)customSRID.second;
195 std::string straux(osrs->GetRoot()->GetChild(0)->GetValue());
197 if (boost::find_first(straux,
"SIRGAS"))
199 if (osrs->IsGeographic())
202 else if (boost::find_first(straux,
"UTM "))
204 double centralm = osrs->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,-1);
207 int zone = (int)(centralm/6 + 31);
209 double fsnorth = osrs->GetProjParm(SRS_PP_FALSE_NORTHING,-1);
212 else if (fsnorth == 0)
223 std::auto_ptr< OGRSpatialReference > osrs(
new OGRSpatialReference() );
225 OGRErr error = osrs->importFromEPSG(srid);
227 if( error != OGRERR_NONE )
234 if( !wktStr.empty() )
236 char* wktStrPtr = (
char*)wktStr.c_str();
237 error = osrs->importFromWkt( &wktStrPtr );
242 error = OGRERR_UNSUPPORTED_SRS;
246 if( error != OGRERR_NONE )
250 std::string proj4Str =
253 if( !proj4Str.empty() )
255 char* proj4StrPtr = (
char*)proj4Str.c_str();
256 error = osrs->importFromProj4( proj4StrPtr );
261 error = OGRERR_UNSUPPORTED_SRS;
265 if(error != OGRERR_NONE)
268 return osrs.release();
275 int nFields = featDef->GetFieldCount();
277 for(
int i = 0; i < nFields; i++)
279 OGRFieldDefn* fieldDef = featDef->GetFieldDefn(i);
284 OGRwkbGeometryType ogrGeomType = featDef->GetGeomType();
286 if(ogrGeomType != wkbNone)
290 dt->
add(geomPropertyType);
307 OGRFeatureDefn* featDef =
new OGRFeatureDefn(dt->
getName().c_str());
310 for(
unsigned int i = 0; i < props.size(); i++)
329 std::string name = fieldDef->GetNameRef();
330 switch(fieldDef->GetType())
344 if(fieldDef->GetWidth() == 0)
400 OGRFieldDefn* fieldDef =
new OGRFieldDefn(p->
getName().c_str(), OFTInteger);
413 fieldDef->SetType(OFTIntegerList);
415 fieldDef->SetType(OFTStringList);
417 fieldDef->SetType(OFTRealList);
424 fieldDef->SetType(OFTString);
425 fieldDef->SetWidth(static_cast<int>(static_cast<te::dt::StringProperty*>(p)->size()));
429 fieldDef->SetType(OFTReal);
433 fieldDef->SetType(OFTReal);
434 fieldDef->SetPrecision(static_cast<te::dt::NumericProperty*>(p)->getScale());
438 fieldDef->SetType(OFTBinary);
446 fieldDef->SetType(OFTDate);
448 fieldDef->SetType(OFTTime);
450 fieldDef->SetType(OFTDateTime);
479 case wkbMultiLineString:
482 case wkbMultiPolygon:
485 case wkbGeometryCollection:
494 case wkbLineString25D:
500 case wkbMultiPoint25D:
503 case wkbMultiLineString25D:
506 case wkbMultiPolygon25D:
509 case wkbGeometryCollection25D:
531 return wkbLineString;
537 return wkbMultiPoint;
540 return wkbMultiLineString;
543 return wkbMultiPolygon;
546 return wkbGeometryCollection;
552 return wkbLineString25D;
555 return wkbPolygon25D;
558 return wkbMultiPoint25D;
561 return wkbMultiLineString25D;
564 return wkbMultiPolygon25D;
567 return wkbGeometryCollection25D;
576 boost::filesystem::path mpath(path.c_str());
578 std::string ext = mpath.extension().string();
580 if(ext ==
".shp" || ext ==
".SHP")
581 return std::string(
"ESRI Shapefile");
583 if(ext ==
".mif" || ext ==
".MIF")
584 return std::string(
"Mapinfo File");
586 if(ext ==
".kml" || ext ==
".KML")
587 return std::string(
"KML");
589 if(ext ==
".geojson" || ext ==
".GEOJSON")
590 return std::string(
"GeoJSON");
592 if(ext ==
".gml" || ext ==
".GML")
593 return std::string(
"GML");
595 if(ext ==
".dxf" || ext ==
".DXF")
596 return std::string(
"DXF");
598 if(ext ==
".dgn" || ext ==
".DGN")
599 return std::string(
"DGN");
607 std::vector<std::string> drivernames;
609 int ndrivers = OGRSFDriverRegistrar::GetRegistrar()->GetDriverCount();
611 for (
int i = 0; i < ndrivers; ++i)
613 OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriver(i);
614 if (filterCreate && !driver->TestCapability(ODrCCreateDataSource))
616 drivernames.push_back(driver->GetName());
624 std::map<std::string, std::string>::const_iterator it = connInfo.find(
"URI");
626 if(it != connInfo.end())
629 it = connInfo.find(
"SOURCE");
631 if(it != connInfo.end())
640 std::size_t pos = sql.find(
"AND Intersection");
643 if(pos == std::string::npos)
644 pos = sql.find(
"WHERE Intersection");
646 if(pos == std::string::npos)
649 std::string newQuery;
651 std::size_t pos2 = sql.find(
"))", pos);
652 newQuery = sql.substr(0, pos);
653 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.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
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, based on ISO 8621.
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.