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(
TE_TR(
"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(
TE_TR(
"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)
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(
TE_TR(
"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(
TE_TR(
"Driver not found.")));
241 if(!driver->TestCapability(ODrCCreateDataSource))
242 throw(Exception(
TE_TR(
"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(
TE_TR(
"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(
TE_TR(
"Driver not found.")));
283 if(!driver->TestCapability(ODrCDeleteDataSource))
284 throw(Exception(
TE_TR(
"The Driver does not have drop capability.")));
286 if(driver->DeleteDataSource(path.c_str()) != OGRERR_NONE)
287 throw(Exception(
TE_TR(
"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 return std::vector<te::common::CharEncoding>();
void drop(const std::map< std::string, std::string > &dsInfo)
It removes the data source with the connection information from a driver.
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
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)
te::da::SQLDialect * dialect
void GetQueryCapabilities(te::da::DataSourceCapabilities &caps)
A class for data providers of OGR.
void GetDataSetTypeCapabilities(te::da::DataSourceCapabilities &caps)
bool exists(const std::map< std::string, std::string > &dsInfo)
Check the existence of a data source in a driver.
void open()
It opens the data source and makes it ready for using.
A class that models the description of a dataset.
void addSpatialTopologicOperator(const std::string &op)
void setSupportGeometry(const bool &support)
void setSupportNumeric(const bool &support)
It represents the SQL query dialect accepted by a given data source.
void create(const std::map< std::string, std::string > &dsInfo)
It creates a new data source.
void addComparsionOperator(const std::string &op)
void setSupportEfficientMove(const bool &support)
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
A class that informs what the dataset implementation of a given data source can perform.
#define TE_TR(message)
It marks a string in order to get translated.
void setSupportDouble(const bool &support)
void setQueryCapabilities(const QueryCapabilities &capabilities)
void setSupportByteArray(const bool &support)
std::string GetDriverName(const std::string &path)
It tries extract the driver name used by OGR Library based on the given path.
void addLogicalOperator(const std::string &op)
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 represents the supported data types of a specific data source.
static te::da::SQLDialect * sm_myDialect
OGR SQL dialect.
A class that informs the query support of a given data source.
OGRDataSource * getOGRDataSource()
void GetCapabilities(OGRDataSource *ds, te::da::DataSourceCapabilities &caps)
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.
void setDataSetCapabilities(const DataSetCapabilities &capabilities)
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
bool isValid() const
It checks if the data source is valid (available for using).
The OGR data source provider.
Utility functions for OGR support.
void setSupportInt32(const bool &support)
void setSupportBidirectionalTraversing(const bool &support)
std::vector< te::common::CharEncoding > getEncodings(const std::map< std::string, std::string > &dsInfo)
It gets the encodings for the data source.
~DataSource()
Virtual destructor.
void setSupportRandomTraversing(const bool &support)
void setDataTypeCapabilities(const DataTypeCapabilities &capabilities)
void setSupportDateTime(const bool &support)
void close()
It closes the data source and clears all the resources used by its internal communication channel...
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...
An static class with global definitions.
DataSource()
Default constructor that can be called by subclasses.
void setSupportArray(const bool &support)
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
static void setDialect(te::da::SQLDialect *dialect)
void setConnectionInfo(const std::map< std::string, std::string > &connInfo)
It sets the connection information to be used when connecting to the data source. ...
static const std::string m_driverIdentifier
The OGR driver identifier.
void setSupportEfficientDataSetSize(const bool &support)
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns an object that can execute transactions in the context of a data source.