26 #include <boost/algorithm/string.hpp> 
   27 #include <boost/format.hpp> 
   28 #include <boost/filesystem.hpp> 
   31 #include "../common/StringUtils.h" 
   32 #include "../common/Translator.h" 
   33 #include "../dataaccess/dataset/DataSetType.h" 
   34 #include "../dataaccess/query/DataSetName.h" 
   35 #include "../dataaccess/query/Select.h" 
   36 #include "../dataaccess/query/From.h" 
   37 #include "../dataaccess/query/FromItem.h" 
   38 #include "../geometry/Envelope.h" 
   39 #include "../raster/Grid.h" 
   40 #include "../raster/Raster.h" 
   41 #include "../raster/RasterProperty.h" 
   50 #include <gdal_priv.h> 
   59   GDALDataset* ds = 
static_cast<GDALDataset*
>(GDALOpen(dsfullname.c_str(), GA_ReadOnly));
 
   62     return std::auto_ptr<te::da::DataSetType>();
 
   70   std::vector<te::rst::BandProperty*> bprops;
 
   76   for (
size_t i=0; i<bprops.size(); ++i)
 
   83   return std::auto_ptr<te::da::DataSetType>(ptr);
 
   87   m_path (boost::filesystem::path(accessInfo))
 
  102   if (boost::filesystem::is_regular_file(path))
 
  105     if( upcaseExtension[ 0 ] == 
'.' ) upcaseExtension = upcaseExtension.substr( 1, upcaseExtension.size() - 1);
 
  107     std::pair< std::multimap< std::string, std::string >::const_iterator,
 
  108       std::multimap< std::string, std::string >::const_iterator > extensionsRangeIts =
 
  111     if( extensionsRangeIts.first != extensionsRangeIts.second )
 
  113       bool subDatasetsSupport = 
false;
 
  114       std::map< std::string, DriverMetadata >::const_iterator metaIt;
 
  115       while( extensionsRangeIts.first != extensionsRangeIts.second )
 
  119         if( metaIt->second.m_subDatasetsSupport )
 
  121           subDatasetsSupport = 
true;
 
  124         ++extensionsRangeIts.first;
 
  127       if( subDatasetsSupport )
 
  131         GDALDataset* gds = 
static_cast<GDALDataset*
>(GDALOpen(path.string().c_str(), GA_ReadOnly));
 
  135         char** subdatasets = gds->GetMetadata(
"SUBDATASETS");
 
  138           dsnames.push_back(path.leaf().string());
 
  143         for(
char** i = subdatasets; *i != 0; ++i)
 
  145           std::map<std::string, std::string> sdsmap;
 
  149           if(sdsmap.begin()->first.find(
"_NAME") != std::string::npos)
 
  151             std::string fullName = sdsmap.begin()->second;
 
  153             dsnames.push_back(subdsname);
 
  160         dsnames.push_back(path.leaf().string());
 
  167     for (boost::filesystem::directory_iterator it(path), itEnd; it !=itEnd; ++it)
 
  168       getDataSetNames(*it,dsnames);
 
  175   std::vector<std::string> dsnames;
 
  177   getDataSetNames(m_path,dsnames);
 
  184   return ( getNumberOfDataSets( path ) > 0 );
 
  189   return hasDataSets(m_path);
 
  194   std::vector<std::string> dsnames;
 
  195   getDataSetNames( path, dsnames );
 
  196   return dsnames.size();
 
  201   return getNumberOfDataSets(m_path);
 
  207   return getDataSetType(m_path,name,uri);
 
  212   if (boost::filesystem::is_regular_file(path))
 
  214     if (path.leaf() == name)
 
  217       std::auto_ptr<te::da::DataSetType> dsty = getType(path.string());
 
  219       dsty->setTitle(name);
 
  226       if( upcaseExtension[ 0 ] == 
'.' ) upcaseExtension = upcaseExtension.substr( 1, upcaseExtension.size() - 1);
 
  228       std::pair< std::multimap< std::string, std::string >::const_iterator,
 
  229         std::multimap< std::string, std::string >::const_iterator > extensionsRangeIts =
 
  232       if( extensionsRangeIts.first != extensionsRangeIts.second )
 
  234         bool subDatasetsSupport = 
