24 #include "../common/Translator.h"
25 #include "../dataaccess/query/SQLDialect.h"
28 #include <ogrsf_frmts.h>
32 #include <boost/filesystem/operations.hpp>
76 if(!ds || ds->GetLayerCount() <= 0)
81 OGRLayer* l = ds->GetLayer(0);
111 return m_connectionInfo;
116 m_connectionInfo = connInfo;
121 return std::auto_ptr<te::da::DataSourceTransactor>(
new Transactor(
this));
128 if(m_connectionInfo.empty())
129 throw Exception(
TR_OGR(
"There is no information about the data source"));
132 std::map<std::string, std::string>::const_iterator it;
134 it = m_connectionInfo.find(
"URI");
135 if (it==m_connectionInfo.end())
136 throw(Exception(
TR_OGR(
"Not enough information to open the data source.")));
140 if (boost::filesystem::exists(path))
141 m_ogrDS = OGRSFDriverRegistrar::Open(path.c_str(), 1);
146 m_ogrDS = OGRSFDriverRegistrar::Open(path.c_str(), 0);
165 OGRDataSource::DestroyDataSource(m_ogrDS);
184 return m_capabilities;
194 if(sm_myDialect != 0)
197 sm_myDialect = dialect;
207 setConnectionInfo(dsInfo);
217 std::map<std::string, std::string>::const_iterator it;
219 it = m_connectionInfo.find(
"URI");
220 if (it==m_connectionInfo.end())
221 throw(Exception(
TR_OGR(
"Not enough information to create data set.")));
224 boost::filesystem::path bpath(path);
225 std::string dir = bpath.parent_path().string();
226 if (!boost::filesystem::exists(dir))
227 boost::filesystem::create_directory(dir);
229 OGRSFDriverRegistrar* driverManager = OGRSFDriverRegistrar::GetRegistrar();
232 it = m_connectionInfo.find(
"DRIVER");
233 if (it!=m_connectionInfo.end())
234 driver = driverManager->GetDriverByName(it->second.c_str());
236 driver = driverManager->GetDriverByName(
GetDriverName(path).c_str());
239 throw(Exception(
TR_OGR(
"Driver not found.")));
241 if(!driver->TestCapability(ODrCCreateDataSource))
242 throw(Exception(
TR_OGR(
"The Driver does not have create capability.")));
244 char** papszOptions = 0;
245 it = m_connectionInfo.begin();
246 while(it != m_connectionInfo.end())
248 if(it->first ==
"URI" || it->first ==
"SOURCE" || it->first ==
"DRIVER")
253 papszOptions = CSLSetNameValue(papszOptions, it->first.c_str(), it->second.c_str());
257 m_ogrDS = driver->CreateDataSource(path.c_str(),papszOptions);
260 CSLDestroy(papszOptions);
264 throw(Exception(
TR_OGR(
"Error creating the dataset.")));
266 std::auto_ptr<te::da::DataSourceTransactor> t = getTransactor();
267 return t->createDataSet(dt, options);
272 std::string path = dsInfo.begin()->second;
274 if(m_ogrDS!=0 && path.compare(m_ogrDS->GetName()) == 0)
277 OGRSFDriverRegistrar* driverManager = OGRSFDriverRegistrar::GetRegistrar();
278 OGRSFDriver* driver = driverManager->GetDriverByName(
GetDriverName(path).c_str());
281 throw(Exception(
TR_OGR(
"Driver not found.")));
283 if(!driver->TestCapability(ODrCDeleteDataSource))
284 throw(Exception(
TR_OGR(
"The Driver does not have drop capability.")));
286 if(driver->DeleteDataSource(path.c_str()) != OGRERR_NONE)
287 throw(Exception(
TR_OGR(
"Error when dropping the data source.")));
292 return boost::filesystem::exists(dsInfo.begin()->second);
297 std::vector<std::string> names;
299 names.push_back(dsInfo.begin()->second);
306 std::vector<std::string> encodings;
void addSpatialTopologicOperator(const std::string &op)
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.
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
void setSupportString(const bool &support)
void setSupportArray(const bool &support)
OGRDataSource * getOGRDataSource()
const std::map< std::string, std::string > & getConnectionInfo() const
It returns the set of parameters used to set up the access channel to the underlying repository...
std::string GetDriverName(const std::string &path)
It tries extract the driver name used by OGR Library based on the given path.
A class for data providers of OGR.
void GetCapabilities(OGRDataSource *ds, te::da::DataSourceCapabilities &caps)
void setSupportDouble(const bool &support)
void GetDataSetTypeCapabilities(te::da::DataSourceCapabilities &caps)
void setSupportEfficientDataSetSize(const bool &support)
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns an object that can execute transactions in the context of a data source.
DataSource()
Default constructor that can be called by subclasses.
Utility functions for OGR support.
void setQueryCapabilities(const QueryCapabilities &capabilities)
void create(const std::map< std::string, std::string > &dsInfo)
It creates a new data source.
static void setDialect(te::da::SQLDialect *dialect)
It represents the SQL query dialect accepted by a given data source.
An static class with global definitions.
void addLogicalOperator(const std::string &op)
bool exists(const std::map< std::string, std::string > &dsInfo)
Check the existence of a data source in a driver.
std::vector< std::string > getDataSourceNames(const std::map< std::string, std::string > &dsInfo)
It gets the data source names available in a driver.
A class that informs the query support of a given data source.
void setSupportDateTime(const bool &support)
void setSupportByteArray(const bool &support)
void setConnectionInfo(const std::map< std::string, std::string > &connInfo)
It sets the connection information to be used when connecting to the data source. ...
#define TR_OGR(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
static te::da::SQLDialect * sm_myDialect
OGR SQL dialect.
void setSupportGeometry(const bool &support)
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
bool isValid() const
It checks if the data source is valid (available for using).
void drop(const std::map< std::string, std::string > &dsInfo)
It removes the data source with the connection information from a driver.
The OGR data source provider.
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
void setSupportRandomTraversing(const bool &support)
void setSupportInt32(const bool &support)
A class that models the description of a dataset.
A class that informs what the dataset implementation of a given data source can perform.
~DataSource()
Virtual destructor.
void open()
It opens the data source and makes it ready for using.
void close()
It closes the data source and clears all the resources used by its internal communication channel...
static const std::string m_driverIdentifier
The OGR driver identifier.
void setDataTypeCapabilities(const DataTypeCapabilities &capabilities)
std::vector< std::string > getEncodings(const std::map< std::string, std::string > &dsInfo)
It gets the encodings for the data source.
void setSupportEfficientMove(const bool &support)
void addComparsionOperator(const std::string &op)
A class that represents the supported data types of a specific data source.
void GetQueryCapabilities(te::da::DataSourceCapabilities &caps)
void setSupportBidirectionalTraversing(const bool &support)
void setSupportNumeric(const bool &support)
void setDataSetCapabilities(const DataSetCapabilities &capabilities)