27 #include "../common/Translator.h"
28 #include "../dataaccess/utils/Utils.h"
29 #include "../datatype/Property.h"
30 #include "../geometry/Envelope.h"
31 #include "../geometry/Geometry.h"
32 #include "../geometry/GeometryProperty.h"
33 #include "../ogr/DataSet.h"
34 #include "../ogr/SQLVisitor.h"
35 #include "../ogr/Utils.h"
42 #include <ogrsf_frmts.h>
48 : te::da::DataSourceTransactor(),
67 assert(m_ds->getOGRDataSource());
69 OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
71 std::string sql =
"SELECT FID, * FROM \'" + name +
"\'";
72 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
75 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
88 assert(m_ds->getOGRDataSource());
90 OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
92 std::string sql =
"SELECT FID, * FROM \'" + name +
"\'";
93 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
96 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
111 assert(m_ds->getOGRDataSource());
113 OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
115 std::string sql =
"SELECT FID, * FROM \'" + name +
"\'";
116 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
119 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
123 layer->SetSpatialFilter(ogrg);
125 OGRGeometryFactory::destroyGeometry(ogrg);
135 assert(m_ds->getOGRDataSource());
137 OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
147 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
150 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
165 assert(m_ds->getOGRDataSource());
167 OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
169 OGRLayer* layer = ds->ExecuteSQL(query.c_str(), 0, 0);
172 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
179 std::vector<std::string> names;
181 if(!m_ds->getOGRDataSource())
184 for(
int i = 0; i < m_ds->getOGRDataSource()->GetLayerCount(); ++i)
185 names.push_back(m_ds->getOGRDataSource()->GetLayer(i)->GetName());
192 if(!m_ds->getOGRDataSource())
195 return m_ds->getOGRDataSource()->GetLayerCount();
200 assert(m_ds->getOGRDataSource());
202 std::string sql(
"SELECT FID, * FROM \'");
205 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
208 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
213 const char* colIdName = layer->GetFIDColumn();
215 if(colIdName == 0 || colIdName[0] ==
'\0')
218 int pos = layer->GetLayerDefn()->GetFieldIndex(colIdName);
222 pk->
add(type->getProperty(pos));
232 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
239 boost::ptr_vector<te::dt::Property> properties;
241 std::auto_ptr<te::da::DataSetType> type = getDataSetType(datasetName);
243 const std::vector<te::dt::Property*>& props = type->getProperties();
244 for(std::size_t i = 0; i < props.size(); ++i)
245 properties.push_back(props[i]->clone());
252 assert(m_ds->getOGRDataSource());
254 std::string sql(
"SELECT FID, * FROM \'");
255 sql += datasetName +
"\'";
257 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
260 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
262 int propertyPos = layer->GetLayerDefn()->GetFieldIndex(name.c_str());
264 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
266 return getProperty(datasetName, static_cast<std::size_t>(propertyPos));
271 assert(m_ds->getOGRDataSource());
273 std::string sql(
"SELECT FID, * FROM \'");
274 sql += datasetName +
"\'";
276 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
279 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
281 OGRFeatureDefn* def = layer->GetLayerDefn();
282 OGRFieldDefn* fdef = def->GetFieldDefn(propertyPos);
284 std::auto_ptr<te::dt::Property> prop;
288 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
295 assert(m_ds->getOGRDataSource());
297 std::string sql(
"SELECT FID, * FROM \'");
298 sql += datasetName +
"\'";
300 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
303 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
305 std::vector<std::string> propertyNames;
307 OGRFeatureDefn* def = layer->GetLayerDefn();
309 for(
int i = 0; i < def->GetFieldCount(); ++i)
310 propertyNames.push_back(def->GetFieldDefn(i)->GetNameRef());
312 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
314 return propertyNames;
319 return getPropertyNames(datasetName).size();
324 std::vector<std::string> propertyNames = getPropertyNames(datasetName);
326 for(std::size_t i = 0; i < propertyNames.size(); ++i)
327 if(propertyNames[i] == name)
334 const std::string& propertyName)
336 assert(m_ds->getOGRDataSource());
338 std::string sql(
"SELECT ");
339 sql += propertyName +
" FROM \'";
340 sql += datasetName +
"\'";
342 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
345 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
347 std::auto_ptr<OGREnvelope> ogrEnv(
new OGREnvelope);
349 if(layer->GetExtent(ogrEnv.get()) != OGRERR_NONE)
351 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
352 throw Exception(
TE_TR(
"Error when attempting to get the extent!"));
357 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
365 return getExtent(datasetName,
"OGR_GEOMETRY");
370 assert(m_ds->getOGRDataSource());
372 OGRLayer* layer = m_ds->getOGRDataSource()->GetLayerByName(datasetName.c_str());
375 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
377 return layer->GetFeatureCount();
382 if(!m_ds->getOGRDataSource())
385 return (m_ds->getOGRDataSource()->GetLayerCount() > 0);
390 if(!m_ds->getOGRDataSource())
393 return (m_ds->getOGRDataSource()->GetLayerByName(name.c_str()) != 0);
401 throw Exception(
TE_TR(
"The method begin() is not supported by the WFS driver!"));
406 throw Exception(
TE_TR(
"The method commit() is not supported by the WFS driver!"));
411 throw Exception(
TE_TR(
"The method rollBack() is not supported by the WFS driver!"));
416 throw Exception(
TE_TR(
"The method isInTransaction() is not supported by the WFS driver!"));
421 throw Exception(
TE_TR(
"The method execute() is not supported by the WFS driver!"));
426 throw Exception(
TE_TR(
"The method execute() is not supported by the WFS driver!"));
431 throw Exception(
TE_TR(
"The method getPrepared() is not supported by the WFS driver!"));
436 throw Exception(
TE_TR(
"The method getBatchExecutor() is not supported by the WFS driver!"));
441 throw Exception(
TE_TR(
"The method cancel() is not supported by the WFS driver!"));
446 throw Exception(
TE_TR(
"The method getLastGeneratedId() is not supported by the WFS driver!"));
451 throw Exception(
TE_TR(
"The method escape() is not supported by the WFS driver!"));
456 throw Exception(
TE_TR(
"The method isDataSetNameValid() is not supported by the WFS driver!"));
461 throw Exception(
TE_TR(
"The method isPropertyNameValid() is not supported by the WFS driver!"));
466 throw Exception(
TE_TR(
"The method addProperty() is not supported by the WFS driver!"));
471 throw Exception(
TE_TR(
"The method dropProperty() is not supported by the WFS driver!"));
476 throw Exception(
TE_TR(
"The method renameProperty() is not supported by the WFS driver!"));
481 throw Exception(
TE_TR(
"The method getPrimaryKey() is not supported by the WFS driver!"));
486 throw Exception(
TE_TR(
"The method primaryKeyExists() is not supported by the WFS driver!"));
491 throw Exception(
TE_TR(
"The method addPrimaryKey() is not supported by the WFS driver!"));
496 throw Exception(
TE_TR(
"The method dropPrimaryKey() is not supported by the WFS driver!"));
501 throw Exception(
TE_TR(
"The method getForeignKey() is not supported by the WFS driver!"));
506 throw Exception(
TE_TR(
"The method getForeignKeyNames() is not supported by the WFS driver!"));
511 throw Exception(
TE_TR(
"The method foreignKeyExists() is not supported by the WFS driver!"));
516 throw Exception(
TE_TR(
"The method addForeignKey() is not supported by the WFS driver!"));
521 throw Exception(
TE_TR(
"The method dropForeignKey() is not supported by the WFS driver!"));
526 throw Exception(
TE_TR(
"The method getUniqueKey() is not supported by the WFS driver!"));
531 throw Exception(
TE_TR(
"The method getUniqueKeyNames() is not supported by the WFS driver!"));
536 throw Exception(
TE_TR(
"The method uniqueKeyExists() is not supported by the WFS driver!"));
541 throw Exception(
TE_TR(
"The method addUniqueKey() is not supported by the WFS driver!"));
546 throw Exception(
TE_TR(
"The method dropUniqueKey() is not supported by the WFS driver!"));
551 throw Exception(
TE_TR(
"The method getCheckConstraint() is not supported by the WFS driver!"));
556 throw Exception(
TE_TR(
"The method getCheckConstraintNames() is not supported by the WFS driver!"));
561 throw Exception(
TE_TR(
"The method checkConstraintExists() is not supported by the WFS driver!"));
566 throw Exception(
TE_TR(
"The method addCheckConstraint() is not supported by the WFS driver!"));
571 throw Exception(
TE_TR(
"The method dropCheckConstraint() is not supported by the WFS driver!"));
576 throw Exception(
TE_TR(
"The method getIndex() is not supported by the WFS driver!"));
581 throw Exception(
TE_TR(
"The method getIndexNames() is not supported by the WFS driver!"));
586 throw Exception(
TE_TR(
"The method indexExists() is not supported by the WFS driver!"));
591 throw Exception(
TE_TR(
"The method addIndex() is not supported by the WFS driver!"));
596 throw Exception(
TE_TR(
"The method dropIndex() is not supported by the WFS driver!"));
601 throw Exception(
TE_TR(
"The method getSequence() is not supported by the WFS driver!"));
606 throw Exception(
TE_TR(
"The method getSequenceNames() is not supported by the WFS driver!"));
611 throw Exception(
TE_TR(
"The method sequenceExists() is not supported by the WFS driver!"));
616 throw Exception(
TE_TR(
"The method addSequence() is not supported by the WFS driver!"));
621 throw Exception(
TE_TR(
"The method dropSequence() is not supported by the WFS driver!"));
625 const std::map<std::string, std::string>& )
627 throw Exception(
TE_TR(
"The method createDataSet() is not supported by the WFS driver!"));
632 const std::map<std::string, std::string>& )
634 throw Exception(
TE_TR(
"The method cloneDataSet() is not supported by the WFS driver!"));
639 throw Exception(
TE_TR(
"The method dropDataSet() is not supported by the WFS driver!"));
645 throw Exception(
TE_TR(
"The method renameDataSet() is not supported by the WFS driver!"));
650 const std::map<std::string, std::string>& ,
653 throw Exception(
TE_TR(
"The method add() is not supported by the WFS driver!"));
658 throw Exception(
TE_TR(
"The method remove() is not supported by the WFS driver!"));
663 const std::vector<std::size_t>& ,
665 const std::map<std::string, std::string>& ,
668 throw Exception(
TE_TR(
"The method update() is not supported by the WFS driver!"));
673 throw Exception(
TE_TR(
"The method optimize() is not supported by the WFS driver!"));
Implementation of the data source for the WFS driver.
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
Implementation of the transactor for the WFS driver.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Utility functions for the data access module.
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
void createDataSet(te::da::DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
TEOGREXPORT OGRGeometry * Convert2OGR(const te::gm::Geometry *teGeom)
It converts the TerraLib Geometry to OGR Geometry.
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
bool foreignKeyExists(const std::string &datasetName, const std::string &name)
It checks if a foreign key with the given name exists in the data source.
CharEncoding
Supported charsets (character encoding).
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
A class that models the description of a dataset.
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
std::auto_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)
It retrieves the property with the given name from the dataset.
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
std::auto_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name)
It gets the index with the given name from the dataset.
double m_urx
Upper right corner x-coordinate.
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
SpatialRelation
Spatial relations between geometric objects.
It describes a sequence (a number generator).
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
void update(const std::string &datasetName, te::da::DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items.
A class that describes a check constraint.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
#define TE_TR(message)
It marks a string in order to get translated.
TEOGREXPORT std::string RemoveSpatialSql(const std::string &sql)
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
void add(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
It adds data items to the dataset in the data source.
Implementation of a DataSet for OGR data provider.
It models a property definition.
Transactor(DataSource *ds)
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
std::auto_ptr< te::da::CheckConstraint > getCheckConstraint(const std::string &datasetName, const std::string &name)
It gets the check constraint of the dataset with the given name.
void optimize(const std::map< std::string, std::string > &opInfo)
For some data access drivers, this method will perform some operations to optimize the data storage...
Implementation of the data source for the WFS driver.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
double m_llx
Lower left corner x-coordinate.
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
bool hasDataSets()
It checks if the data source has any dataset.
void cancel()
It requests that the data source stop the processing of the current command.
An Envelope defines a 2D rectangular region.
std::auto_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, const std::string &propertyName)
It retrieves the bounding rectangle of the spatial property for the given dataset.
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
TEOGREXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
It models a foreign key constraint for a DataSetType.
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
It describes a unique key (uk) constraint.
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
void cloneDataSet(const std::string &name, const std::string &cloneName, const std::map< std::string, std::string > &options)
It clones the dataset in the data source.
void begin()
NOT SUPPORTED METHODS.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A Select models a query to be used when retrieving data from a DataSource.
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
std::auto_ptr< te::da::DataSet > query(const te::da::Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. A dataset can be connected or di...
double m_lly
Lower left corner y-coordinate.
A dataset is the unit of information manipulated by the data access module of TerraLib.
bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
double m_ury
Upper right corner y-coordinate.
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
It describes a primary key (pk) constraint.
bool checkConstraintExists(const std::string &datasetName, const std::string &name)
It checks if a check-constraint with the given name exists in the data source.
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
void addIndex(const std::string &datasetName, te::da::Index *idx, const std::map< std::string, std::string > &options)
It adds an index to the dataset.
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
std::auto_ptr< te::da::PreparedQuery > getPrepared(const std::string &qName=std::string(""))
It creates a prepared query object that may be used for query commands (select, insert, update and delete) that are used repeatedly.
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
te::common::CharEncoding getEncoding()
It return the DataSource current encoding.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
bool indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
void dropSequence(const std::string &name)
It removes the sequence from the data source.
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
std::auto_ptr< te::da::UniqueKey > getUniqueKey(const std::string &datasetName, const std::string &name)
It gets the unique key in the dataset with the given name.
A Query is independent from the data source language/dialect.
It describes an index associated to a DataSetType.
std::auto_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
An exception class for the TerraLib WFS module.
TEOGREXPORT int Convert2TerraLibProjection(OGRSpatialReference *osrs)
It converts the OGR Projection to TerraLib Projection.
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
void commit()
It commits the transaction.
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
std::auto_ptr< te::da::DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. A dataset can be connected or disconnected. A connected dataset, after its creation through the data source transactor, continues to depend on the connection given by its associated data source. Differently, a disconnected dataset, after its creation, no more depends of the connection given by the data source, and it continues to live after the connection has been released to the data source.
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.