false;
 
  235         std::map< std::string, DriverMetadata >::const_iterator metaIt;
 
  236         while( extensionsRangeIts.first != extensionsRangeIts.second )
 
  240           if( metaIt->second.m_subDatasetsSupport )
 
  242             subDatasetsSupport = 
true;
 
  245           ++extensionsRangeIts.first;
 
  248         if( subDatasetsSupport )
 
  253           GDALDataset* gds = 
static_cast<GDALDataset*
>(GDALOpen(path.string().c_str(), GA_ReadOnly));
 
  255             return std::auto_ptr<te::da::DataSetType>();
 
  257           char** subdatasets = gds->GetMetadata(
"SUBDATASETS");
 
  261             return std::auto_ptr<te::da::DataSetType>(); 
 
  264           for(
char** i = subdatasets; *i != 0; i=i+2)
 
  266             std::string sds_name = std::string(*i);
 
  267             std::string sds_desc = std::string(*(i+1));
 
  269             unsigned pos = sds_name.find(
"=");
 
  270             std::string val = sds_name.substr(++pos);
 
  276               std::auto_ptr<te::da::DataSetType> dsty = getType(val);
 
  279               pos = sds_desc.find(
"=");
 
  280               val = sds_desc.substr(++pos);
 
  290           return std::auto_ptr<te::da::DataSetType>(); 
 
  295         return std::auto_ptr<te::da::DataSetType>();
 
  301     for (boost::filesystem::directory_iterator it(path), itEnd; it != itEnd; ++it)
 
  303       std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(*it,name,uri);
 
  308   return std::auto_ptr<te::da::DataSetType>();
 
  318   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(m_path,name,uri);
 
  320     return std::auto_ptr<te::da::DataSet>();
 
  322   return std::auto_ptr<te::da::DataSet>(
new DataSet(dsty,accessPolicy, uri)); 
 
  333   return getDataSet(name, travType, connected, accessPolicy);
 
  344   return getDataSet(name, travType, connected, accessPolicy);
 
  353   return getDataSet(name, travType, connected, accessPolicy);
 
  359   boost::ptr_vector<te::dt::Property> properties;
 
  361   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
 
  363     return boost::ptr_vector<te::dt::Property>();
 
  365   const std::vector<te::dt::Property*>& props = dsty->getProperties();
 
  366   for(std::size_t i = 0; i < props.size(); ++i)
 
  367       properties.push_back(props[i]->clone());  
 
  374   boost::ptr_vector<te::dt::Property> properties;
 
  376   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
 
  378     return std::auto_ptr<te::dt::Property>();
 
  380   const std::vector<te::dt::Property*>& props = dsty->getProperties();
 
  381   for(std::size_t i = 0; i < props.size(); ++i)
 
  383     if (props[i]->getName() == name)
 
  384       return std::auto_ptr<te::dt::Property>(props[i]->clone()); 
 
  387   return std::auto_ptr<te::dt::Property>();
 
  392   boost::ptr_vector<te::dt::Property> properties;
 
  394   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
 
  396     return std::auto_ptr<te::dt::Property>();
 
  398   const std::vector<te::dt::Property*>& props = dsty->getProperties();
 
  399   if (propertyPos<props.size() && propertyPos>0)
 
  400     return std::auto_ptr<te::dt::Property>(props[propertyPos]->clone()); 
 
  402   return std::auto_ptr<te::dt::Property>();
 
  407   std::vector<std::string> pNames;
 
  409   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
 
  412     const std::vector<te::dt::Property*>& props = dsty->getProperties();
 
  413     for(std::size_t i = 0; i < props.size(); ++i)
 
  414       pNames.push_back(props[i]->getName());
 
  421   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
 
  423     return dsty->getProperties().size(); 
 
  430   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
 
  433     const std::vector<te::dt::Property*>& props = dsty->getProperties();
 
  434     for(std::size_t i = 0; i < props.size(); ++i)
 
  435       if(props[i]->getName()==name)
 
  443   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
 
  445     return (propertyPos < dsty->getProperties().size() && propertyPos>0);
 
  458     throw Exception(
TE_TR(
"Can not process the Select object."));
 
  463     throw Exception(
TE_TR(
"Can not process the Select object."));
 
  465   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(dsname->
getName());
 
  470     throw Exception(
TE_TR(
"Can not process the Select object: dataset not found."));
 
  472   std::string uri = dsty->getTitle();
 
  473   return std::auto_ptr<te::da::DataSet>(
new DataSet(dsty,accessPolicy,uri)); 
 
  481   std::vector<std::string> words;
 
  483   boost::split(words, s, boost::is_any_of(
", "), boost::token_compress_on);
 
  485   std::vector<std::string>::const_iterator it = std::find(words.begin(), words.end(), 
"FROM");
 
  486   if (it== words.end())
 
  487     it =  std::find(words.begin(), words.end(), 
"from");
 
  489   if (it== words.end())
 
  490     throw Exception(
TE_TR(
"Can not process the query expression."));
 
  493   if (it== words.end())
 
  494     throw Exception(
TE_TR(
"Can not process the query expression."));  
 
  496   std::string dsname = *it;
 
  498   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(dsname);
 
  500     throw Exception(
TE_TR(
"Can not process the Select object: dataset not found."));
 
  502   std::string uri = dsty->getTitle();
 
  503   return std::auto_ptr<te::da::DataSet>(
new DataSet(dsty,accessPolicy,uri));
 
  508   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(name);
 
  510   return (dsty.get() != 0);
 
  515   std::auto_ptr<te::dt::Property> pp = getProperty(datasetName,propertyPos);
 
  524   return std::auto_ptr<te::gm::Envelope>();
 
  529   std::auto_ptr<te::dt::Property> pp = getProperty(datasetName,propertyName);
 
  538   return std::auto_ptr<te::gm::Envelope>();
 
  542                                          const std::map<std::string, std::string>& options) 
 
  544   if (!boost::filesystem::is_directory(m_path))
 
  545     throw Exception(
TE_TR(
"Create operation supported just on directory data sources."));
 
  549   boost::filesystem::path paux(m_path);
 
  552   if (boost::filesystem::exists(paux))
 
  553     throw Exception((boost::format(
TE_TR(
"The datasource already has a dataset with this name (\"%1%\")!")) % dt->
getName()).str());
 
  560     throw Exception(
TE_TR(
"GDAL driver couldn't persist the raster file."));
 
  566                                         const std::string& cloneName,
 
  567                                         const std::map<std::string, std::string>& options)
 
  569   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(name); 
 
  572     throw Exception(
TE_TR(
"Dataset does not exist."));
 
  574   boost::filesystem::path mpath(dsty->getTitle());
 
  576   if (!boost::filesystem::is_regular_file(mpath))
 
  577     throw Exception(
TE_TR(
"Can not clone a dataset that it is not a raster file."));
 
  579   boost::filesystem::path newpath(mpath.parent_path() /= cloneName);
 
  580   boost::filesystem::copy_file(mpath, newpath);
 
  586   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(name); 
 
  589     throw Exception(
TE_TR(
"Dataset does not exist."));
 
  591   boost::filesystem::path mpath(dsty->getTitle());
 
  592   if (!boost::filesystem::is_regular_file(mpath))
 
  593     throw Exception(
TE_TR(
"Can not drop a dataset that it is not a raster file."));
 
  595   boost::filesystem::remove(mpath.string());  
 
  600   std::auto_ptr<te::da::DataSetType> dsty = getDataSetType(name); 
 
  603     throw Exception(
TE_TR(
"Dataset does not exist."));
 
  605   boost::filesystem::path mpath(dsty->getTitle());
 
  606   if (!boost::filesystem::is_regular_file(mpath))
 
  607     throw Exception(
TE_TR(
"Can not rename a dataset that it is not a raster file."));
 
  609   boost::filesystem::path newpath(mpath.parent_path() /= newName);
 
  610   boost::filesystem::rename(mpath, newpath);
 
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset. 
 
