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 = m_ds->getOGRDataSource();
72 std::string sql =
"SELECT FID, * FROM \'" + name +
"\'";
73 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
76 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
94 assert(m_ds->getOGRDataSource());
96 OGRDataSource* ds = m_ds->getOGRDataSource();
99 std::string sql =
"SELECT FID, * FROM \'" + name +
"\'";
100 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
103 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
118 assert(m_ds->getOGRDataSource());
120 OGRDataSource* ds = m_ds->getOGRDataSource();
123 std::string sql =
"SELECT FID, * FROM \'" + name +
"\'";
124 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
127 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
131 layer->SetSpatialFilter(ogrg);
133 OGRGeometryFactory::destroyGeometry(ogrg);
143 assert(m_ds->getOGRDataSource());
145 OGRDataSource* ds = m_ds->getOGRDataSource();
156 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
159 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
174 assert(m_ds->getOGRDataSource());
176 OGRDataSource* ds = m_ds->getOGRDataSource();
179 OGRLayer* layer = ds->ExecuteSQL(query.c_str(), 0, 0);
182 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
189 std::vector<std::string> names;
191 if(!m_ds->getOGRDataSource())
194 for(
int i = 0; i < m_ds->getOGRDataSource()->GetLayerCount(); ++i)
195 names.push_back(m_ds->getOGRDataSource()->GetLayer(i)->GetName());
202 if(!m_ds->getOGRDataSource())
205 return m_ds->getOGRDataSource()->GetLayerCount();
210 assert(m_ds->getOGRDataSource());
212 std::string sql(
"SELECT FID, * FROM \'");
215 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
218 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
223 const char* colIdName = layer->GetFIDColumn();
225 if(colIdName == 0 || colIdName[0] ==
'\0')
228 int pos = layer->GetLayerDefn()->GetFieldIndex(colIdName);
232 pk->
add(type->getProperty(pos));
242 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
249 boost::ptr_vector<te::dt::Property> properties;
251 std::auto_ptr<te::da::DataSetType> type = getDataSetType(datasetName);
253 const std::vector<te::dt::Property*>& props = type->getProperties();
254 for(std::size_t i = 0; i < props.size(); ++i)
255 properties.push_back(props[i]->clone());
262 assert(m_ds->getOGRDataSource());
264 std::string sql(
"SELECT FID, * FROM \'");
265 sql += datasetName +
"\'";
267 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
270 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
272 int propertyPos = layer->GetLayerDefn()->GetFieldIndex(name.c_str());
274 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
276 return getProperty(datasetName, static_cast<std::size_t>(propertyPos));
281 assert(m_ds->getOGRDataSource());
283 std::string sql(
"SELECT FID, * FROM \'");
284 sql += datasetName +
"\'";
286 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
289 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
291 OGRFeatureDefn* def = layer->GetLayerDefn();
292 OGRFieldDefn* fdef = def->GetFieldDefn(propertyPos);
294 std::auto_ptr<te::dt::Property> prop;
298 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
305 assert(m_ds->getOGRDataSource());
307 std::string sql(
"SELECT FID, * FROM \'");
308 sql += datasetName +
"\'";
310 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
313 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
315 std::vector<std::string> propertyNames;
317 OGRFeatureDefn* def = layer->GetLayerDefn();
319 for(
int i = 0; i < def->GetFieldCount(); ++i)
320 propertyNames.push_back(def->GetFieldDefn(i)->GetNameRef());
322 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
324 return propertyNames;
329 return getPropertyNames(datasetName).size();
334 std::vector<std::string> propertyNames = getPropertyNames(datasetName);
336 for(std::size_t i = 0; i < propertyNames.size(); ++i)
337 if(propertyNames[i] == name)
344 const std::string& propertyName)
346 assert(m_ds->getOGRDataSource());
348 std::string sql(
"SELECT ");
349 sql += propertyName +
" FROM \'";
350 sql += datasetName +
"\'";
352 OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
355 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
357 std::auto_ptr<OGREnvelope> ogrEnv(
new OGREnvelope);
359 if(layer->GetExtent(ogrEnv.get()) != OGRERR_NONE)
361 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
362 throw Exception(
TE_TR(
"Error when attempting to get the extent!"));
367 m_ds->getOGRDataSource()->ReleaseResultSet(layer);
375 return getExtent(datasetName,
"OGR_GEOMETRY");
380 assert(m_ds->getOGRDataSource());
382 OGRLayer* layer = m_ds->getOGRDataSource()->GetLayerByName(datasetName.c_str());
385 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
387 return layer->GetFeatureCount();
392 if(!m_ds->getOGRDataSource())
395 return (m_ds->getOGRDataSource()->GetLayerCount() > 0);
400 if(!m_ds->getOGRDataSource())
403 return (m_ds->getOGRDataSource()->GetLayerByName(name.c_str()) != 0);
411 throw Exception(
TE_TR(
"The method begin() is not supported by the WFS driver!"));
416 throw Exception(
TE_TR(
"The method commit() is not supported by the WFS driver!"));
421 throw Exception(
TE_TR(
"The method rollBack() is not supported by the WFS driver!"));
426 throw Exception(
TE_TR(
"The method isInTransaction() is not supported by the WFS driver!"));
431 throw Exception(
TE_TR(
"The method execute() is not supported by the WFS driver!"));
436 throw Exception(
TE_TR(
"The method execute() is not supported by the WFS driver!"));
441 throw Exception(
TE_TR(
"The method getPrepared() is not supported by the WFS driver!"));
446 throw Exception(
TE_TR(
"The method getBatchExecutor() is not supported by the WFS driver!"));
451 throw Exception(
TE_TR(
"The method cancel() is not supported by the WFS driver!"));
456 throw Exception(
TE_TR(
"The method getLastGeneratedId() is not supported by the WFS driver!"));
461 throw Exception(
TE_TR(
"The method escape() is not supported by the WFS driver!"));
466 throw Exception(
TE_TR(
"The method isDataSetNameValid() is not supported by the WFS driver!"));
471 throw Exception(
TE_TR(
"The method isPropertyNameValid() is not supported by the WFS driver!"));
476 throw Exception(
TE_TR(
"The method addProperty() is not supported by the WFS driver!"));
481 throw Exception(
TE_TR(
"The method dropProperty() is not supported by the WFS driver!"));
486 throw Exception(
TE_TR(
"The method renameProperty() is not supported by the WFS driver!"));
491 throw Exception(
TE_TR(
"The method getPrimaryKey() is not supported by the WFS driver!"));
496 throw Exception(
TE_TR(
"The method primaryKeyExists() is not supported by the WFS driver!"));
501 throw Exception(
TE_TR(
"The method addPrimaryKey() is not supported by the WFS driver!"));
506 throw Exception(
TE_TR(
"The method dropPrimaryKey() is not supported by the WFS driver!"));
511 throw Exception(
TE_TR(
"The method getForeignKey() is not supported by the WFS driver!"));
516 throw Exception(
TE_TR(
"The method getForeignKeyNames() is not supported by the WFS driver!"));
521 throw Exception(
TE_TR(
"The method foreignKeyExists() is not supported by the WFS driver!"));
526 throw Exception(
TE_TR(
"The method addForeignKey() is not supported by the WFS driver!"));
531 throw Exception(
TE_TR(
"The method dropForeignKey() is not supported by the WFS driver!"));
536 throw Exception(
TE_TR(
"The method getUniqueKey() is not supported by the WFS driver!"));
541 throw Exception(
TE_TR(
"The method getUniqueKeyNames() is not supported by the WFS driver!"));
546 throw Exception(
TE_TR(
"The method uniqueKeyExists() is not supported by the WFS driver!"));
551 throw Exception(
TE_TR(
"The method addUniqueKey() is not supported by the WFS driver!"));
556 throw Exception(
TE_TR(
"The method dropUniqueKey() is not supported by the WFS driver!"));
561 throw Exception(
TE_TR(
"The method getCheckConstraint() is not supported by the WFS driver!"));
566 throw Exception(
TE_TR(
"The method getCheckConstraintNames() is not supported by the WFS driver!"));
571 throw Exception(
TE_TR(
"The method checkConstraintExists() is not supported by the WFS driver!"));
576 throw Exception(
TE_TR(
"The method addCheckConstraint() is not supported by the WFS driver!"));
581 throw Exception(
TE_TR(
"The method dropCheckConstraint() is not supported by the WFS driver!"));
586 throw Exception(
TE_TR(
"The method getIndex() is not supported by the WFS driver!"));
591 throw Exception(
TE_TR(
"The method getIndexNames() is not supported by the WFS driver!"));
596 throw Exception(
TE_TR(
"The method indexExists() is not supported by the WFS driver!"));
601 throw Exception(
TE_TR(
"The method addIndex() is not supported by the WFS driver!"));
606 throw Exception(
TE_TR(
"The method dropIndex() is not supported by the WFS driver!"));
611 throw Exception(
TE_TR(
"The method getSequence() is not supported by the WFS driver!"));
616 throw Exception(
TE_TR(
"The method getSequenceNames() is not supported by the WFS driver!"));
621 throw Exception(
TE_TR(
"The method sequenceExists() is not supported by the WFS driver!"));
626 throw Exception(
TE_TR(
"The method addSequence() is not supported by the WFS driver!"));
631 throw Exception(
TE_TR(
"The method dropSequence() is not supported by the WFS driver!"));
635 const std::map<std::string, std::string>& )
637 throw Exception(
TE_TR(
"The method createDataSet() is not supported by the WFS driver!"));
642 const std::map<std::string, std::string>& )
644 throw Exception(
TE_TR(
"The method cloneDataSet() is not supported by the WFS driver!"));
649 throw Exception(
TE_TR(
"The method dropDataSet() is not supported by the WFS driver!"));
655 throw Exception(
TE_TR(
"The method renameDataSet() is not supported by the WFS driver!"));
660 const std::map<std::string, std::string>& ,
663 throw Exception(
TE_TR(
"The method add() is not supported by the WFS driver!"));
668 throw Exception(
TE_TR(
"The method remove() is not supported by the WFS driver!"));
673 const std::vector<std::size_t>& ,
675 const std::map<std::string, std::string>& ,
678 throw Exception(
TE_TR(
"The method update() is not supported by the WFS driver!"));
683 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.