27 #include "../common/Exception.h" 28 #include "../common/Globals.h" 29 #include "../core/translator/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" 46 #include "../core/logger/Logger.h" 49 #include <ogrsf_frmts.h> 50 #include <ogr_spatialref.h> 53 #include <boost/algorithm/string.hpp> 54 #include <boost/filesystem.hpp> 58 int wkbSize = ogrGeom->WkbSize();
60 unsigned char* wkbArray =
new unsigned char[wkbSize];
62 ogrGeom->exportToWkb(wkbNDR, wkbArray);
87 OGRSpatialReference::DestroySpatialReference(srs);
96 char* wkbArray =
new char[size];
100 OGRGeometry* ogrGeom =
nullptr;
102 OGRSpatialReference *srs_aux = srs->Clone();
103 OGRErr result = OGRGeometryFactory::createFromWkb((
unsigned char*)wkbArray, srs_aux, &ogrGeom, static_cast<int>(size));
108 if (result == OGRERR_NONE)
111 if (result == OGRERR_NOT_ENOUGH_DATA)
114 if (result == OGRERR_UNSUPPORTED_GEOMETRY_TYPE)
117 if (result == OGRERR_CORRUPT_DATA)
130 OGREnvelope* envOGR =
new OGREnvelope();
131 envOGR->MinX = env->
m_llx;
132 envOGR->MinY = env->
m_lly;
133 envOGR->MaxX = env->
m_urx;
134 envOGR->MaxY = env->
m_ury;
145 OGRErr ogrReturn = osrs->AutoIdentifyEPSG();
146 if( ogrReturn == OGRERR_NONE )
148 const char* srsAuth = osrs->GetAuthorityCode(
nullptr);
152 srid = atoi(srsAuth);
159 char* proj4StrPtr =
nullptr;
160 ogrReturn = osrs->exportToProj4( &proj4StrPtr );
162 if( ogrReturn == OGRERR_NONE )
164 std::pair< std::string, unsigned int > customSRID;
165 proj4 = std::string ( proj4StrPtr );
167 OGRFree( proj4StrPtr );
173 srid = (
int)customSRID.second;
184 char* wktPtr =
nullptr;
185 ogrReturn = osrs->exportToWkt( &wktPtr );
187 if( ogrReturn == OGRERR_NONE )
189 std::pair< std::string, unsigned int > customSRID;
190 wkt = std::string( wktPtr );
198 srid = (
int)customSRID.second;
209 std::string straux(osrs->GetRoot()->GetChild(0)->GetValue());
211 if (boost::find_first(straux,
"SIRGAS"))
213 if (osrs->IsGeographic())
216 else if (boost::find_first(straux,
"UTM "))
218 double centralm = osrs->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,-1);
221 int zone = (
int)(centralm/6 + 31);
223 double fsnorth = osrs->GetProjParm(SRS_PP_FALSE_NORTHING,-1);
226 else if (fsnorth == 0)
236 if (wkt.empty() ==
false && proj4.empty() ==
false)
239 srid = boost::lexical_cast<
int>(strNewSRID);
240 std::string newName =
"USER:" + strNewSRID;
250 std::unique_ptr< OGRSpatialReference > osrs(
new OGRSpatialReference() );
252 OGRErr error = osrs->importFromEPSG(srid);
254 if( error != OGRERR_NONE )
258 std::string proj4Str =
261 if( !proj4Str.empty() )
263 char* proj4StrPtr = (
char*)proj4Str.c_str();
264 error = osrs->importFromProj4( proj4StrPtr );
269 error = OGRERR_UNSUPPORTED_SRS;
273 if( error != OGRERR_NONE )
280 if( !wktStr.empty() )
282 char* wktStrPtr = (
char*)wktStr.c_str();
283 error = osrs->importFromWkt( &wktStrPtr );
288 error = OGRERR_UNSUPPORTED_SRS;
292 if(error != OGRERR_NONE)
295 return osrs.release();
302 int nFields = featDef->GetFieldCount();
304 for(
int i = 0; i < nFields; i++)
306 OGRFieldDefn* fieldDef = featDef->GetFieldDefn(i);
311 OGRwkbGeometryType ogrGeomType = featDef->GetGeomType();
313 if(ogrGeomType != wkbNone)
317 dt->
add(geomPropertyType);
334 OGRFeatureDefn* featDef =
new OGRFeatureDefn(dt->
getName().c_str());
337 for(
unsigned int i = 0; i < props.size(); i++)
356 std::string name = fieldDef->GetNameRef();
357 switch(fieldDef->GetType())
375 if(fieldDef->GetWidth() == 0)
421 OGRFieldDefn* fieldDef =
new OGRFieldDefn(p->
getName().c_str(), OFTInteger);
430 fieldDef->SetType(OFTInteger64);
441 fieldDef->SetType(OFTIntegerList);
443 fieldDef->SetType(OFTStringList);
445 fieldDef->SetType(OFTRealList);
452 fieldDef->SetType(OFTString);
453 fieldDef->SetWidth(static_cast<int>(static_cast<te::dt::StringProperty*>(p)->size()));
457 fieldDef->SetType(OFTReal);
461 fieldDef->SetType(OFTReal);
462 fieldDef->SetPrecision(static_cast<te::dt::NumericProperty*>(p)->getScale());
466 fieldDef->SetType(OFTBinary);
474 fieldDef->SetType(OFTDate);
476 fieldDef->SetType(OFTTime);
478 fieldDef->SetType(OFTDateTime);
513 case wkbMultiPointZM:
516 case wkbMultiPoint25D:
529 case wkbLineStringZM:
532 case wkbLineString25D:
535 case wkbMultiLineString:
538 case wkbMultiLineStringM:
541 case wkbMultiLineStringZM:
544 case wkbMultiLineString25D:
560 case wkbMultiPolygon:
563 case wkbMultiPolygonM:
566 case wkbMultiPolygonZM:
569 case wkbMultiPolygon25D:
573 case wkbGeometryCollection:
576 case wkbGeometryCollectionM:
579 case wkbGeometryCollectionZM:
582 case wkbGeometryCollection25D:
586 case wkbMultiSurface:
589 case wkbMultiSurfaceM:
592 case wkbMultiSurfaceZM:
595 case wkbMultiSurfaceZ:
599 case wkbPolyhedralSurface:
602 case wkbPolyhedralSurfaceM:
605 case wkbPolyhedralSurfaceZM:
608 case wkbPolyhedralSurfaceZ:
666 return wkbLineString;
669 return wkbLineString25D;
672 return wkbLineStringM;
675 return wkbLineStringZM;
682 return wkbPolygon25D;
692 return wkbMultiPoint;
695 return wkbMultiPoint25D;
698 return wkbMultiPointM;
701 return wkbMultiPointZM;
705 return wkbMultiLineString;
708 return wkbMultiLineString25D;
711 return wkbMultiLineStringM;
714 return wkbMultiLineStringZM;
718 return wkbMultiPolygon;
721 return wkbMultiPolygon25D;
724 return wkbMultiPolygonM;
727 return wkbMultiPolygonZM;
731 return wkbGeometryCollection;
734 return wkbGeometryCollection25D;
737 return wkbGeometryCollectionM;
740 return wkbGeometryCollectionZM;
744 return wkbMultiSurface;
747 return wkbMultiSurfaceM;
750 return wkbMultiSurfaceZM;
753 return wkbMultiSurfaceZ;
757 return wkbPolyhedralSurface;
760 return wkbPolyhedralSurfaceZ;
763 return wkbPolyhedralSurfaceM;
766 return wkbPolyhedralSurfaceZM;
789 return wkbTriangleZM;
801 boost::filesystem::path mpath(path.c_str());
803 std::string ext = mpath.extension().string();
805 if(ext ==
".shp" || ext ==
".SHP")
806 return std::string(
"ESRI Shapefile");
808 if(ext ==
".mif" || ext ==
".MIF")
809 return std::string(
"Mapinfo File");
811 if(ext ==
".kml" || ext ==
".KML")
812 return std::string(
"KML");
814 if(ext ==
".geojson" || ext ==
".GEOJSON")
815 return std::string(
"GeoJSON");
817 if(ext ==
".gml" || ext ==
".GML")
818 return std::string(
"GML");
820 if(ext ==
".dxf" || ext ==
".DXF")
821 return std::string(
"DXF");
823 if(ext ==
".dgn" || ext ==
".DGN")
824 return std::string(
"DGN");
826 if (ext ==
".csv" || ext ==
".CSV")
827 return std::string(
"CSV");
834 std::vector<std::string> drivernames;
836 int ndrivers = GetGDALDriverManager()->GetDriverCount();
838 for (
int i = 0; i < ndrivers; ++i)
840 GDALDriver* driver = GetGDALDriverManager()->GetDriver(i);
841 if (filterCreate && !OGR_Dr_TestCapability(driver, ODrCCreateDataSource))
843 drivernames.push_back(driver->GetDescription());
851 std::map<std::string, std::string>::const_iterator it = connInfo.find(
"URI");
853 if(it != connInfo.end())
856 it = connInfo.find(
"SOURCE");
858 if(it != connInfo.end())
867 std::size_t pos = sql.find(
"AND Intersection");
870 if(pos == std::string::npos)
871 pos = sql.find(
"WHERE Intersection");
873 if(pos == std::string::npos)
876 std::string newQuery;
878 std::size_t pos2 = sql.find(
"))", pos);
879 newQuery = sql.substr(0, pos);
880 newQuery += sql.substr(pos2 + 2);
887 static boost::mutex getStaticMutexStaticMutex;
888 return getStaticMutexStaticMutex;
void setTitle(const std::string &title)
It sets a human descriptive title for the DataSetType.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
TEOGREXPORT OGRGeometry * Convert2OGR(const te::gm::Geometry *teGeom)
It converts the TerraLib Geometry to OGR Geometry.
An atomic property like an integer or double.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
bool hasGeom() const
It returns true if the DataSetType has at least one geometry property; otherwise, it returns false...
A class that models the description of a dataset.
TEOGREXPORT boost::mutex & getStaticMutex()
Returns a reference to a static mutex initialized when this module is initialized.
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 _NOEXCEPT_OP(true)
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.
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
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.
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.
static te::dt::TimeDuration dt(20, 30, 50, 11)
The type for string types: FIXED_STRING, VAR_STRING or STRING.
Utility functions for the data access module.
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.
#define TE_SRS_SIRGAS2000
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.
void OGRErrorHandler(CPLErr eErrClass, int errNo, const char *msg)
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 TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
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)
te::da::DataSetType * Convert2TerraLib(sqlite3_stmt *pStmt)
#define TEOGREXPORT
You can use this macro in order to export/import classes and functions from this module.
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.
void getWkb(char *wkb, te::common::MachineByteOrder byteOrder) const _NOEXCEPT_OP(false)
It serializes the geometry to a WKB representation into the specified buffer.
const std::string & getName() const
It returns the property name.