void setTitle(const std::string &title)
It sets a human descriptive title for the DataSetType. 
 
Property * getProperty(std::size_t i) const 
It returns the i-th property. 
 
const std::multimap< std::string, std::string > & GetGDALDriversUCaseExt2DriversMap()
Returns a map all GDAL supported Upper-case extensions to their respective driver names...
 
void set(te::rst::Grid *grid)
Sets the definition of the raster grid support. 
 
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. 
 
CharEncoding
Supported charsets (character encoding). 
 
Utilitary functions to access GDAL and match some of its concepts to TerraLib concepts. 
 
A class that models the name of a dataset used in a From clause. 
 
TEGDALEXPORT void GetBandProperties(GDALDataset *gds, std::vector< te::rst::BandProperty * > &bprops)
Gets the list of bands definition from a GDAL dataset. 
 
A class that models the description of a dataset. 
 
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset. 
 
const double & getUpperRightX() const 
It returns a constant refernce to the x coordinate of the upper right corner. 
 
const std::map< std::string, DriverMetadata > & GetGDALDriversMetadata()
Returns metadata from all registered GDAL drivers (key: driver name). 
 
void ExtractKVP(const std::string &kvpStr, std::map< std::string, std::string > &kvp, const std::string &kvpDelimiter="&", const std::string &kvDelimiter="=", bool toUpper=false)
It extracts a key-value map from a string. 
 
