27 #include "../core/translator/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> 66 GDALDataset*
ds = (GDALDataset*)GDALOpenEx(
m_ds->
getOGRDataSource()->GetDescription(), GDAL_OF_READONLY,
nullptr,
nullptr,
nullptr);
68 std::string sql =
"SELECT FID, * FROM \"" + name +
"\"";
69 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(),
nullptr,
nullptr);
72 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
83 const std::string& name,
const std::string& ,
91 GDALDataset*
ds = (GDALDataset*)GDALOpenEx(
m_ds->
getOGRDataSource()->GetDescription(), GDAL_OF_READONLY,
nullptr,
nullptr,
nullptr);
93 std::string sql =
"SELECT FID, * FROM \"" + name +
"\"";
94 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(),
nullptr,
nullptr);
97 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
115 GDALDataset*
ds = (GDALDataset*)GDALOpenEx(
m_ds->
getOGRDataSource()->GetDescription(), GDAL_OF_READONLY,
nullptr,
nullptr,
nullptr);
117 std::string sql =
"SELECT FID, * FROM \"" + name +
"\"";
118 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(),
nullptr,
nullptr);
121 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
125 layer->SetSpatialFilter(ogrg);
127 OGRGeometryFactory::destroyGeometry(ogrg);
140 GDALDataset*
ds = (GDALDataset*)GDALOpenEx(
m_ds->
getOGRDataSource()->GetDescription(), GDAL_OF_READONLY,
nullptr,
nullptr,
nullptr);
150 OGRLayer* layer = ds->ExecuteSQL(sql.c_str(),
nullptr,
nullptr);
153 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
171 GDALDataset*
ds = (GDALDataset*)GDALOpenEx(
m_ds->
getOGRDataSource()->GetDescription(), GDAL_OF_READONLY,
nullptr,
nullptr,
nullptr);
173 OGRLayer* layer = ds->ExecuteSQL(query.c_str(),
nullptr,
nullptr);
176 throw Exception(
TE_TR(
"The informed data set could not be found in the data source!"));
183 std::vector<std::string> names;
206 std::string sql(
"SELECT FID, * FROM \"");
212 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
217 const char* colIdName = layer->GetFIDColumn();
219 if(colIdName ==
nullptr || colIdName[0] ==
'\0')
222 int pos = layer->GetLayerDefn()->GetFieldIndex(colIdName);
226 pk->
add(type->getProperty(pos));
243 boost::ptr_vector<te::dt::Property> properties;
245 std::unique_ptr<te::da::DataSetType> type =
getDataSetType(datasetName);
247 const std::vector<te::dt::Property*>& props = type->getProperties();
248 for(std::size_t i = 0; i < props.size(); ++i)
249 properties.push_back(props[i]->clone());
258 std::string sql(
"SELECT FID, * FROM \"");
259 sql += datasetName +
"\"";
264 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
266 int propertyPos = layer->GetLayerDefn()->GetFieldIndex(name.c_str());
270 return getProperty(datasetName, static_cast<std::size_t>(propertyPos));
277 std::string sql(
"SELECT FID, * FROM \"");
278 sql += datasetName +
"\"";
283 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
285 OGRFeatureDefn* def = layer->GetLayerDefn();
286 OGRFieldDefn* fdef = def->GetFieldDefn(static_cast<int>(propertyPos));
288 std::unique_ptr<te::dt::Property> prop;
301 std::string sql(
"SELECT FID, * FROM \"");
302 sql += datasetName +
"\"";
307 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
309 std::vector<std::string> propertyNames;
311 OGRFeatureDefn* def = layer->GetLayerDefn();
313 for(
int i = 0; i < def->GetFieldCount(); ++i)
314 propertyNames.push_back(def->GetFieldDefn(i)->GetNameRef());
318 return propertyNames;
330 for(std::size_t i = 0; i < propertyNames.size(); ++i)
331 if(propertyNames[i] == name)
338 const std::string& propertyName)
342 std::string sql(
"SELECT ");
343 sql += propertyName +
" FROM \"";
344 sql += datasetName +
"\"";
349 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
351 std::unique_ptr<OGREnvelope> ogrEnv(
new OGREnvelope);
353 if(layer->GetExtent(ogrEnv.get()) != OGRERR_NONE)
356 throw Exception(
TE_TR(
"Error when attempting to get the extent!"));
369 return getExtent(datasetName,
"OGR_GEOMETRY");
379 throw Exception(
TE_TR(
"Could not retrieve the informed data set!"));
381 return layer->GetFeatureCount();
405 throw Exception(
TE_TR(
"The method begin() is not supported by the WFS driver!"));
410 throw Exception(
TE_TR(
"The method commit() is not supported by the WFS driver!"));
415 throw Exception(
TE_TR(
"The method rollBack() is not supported by the WFS driver!"));
420 throw Exception(
TE_TR(
"The method isInTransaction() is not supported by the WFS driver!"));
425 throw Exception(
TE_TR(
"The method execute() is not supported by the WFS driver!"));
430 throw Exception(
TE_TR(
"The method execute() is not supported by the WFS driver!"));
435 throw Exception(
TE_TR(
"The method getPrepared() is not supported by the WFS driver!"));
440 throw Exception(
TE_TR(
"The method getBatchExecutor() is not supported by the WFS driver!"));
445 throw Exception(
TE_TR(
"The method cancel() is not supported by the WFS driver!"));
450 throw Exception(
TE_TR(
"The method getLastGeneratedId() is not supported by the WFS driver!"));
455 throw Exception(
TE_TR(
"The method escape() is not supported by the WFS driver!"));
460 throw Exception(
TE_TR(
"The method isDataSetNameValid() is not supported by the WFS driver!"));
465 throw Exception(
TE_TR(
"The method isPropertyNameValid() is not supported by the WFS driver!"));
470 throw Exception(
TE_TR(
"The method addProperty() is not supported by the WFS driver!"));
475 throw Exception(
TE_TR(
"The method dropProperty() is not supported by the WFS driver!"));
480 throw Exception(
TE_TR(
"The method renameProperty() is not supported by the WFS driver!"));
485 throw Exception(
TE_TR(
"The method getPrimaryKey() is not supported by the WFS driver!"));
490 throw Exception(
TE_TR(
"The method primaryKeyExists() is not supported by the WFS driver!"));
495 throw Exception(
TE_TR(
"The method addPrimaryKey() is not supported by the WFS driver!"));
500 throw Exception(
TE_TR(
"The method dropPrimaryKey() is not supported by the WFS driver!"));
505 throw Exception(
TE_TR(
"The method getForeignKey() is not supported by the WFS driver!"));
510 throw Exception(
TE_TR(
"The method getForeignKeyNames() is not supported by the WFS driver!"));
515 throw Exception(
TE_TR(
"The method foreignKeyExists() is not supported by the WFS driver!"));
520 throw Exception(
TE_TR(
"The method addForeignKey() is not supported by the WFS driver!"));
525 throw Exception(
TE_TR(
"The method dropForeignKey() is not supported by the WFS driver!"));
530 throw Exception(
TE_TR(
"The method getUniqueKey() is not supported by the WFS driver!"));
535 throw Exception(
TE_TR(
"The method getUniqueKeyNames() is not supported by the WFS driver!"));
540 throw Exception(
TE_TR(
"The method uniqueKeyExists() is not supported by the WFS driver!"));
545 throw Exception(
TE_TR(
"The method addUniqueKey() is not supported by the WFS driver!"));
550 throw Exception(
TE_TR(
"The method dropUniqueKey() is not supported by the WFS driver!"));
555 throw Exception(
TE_TR(
"The method getCheckConstraint() is not supported by the WFS driver!"));
560 throw Exception(
TE_TR(
"The method getCheckConstraintNames() is not supported by the WFS driver!"));
565 throw Exception(
TE_TR(
"The method checkConstraintExists() is not supported by the WFS driver!"));
570 throw Exception(
TE_TR(
"The method addCheckConstraint() is not supported by the WFS driver!"));
575 throw Exception(
TE_TR(
"The method dropCheckConstraint() is not supported by the WFS driver!"));
580 throw Exception(
TE_TR(
"The method getIndex() is not supported by the WFS driver!"));
585 throw Exception(
TE_TR(
"The method getIndexNames() is not supported by the WFS driver!"));
590 throw Exception(
TE_TR(
"The method indexExists() is not supported by the WFS driver!"));
595 throw Exception(
TE_TR(
"The method addIndex() is not supported by the WFS driver!"));
600 throw Exception(
TE_TR(
"The method dropIndex() is not supported by the WFS driver!"));
605 throw Exception(
TE_TR(
"The method getSequence() is not supported by the WFS driver!"));
610 throw Exception(
TE_TR(
"The method getSequenceNames() is not supported by the WFS driver!"));
615 throw Exception(
TE_TR(
"The method sequenceExists() is not supported by the WFS driver!"));
620 throw Exception(
TE_TR(
"The method addSequence() is not supported by the WFS driver!"));
625 throw Exception(
TE_TR(
"The method dropSequence() is not supported by the WFS driver!"));
629 const std::map<std::string, std::string>& )
631 throw Exception(
TE_TR(
"The method createDataSet() is not supported by the WFS driver!"));
636 const std::map<std::string, std::string>& )
638 throw Exception(
TE_TR(
"The method cloneDataSet() is not supported by the WFS driver!"));
643 throw Exception(
TE_TR(
"The method dropDataSet() is not supported by the WFS driver!"));
649 throw Exception(
TE_TR(
"The method renameDataSet() is not supported by the WFS driver!"));
654 const std::map<std::string, std::string>& ,
658 throw Exception(
TE_TR(
"The method add() is not supported by the WFS driver!"));
663 throw Exception(
TE_TR(
"The method remove() is not supported by the WFS driver!"));
668 const std::vector<std::size_t>& ,
670 const std::map<std::string, std::string>& ,
673 throw Exception(
TE_TR(
"The method update() is not supported by the WFS driver!"));
678 throw Exception(
TE_TR(
"The method optimize() is not supported by the WFS driver!"));
std::unique_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.
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
void add(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0, bool enableProgress=true)
It adds data items to the dataset in the data source.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
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.
std::unique_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name)
It gets the index with the given name from the dataset.
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.
Implementation of the data source for the WFS driver.
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
Base exception class for plugin module.
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.
An exception class for the TerraLib WFS module.
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.
GDALDataset * getOGRDataSource()
std::unique_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::unique_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.
std::unique_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)
It retrieves the property 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).
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
static te::dt::Date ds(2010, 01, 01)
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.
It models a property definition.
Transactor(DataSource *ds)
std::unique_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
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.
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.
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.
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::unique_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.
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of 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::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about 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.
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.
Utility functions for the data access module.
std::unique_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
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.
double m_lly
Lower left corner y-coordinate.
std::unique_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...
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.
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.
std::unique_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
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::string escape(const std::string &value)
It escapes a string for using in commands and queries.
Implementation of the transactor for the WFS driver.
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::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.
A Query is independent from the data source language/dialect.
It describes an index associated to a DataSetType.
std::unique_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::unique_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
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::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.