16 std::string aux, user, password, host, port, path, query;
17 std::string strURI =
"pgsql://";
19 std::cout <<
"Inform the Host for your postGIS server (ENTER to accept default \'atlas.dpi.inpe.br\'): ";
20 std::getline (std::cin, aux);
21 host = aux.empty() ?
"atlas.dpi.inpe.br" : aux;
23 std::cout <<
"Inform the Port number to access your postGIS server (ENTER to accept default \'5433\'): ";
24 std::getline (std::cin, aux);
25 port = aux.empty() ?
"5433" : aux;
27 std::cout <<
"Inform the User to access your postGIS server (ENTER to accept default \'postgres\'): ";
28 std::getline (std::cin, aux);
29 user = aux.empty() ?
"postgres" : aux;
31 std::cout <<
"Inform the Password to access your postGIS server (ENTER to accept default \'postgres\'): ";
32 std::getline (std::cin, aux);
33 password = aux.empty() ?
"postgres" : aux;
35 std::cout <<
"Inform the Database name to connect to your postGIS server (ENTER to accept default \'terralib4\'): ";
36 std::getline (std::cin, aux);
37 path = aux.empty() ?
"terralib4" : aux;
39 std::cout <<
"Inform the Client enconding to connect to your postGIS server (ENTER to accept default \'UTF-8\'): ";
40 std::getline(std::cin, aux);
43 std::cout <<
"Inform the Connection Time Out to connect to your postGIS server (ENTER to accept default \'4\'): ";
44 std::getline (std::cin, aux);
45 query += aux.empty() ?
"&PG_CONNECT_TIMEOUT=4" :
"&PG_CONNECT_TIMEOUT=" + aux;
48 strURI += password +
"@";
61 catch(
const std::exception& e)
63 std::cout <<
"Datasource " << host <<
"/" << path <<
" can not be used!\nMake sure to have the correct connection parameters\n";
64 std::cout <<
"Error: " << e.what() << std::endl;
70 std::cout <<
"Datasource " << host <<
"/" << path <<
" can not be used!\nMake sure to have the correct connection parameters\n";
75 std::cout <<
"Using datasource " << host <<
"/" << path << std::endl;
90 std::cout <<
"Datasource is opened? " << std::boolalpha << ds->isOpened() <<
'\n';
91 std::cout <<
"Datasource is valid? " << std::boolalpha << ds->isValid() <<
'\n';
94 std::cout << std::endl;
98 std::vector<std::string> dsets = ds->getDataSetNames();
102 std::cout <<
"Datasource has no datasets.\n";
107 std::cout <<
"\nThere is(are) " << dsets.size() <<
" dataset(s) in the datasource: \n";
108 for (
size_t i=0; i<dsets.size(); ++i)
109 std::cout <<
'\t' << i+1 <<
':' << dsets[i] << std::endl;
114 std::cout <<
"\nSelect a dataset from 1 to " << ds->getNumberOfDataSets() <<
" to see its data (0 to none): ";
117 if (n<1 || n>ds->getNumberOfDataSets())
119 PrintDataSet(dsets[n-1], ds->getDataSet(dsets[n-1]).get());
123 std::vector<std::string>::iterator it;
124 it = std::find(dsets.begin(),dsets.end(),
"public.munic_2001");
125 if (it != dsets.end())
127 std::cout <<
"\nHow to do spatial filtering using the dataset \'public.munic_2001\'\n";
132 it = std::find(dsets.begin(),dsets.end(),
"public.our_country");
133 if (it != dsets.end())
136 std::cout <<
"\nHow to create a new dataset the dataset: ex 'public.our_country'\n";
137 std::unique_ptr<te::da::DataSourceTransactor> transactor = ds->getTransactor();
138 std::string dt_name =
"our_country";
139 std::cout << std::endl <<
"Creating dataSet= " << dt_name << std::endl;
149 std::cout << std::endl <<
"Adding Primary Key to " << dt_name << std::endl;
154 std::cout << std::endl <<
"Adding Unique Key to " << dt_name << std::endl;
159 std::cout << std::endl <<
"Adding spatial index to " << dt_name << std::endl;
164 std::cout << std::endl <<
"Adding new Property population to " << dt_name << std::endl;
169 std::cout << std::endl <<
"Droping Property population of " << dt_name <<
" using transactor or ds"<< std::endl;
170 (transactor.get())->dropProperty(datasetType->
getName(),
"population");
173 std::cout << std::endl <<
"Adding new Property population to " << dt_name << std::endl;
177 ds->dropProperty(dt_name,
"population");
180 ds->dropProperty(dt_name,
"spatial_data");
183 std::cout << std::endl <<
"Droping dataSet " << dt_name << std::endl;
184 ds->dropDataSet(dt_name);
191 if (transactor->isInTransaction())
192 std::cout << std::endl <<
"Transactor in transaction! "<< std::endl;
193 delete transactor.release();
196 catch(
const std::exception& e)
198 std::cout << std::endl <<
"An exception has occurred in the PostGIS Example: " << e.what() << std::endl;
202 std::cout << std::endl <<
"An unexpected exception has occurred in the PostGIS Example!" << std::endl;
This file contains include headers for the Data Type module of TerraLib.
te::dt::SimpleProperty * AddProperty(const std::string &datasetname, te::da::DataSourceTransactor *transactor)
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
An atomic property like an integer or double.
A class that models the description of a dataset.
void RetrieveUsingSpatialFilter(te::da::DataSource *ds)
An example showing how to retrieve data using a spatial filter.
te::da::Index * AddSpatialIndex(const std::string &datasetname, te::da::DataSourceTransactor *transactor)
void PostGISExample()
An example using PostGIS data source driver.
static te::dt::Date ds(2010, 01, 01)
void PrintDataSourceCapabilities(te::da::DataSource *ds)
It retrieves and prints the capabilities of a given data source.
te::da::UniqueKey * AddUniqueKey(const std::string &datasetname, te::da::DataSourceTransactor *transactor)
te::da::DataSetType * CreateDataSetType(const std::string &datasetname, te::da::DataSetType *dt, te::da::DataSourceTransactor *transactor)
static std::string getEncodingName(EncodingType et)
Retrive a string from a given character encoding type enum.
te::da::PrimaryKey * AddPrimaryKey(const std::string &datasetname, te::da::DataSourceTransactor *transactor)
Examples on how to access/manipulate DataSources in TerraLib.
A factory for data sources.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
It describes a unique key (uk) constraint.
std::unique_ptr< te::da::DataSource > GetPostGISConnection()
It returns the union of a geometry vector.
void add(Constraint *c)
It adds a new constraint.
It describes a primary key (pk) constraint.
void DroppingDataSetType(const std::string &datasetname, te::da::DataSourceTransactor *trans)
It removes a data set type from the associated data source.
It describes an index associated to a DataSetType.
void PrintDataSet(std::string datasetName, te::da::DataSet *dataset)
It prints the data in a given dataset.
const std::string & getName() const
It returns the property name.