const double & getLowerLeftY() const 
It returns a constant refernce to the y coordinate of the lower left corner. 
 
std::string Convert2UCase(const std::string &value)
It converts a string to upper case. 
 
SpatialRelation
Spatial relations between geometric objects. 
 
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source. 
 
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
 
std::auto_ptr< te::da::DataSetType > getType(const std::string &dsfullname)
 
const double & getUpperRightY() const 
It returns a constant refernce to the x coordinate of the upper right corner. 
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
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. 
 
An exception class for the GDAL module. 
 
te::common::CharEncoding getEncoding()
It return the DataSource current encoding. 
 
AccessPolicy
Supported data access policies (can be used as bitfield). 
 
TraverseType
A dataset can be traversed in two ways: 
 
GDALDataset * CreateRaster(te::rst::Grid *g, const std::vector< te::rst::BandProperty * > &bands, const std::map< std::string, std::string > &optParams)
Creates a raster data using GDAL. 
 
void add(te::rst::BandProperty *b)
It adds a new band information to the property. 
 
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::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. 
 
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. 
 
std::vector< std::string > getDataSetNames()
It It gets the dataset names available 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::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...
 
std::string GetParentDataSetName(const std::string &subDataSetName)
It returns the parent dataset name from a Sub DataSet name. 
 
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset. 
 
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. 
 
te::da::DataSource * getDataSource() const 
It returns the parent data source of the transactor. 
 
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. 
 
boost::ptr_vector< FromItem > From
It models the FROM clause for a query. 
 
std::string GetDriverName(const std::string &dsName)
It returns the GDAL driver name associated to a data source name. 
 
void add(Constraint *c)
It adds a new constraint. 
 
te::rst::Grid * getGrid()
Returns the definition of the raster grid support. 
 
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source. 
 
const double & getLowerLeftX() const 
It returns a constant reference to the x coordinate of the lower left corner. 
 
GDAL data set use counter. 
 
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid. 
 
A GDAL data set gives access to a raster file. 
 
const std::string & getName() const 
It returns the dataset name. 
 
std::vector< te::rst::BandProperty * > & getBandProperties()
Returns a reference to the list of bands definitions. 
 
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. 
 
A rectified grid is the spatial support for raster data. 
 
std::string GetSubDataSetName(const std::string &name, const std::string &driverName)
It returns the Sub DataSet name from the given name or the same name. 
 
TEGDALEXPORT te::rst::Grid * GetGrid(GDALDataset *gds)
Gets the grid definition from a GDAL dataset. 
 
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset. 
 
The implementation of a DataSource that consists of datasets that can be decoded by the GDAL Library...
 
Select & from(const FromItem &item)
 
bool hasDataSets()
It checks if the data source has any dataset. 
 
const std::string & getName() const 
It returns the property name. 
 
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset. 
 
Transactor(const std::string &accessInfo)