26 #include "../core/filesystem/FileSystem.h" 27 #include "../core/translator/Translator.h" 28 #include "../core/uri/URI.h" 29 #include "../core/uri/Utils.h" 30 #include "../dataaccess/query/SQLDialect.h" 33 #include <ogrsf_frmts.h> 35 #include <gdal_priv.h> 40 #include <boost/filesystem/operations.hpp> 41 #include <boost/algorithm/string/replace.hpp> 87 if(!ds || ds->GetLayerCount() <= 0)
92 OGRLayer* l = ds->GetLayer(0);
131 return std::unique_ptr<te::da::DataSourceTransactor>(
new Transactor(
this));
139 throw Exception(
TE_TR(
"There is no valid information about the data source"));
142 boost::replace_all(path,
"file://",
"");
145 std::map<std::string, std::string>::const_iterator it;
148 throw(
Exception(
TE_TR(
"Not enough information to open the data source.")));
151 it = kvp.find(
"SHAPE_ENCODING");
153 CPLSetConfigOption(
"SHAPE_ENCODING", it->second.c_str());
156 m_ogrDS = (GDALDataset*)GDALOpenEx(path.c_str(), GDAL_OF_UPDATE,
nullptr,
nullptr,
nullptr);
161 m_ogrDS = (GDALDataset*)GDALOpenEx(path.c_str(), GDAL_OF_READONLY,
nullptr,
nullptr,
nullptr);
226 throw Exception(
TE_TR(
"There is no valid information about the data source"));
229 boost::replace_all(path,
"file://",
"");
232 std::map<std::string, std::string>::const_iterator it;
235 throw(
Exception(
TE_TR(
"Not enough information to create data set.")));
237 boost::filesystem::path bpath(path);
238 std::string dir = bpath.parent_path().string();
243 it = kvp.find(
"SHAPE_ENCODING");
245 CPLSetConfigOption(
"SHAPE_ENCODING", it->second.c_str());
247 GDALDriverManager* driverManager = GetGDALDriverManager();
250 it = kvp.find(
"DRIVER");
252 driver = driverManager->GetDriverByName(it->second.c_str());
254 driver = driverManager->GetDriverByName(
GetDriverName(path).c_str());
256 if (driver ==
nullptr)
259 if (!OGR_Dr_TestCapability(driver, ODrCCreateDataSource))
260 throw(
Exception(
TE_TR(
"The driver has no capability for creating a datasource!")));
262 char** papszOptions =
nullptr;
264 while (it != kvp.end())
266 papszOptions = CSLSetNameValue(papszOptions, it->first.c_str(), it->second.c_str());
270 m_ogrDS = driver->Create(path.c_str(), 0, 0, 0, GDT_Unknown, papszOptions);
273 CSLDestroy(papszOptions);
298 std::unique_ptr<te::da::DataSourceTransactor> t =
getTransactor();
299 return t->createDataSet(dt, options);
306 std::string path = auxURI.
path();
308 if (
m_ogrDS !=
nullptr && path.compare(
m_ogrDS->GetDescription()) == 0)
311 GDALDriverManager* driverManager = GetGDALDriverManager();
312 GDALDriver* driver = driverManager->GetDriverByName(
GetDriverName(path).c_str());
314 if (driver ==
nullptr)
317 if (!OGR_Dr_TestCapability(driver, ODrCDeleteDataSource))
327 boost::replace_all(path,
"file://",
"");
337 boost::replace_all(path,
"file://",
"");
339 std::vector<std::string> names;
343 names.push_back(path);
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.
std::string path() const
Retrieving the path.
void setSupportString(const bool &support)
te::da::SQLDialect * dialect
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
void open()
It opens the data source and makes it ready for using.
Base exception class for plugin module.
A class that models the description of a dataset.
te::core::EncodingType getEncoding()
It return the DataSource current encoding.
void addSpatialTopologicOperator(const std::string &op)
void setSupportGeometry(const bool &support)
void setSupportNumeric(const bool &support)
DataSource(const std::string &connInfo)
It represents the SQL query dialect accepted by a given data source.
void addComparsionOperator(const std::string &op)
void createOGRDataSource()
void setSupportEfficientMove(const bool &support)
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
bool isValid() const
Return if the given URI is valid or not.
void setAccessPolicy(const te::common::AccessPolicy &accessPolicy)
static te::dt::Date ds(2010, 01, 01)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
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 setSupportInt64(const bool &support)
void setSupportDouble(const bool &support)
void setQueryCapabilities(const QueryCapabilities &capabilities)
void setAsConnected(const bool &connected)
void setSupportByteArray(const bool &support)
std::string query() const
Retrieving the query.
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)
te::da::DataSourceCapabilities m_capabilities
OGR capabilities.
void GetCapabilities(GDALDataset *ds, te::da::DataSourceCapabilities &caps)
EncodingType
Supported character encodings.
A class that represents the supported data types of a specific data source.
te::core::EncodingType m_encoding
The data source encoding type.
static te::da::SQLDialect * sm_myDialect
OGR SQL dialect.
A class that informs the query support of a given data source.
This file contains include headers for the TerraLib GDAL driver.
static te::dt::TimeDuration dt(20, 30, 50, 11)
te::da::DataSource * Build(const te::core::URI &uri)
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).
std::vector< std::string > getDataSourceNames(const std::string &connInfo)
It gets the data source names available in a driver.
const std::string & uri() const
Retrieving the full URI.
The OGR data source provider.
void setSupportInt32(const bool &support)
void setSupportBidirectionalTraversing(const bool &support)
GDALDataset * getOGRDataSource()
A class for representing an Uniform Resource Identifier (URI).
GDALDataset * m_ogrDS
A pointer to OGR Data Source.
void GetQueryCapabilities(te::da::DataSourceCapabilities &caps)
~DataSource()
Virtual destructor.
static bool createDirectory(const std::string &path)
Creates a directory from a given path in UTF-8.
void setEncoding(const te::core::EncodingType &et)
It sets the encodings for the data source.
std::unique_ptr< te::da::DataSourceTransactor > getTransactor()
It returns the set of parameters used to set up the access channel to the underlying repository...
This file contains utility functions used to manipulate data from a URI.
void setSupportRandomTraversing(const bool &support)
A class for data providers of OGR.
void setDataTypeCapabilities(const DataTypeCapabilities &capabilities)
te::core::URI m_uri
The URI used to describe the datasource connection;.
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
void drop(const std::string &connInfo)
It removes the data source with the connection information from a driver.
void setSupportDateTime(const bool &support)
void close()
It closes the data source and clears all the resources used by its internal communication channel...
TECOREEXPORT std::string URIDecode(const std::string &srcUri)
Decodes an encoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
void setSupportArray(const bool &support)
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
bool exists(const std::string &connInfo)
Check the existence of a data source in a driver.
static void setDialect(te::da::SQLDialect *dialect)
bool m_isValid
True if this is a valid datasource.
static const std::string m_driverIdentifier
The OGR driver identifier.
An static class with global definitions.
void setSupportEfficientDataSetSize(const bool &support)
void GetDataSetTypeCapabilities(te::da::DataSourceCapabilities &caps)
void create(const std::string &connInfo)
It creates a new data source.