TerraLib and TerraView Wiki Page

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
wiki:designimplementation:dataaccess [2014/04/04 18:07]
marisa [DataSetItem]
wiki:designimplementation:dataaccess [2014/08/18 14:14] (current)
marisa [DataSource]
Line 39: Line 39:
 Each data source driver must have a unique identifier. This identifier is a string (//in capital letters//) with the data source type name and it is available through the method ''​getType''​. Examples of identifiers are: POSTGIS, OGR, GDAL, SQLITE, WFS, WCS, MYSQL, ORACLE, SHP, MICROSOFT_ACCESS. ​ Each data source driver must have a unique identifier. This identifier is a string (//in capital letters//) with the data source type name and it is available through the method ''​getType''​. Examples of identifiers are: POSTGIS, OGR, GDAL, SQLITE, WFS, WCS, MYSQL, ORACLE, SHP, MICROSOFT_ACCESS. ​
  
-A data source is also characterized by a set of parameters that can be used to set up an access channel to its underlying repository. This information is referred as the data source connection information. This information may be provided as an associative container (a set of key-value pairs) through the method ''​setConnectionInfo''​ or using a plain connection string through the method ''​setConnectionStr''​. The key-value pairs (kvp) may contain information about maximum number of accepted connections,​ user name and password required for establishing a connection, the url of a service or any other information needed by the data source to operate. The parameters are dependent on the data source driver. So, please, check the driver documentation for any additional information on the supported parameters. When using a plain string, the information is encoded by a set of key-value pairs separated by an equal sign and each pair is separated by the ampersand (''&''​) and they must be URL encoded. For instance, in a PostGIS data source it is usual to use the following syntax:+A data source is also characterized by a set of parameters that can be used to set up an access channel to its underlying repository. This information is referred as the data source connection information. This information may be provided as an associative container (a set of key-value pairs) through the method ''​setConnectionInfo''​. The key-value pairs (kvp) may contain information about maximum number of accepted connections,​ user name and password required for establishing a connection, the url of a service or any other information needed by the data source to operate. The parameters are dependent on the data source driver. So, please, check the driver documentation for any additional information on the supported parameters. For instance, in a PostGIS data source it is usual to use the following syntax:
  
 <code cpp> <code cpp>
-std::string connInfo ​"host=atlas.dpi.inpe.br&port=5432&​dbname=mydb&​user=postgres&​password=mypasswd&​connect_timeout=20";+  std::​map<​std::string, std::​string> ​connInfo
 +  pgisInfo["PG_HOST"​] ​"atlas.dpi.inpe.br" ;   // or "​localhost";​ 
 +  pgisInfo["​PG_PORT"​] ​"​5433"​ ; 
 +  pgisInfo["​PG_USER"​] ​"postgres"; 
 +  pgisInfo["​PG_PASSWORD"​] ​"​xxxxxxx";​ 
 +  pgisInfo["​PG_DB_NAME"​] ​"​terralib4";​ 
 +  pgisInfo["​PG_CONNECT_TIMEOUT"​] = "​4";​ 
 +  pgisInfo["​PG_CONNECT_TIMEOUT"​] = "​4";​ 
 +  pgisInfo["​PG_CLIENT_ENCODING"​] = "​CP1252"; ​
 </​code>​ </​code>​
  
 For a WFS data source available at ''​http://​www.dpi.inpe.br/​wfs''​ the connection string could be: For a WFS data source available at ''​http://​www.dpi.inpe.br/​wfs''​ the connection string could be:
 <code cpp> <code cpp>
-std::string connInfo ​"service=http%3A%2F%2Fwww.dpi.inpe.br%2Fwfs";+std::​map<​std::string, std::​string> ​connInfo
 +connInfo["URI"​] ​"http://www.dpi.inpe.br/wfs";
 </​code>​ </​code>​
  
-The method ''​getConnectionInfo''​ returns an associative container (set of key-value pairs) with the connection information. The same information is also available in an URL encoded string through the method ''​getConnectionStr''​.+The method ''​getConnectionInfo''​ returns an associative container (set of key-value pairs) with the connection information.
  
-Another useful information available in a data source is its known [[:​wiki:​designimplementation:​dataaccess#​common_data_source_capabilities|capabilities]]. The method ''​getCapabilities''​ returns ​an associative container with all information about what the data source can perform. Here you will find if the data source implementation supports primary keys, foreign keys, if it can be used in a thread environment and much more information. There is a list of common key-value pairs that every data access driver must supply although each implementation can provide additional information.+Another useful information available in a data source is its known [[:​wiki:​designimplementation:​dataaccess#​common_data_source_capabilities|capabilities]]. The method ''​getCapabilities''​ returns all information about what the data source can perform. Here you will find if the data source implementation supports primary keys, foreign keys, if it can be used in a thread environment and much more information. There is a list of common key-value pairs that every data access driver must supply although each implementation can provide additional information.
  
 A data source can be in one of the following states: //opened// or //closed//. In order to open a data source and makes it ready for use, one needs to provide the set of parameters required to set up the underlying access channel to the repository and then call one of the ''​open''​ methods. These methods will prepare the data source to work. If the implementation needs to open a connection to a database server, or to open a file or to get information from a Web Service, these methods can do this kind of job in order to prepare the data source to be in an operational mode. As one can see, you can use an associative container with the connection information or a string in a kvp notation. A data source can be in one of the following states: //opened// or //closed//. In order to open a data source and makes it ready for use, one needs to provide the set of parameters required to set up the underlying access channel to the repository and then call one of the ''​open''​ methods. These methods will prepare the data source to work. If the implementation needs to open a connection to a database server, or to open a file or to get information from a Web Service, these methods can do this kind of job in order to prepare the data source to be in an operational mode. As one can see, you can use an associative container with the connection information or a string in a kvp notation.
Line 80: Line 89:
 <code cpp> <code cpp>
  
-// this is the connection ​string ​when dealing with a single shape-file +// this is the connection ​info when dealing with a single shape-file 
-std::string ogrInfo("connection_string=/​data/​shp/​munic_2001.shp"​);+std::​map<​std::​string, ​std::stringogrInfo
 +ogrInfo["URI"​] ​"./​data/​shp/​munic_2001.shp";​
  
 // use the factory to create a data source capable of accessing shape-file data // use the factory to create a data source capable of accessing shape-file data
-te::​da::​DataSourceds = te::​da::​DataSourceFactory::​make("​OGR"​);​+std::​auto_ptr<​te::​da::​DataSource>  ​ds = te::​da::​DataSourceFactory::​make("​OGR"​);​
  
 // set the connection info and open the data source ​ // set the connection info and open the data source ​
Line 92: Line 102:
 ... // operate on the data source ... // operate on the data source
  
-// release the data source when it is not needed anymore 
-delete ds; 
 </​code>​ </​code>​
  
Line 99: Line 107:
  
 <code cpp> <code cpp>
-// this is the connection ​string +// this is the connection ​info when dealing with a directory of raster files 
-std::string gdalInfo="URI=./​data/​rasters/";​ +std::​map<​std::​string, ​std::stringgdalInfo
 +gdalInfo["SOURCE"​] ​"./​data/​rasters/";​ 
 +  
 // use the factory to create a data source capable of accessing image files // use the factory to create a data source capable of accessing image files
-te::​da::​DataSourceds = te::​da::​DataSourceFactory::​make("​GDAL"​);​+std::​auto_ptr<​te::​da::​DataSourceds = te::​da::​DataSourceFactory::​make("​GDAL"​);​
  
 // set the connection info and open data source to make it ready for use  // set the connection info and open data source to make it ready for use 
Line 111: Line 120:
 ... // operate on the data source ... // operate on the data source
  
-// release the data source when it is not needed anymore 
-delete ds; 
 </​code>​ </​code>​
  
Line 119: Line 126:
 <code cpp> <code cpp>
 // use the factory to create a data source capable of accessing a PostgreSQL with the PostGIS extension enabled // use the factory to create a data source capable of accessing a PostgreSQL with the PostGIS extension enabled
-te::​da::​DataSourceds = te::​da::​DataSourceFactory::​make("​POSTGIS"​);​+std::​auto_ptr<​te::​da::​DataSourceds = te::​da::​DataSourceFactory::​make("​POSTGIS"​);​
  
 // a map from parameter name to parameter value // a map from parameter name to parameter value
 std::​map<​std::​string,​ std::​string>​ connInfo; std::​map<​std::​string,​ std::​string>​ connInfo;
  
-connInfo["​host"] = "​atlas.dpi.inpe.br"​ ;   // or "​localhost";​ +connInfo["​PG_HOST"] = "​atlas.dpi.inpe.br"​ ;   // or "​localhost";​ 
-connInfo["​user"] = "​postgres";​ +connInfo["​PG_USER"] = "​postgres";​ 
-connInfo["​password"] = "​xxxxxxxx";​ +connInfo["​PG_PASSWORD"] = "​xxxxxxxx";​ 
-connInfo["​dbname"] = "​mydb";​ +connInfo["​PG_DB_NAME"] = "​mydb";​ 
-connInfo["​connect_timeout"] = "​4";​ +connInfo["​PG_CONNECT_TIMEOUT"] = "​4";​ 
-connInfo["​port"] = "​5432";​+connInfo["​PG_CLIENT_ENCODING"​] = "​WIN1252"; ​ //or "​LATIN1"​ 
 +connInfo["​PG_PORT"] = "​5432";​
  
 // set the connection info and open the data source to make it ready for use // set the connection info and open the data source to make it ready for use
Line 137: Line 145:
 ... // operate on the data source ... // operate on the data source
  
-// release the data source when it is not needed anymore 
-delete ds; 
 </​code>​ </​code>​
  
Line 330: Line 336:
  
 {{:​wiki:​designimplementation:​dataaccess:​da_datasourcecatalog.png|DataSourceCatalog class}} {{:​wiki:​designimplementation:​dataaccess:​da_datasourcecatalog.png|DataSourceCatalog class}}
 +
 +[[@../​doxygendoc/​df/​d70/​classte_1_1da_1_1DataSourceCatalog.html|DataSourceCatalog Class]]
  
 As can be seen in the above diagram all data source implementations provide the ''​getCatalog()''​ method for given access to the cached dataset schema if one exists. This cache can be controlled by the programmer or can be loaded all at once using the [[:​wiki:​designimplementation:​dataaccess#​datasourcecatalogloader|DataSourceCatalogLoader]] (see the ''​getCatalogLoader''​ in the [[:​wiki:​designimplementation:​dataaccess#​datasourcetransactor|DataSourceTransactor]] class). A catalog that belongs to a data source will have an explicit association to it. The method ''​getDataSource''​ can be used to access the data source associated to the catalog. ​ As can be seen in the above diagram all data source implementations provide the ''​getCatalog()''​ method for given access to the cached dataset schema if one exists. This cache can be controlled by the programmer or can be loaded all at once using the [[:​wiki:​designimplementation:​dataaccess#​datasourcecatalogloader|DataSourceCatalogLoader]] (see the ''​getCatalogLoader''​ in the [[:​wiki:​designimplementation:​dataaccess#​datasourcetransactor|DataSourceTransactor]] class). A catalog that belongs to a data source will have an explicit association to it. The method ''​getDataSource''​ can be used to access the data source associated to the catalog. ​
Line 386: Line 394:
  
 {{:​wiki:​designimplementation:​dataaccess:​da_datasourcetransactor.png|DataSourceTransactor class}} {{:​wiki:​designimplementation:​dataaccess:​da_datasourcetransactor.png|DataSourceTransactor class}}
 +
 +[[@../​doxygendoc/​dd/​d53/​classte_1_1da_1_1DataSourceTransactor.html|DataSourceTransactor class]]
  
 Depending on its capabilities a transactor can support ACID transactions:​ Depending on its capabilities a transactor can support ACID transactions:​
Line 851: Line 861:
 {{:​wiki:​designimplementation:​dataaccess:​da_capabilities.png|Data Source Capabilities}} {{:​wiki:​designimplementation:​dataaccess:​da_capabilities.png|Data Source Capabilities}}
  
-Besides the common capabilities each driver can also provides specific capabilities that must be handle by special code.+Besides the common capabilities each driver can also provides specific capabilities that must be handle by special code.  
 + 
 +Below some capabilities are described. To access all the details about capabilities click [[@../​doxygendoc/​da/​df7/​classte_1_1da_1_1DataSourceCapabilities.html|here]].
  
 === DataSourceCapabilities Class ==== === DataSourceCapabilities Class ====