TsIdentity.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 //TerraLib
21 #include <terralib_buildconfig.h>
25 #include <terralib/vp/Identity.h>
26 
27 // Boost
28 #include <boost/test/unit_test.hpp>
29 #include <boost/uuid/random_generator.hpp>
30 #include <boost/uuid/uuid_io.hpp>
31 
32 BOOST_AUTO_TEST_SUITE( identity_tests )
33 
34 /* Tests with shape as input and output */
35 BOOST_AUTO_TEST_CASE( identity_shptoshp_test )
36 {
37  std::string data_dir = TERRALIB_DATA_DIR;
38 
39  std::string input_filename(data_dir + "/shape/munic_goias.shp");
40  std::string srcInputInfo ("file://" + input_filename);
41 
42  std::string intersection_filename(data_dir +
43  "/shape/munic_goias_selected.shp");
44  std::string srcIntersectionInfo ("file://" + intersection_filename);
45 
46 
47  te::da::DataSourcePtr srcInputDs(
48  te::da::DataSourceFactory::make("OGR", srcInputInfo));
49  srcInputDs->open();
50 
51  te::da::DataSourcePtr srcIntersectionDs(
52  te::da::DataSourceFactory::make("OGR", srcIntersectionInfo));
53  srcIntersectionDs->open();
54 
55 
56  std::string input_DsetName = "munic_goias";
57  std::string intersection_DsetName = "munic_goias_selected";
58 
59 
60  BOOST_REQUIRE_MESSAGE(srcInputDs->dataSetExists(input_DsetName),
61  "Input dataset not found: " + input_DsetName);
62 
63  std::unique_ptr<te::da::DataSet> input_Dset =
64  srcInputDs->getDataSet(input_DsetName);
65 
66  std::unique_ptr<te::da::DataSetType> input_DsetType =
67  srcInputDs->getDataSetType(input_DsetName);
68 
69  BOOST_REQUIRE_MESSAGE(srcIntersectionDs->dataSetExists(intersection_DsetName),
70  "Input dataset not found: " + intersection_DsetName);
71 
72  std::unique_ptr<te::da::DataSet> intersection_Dset =
73  srcIntersectionDs->getDataSet(intersection_DsetName);
74 
75  std::unique_ptr<te::da::DataSetType> intersection_DsetType =
76  srcIntersectionDs->getDataSetType(intersection_DsetName);
77 
78  std::vector<std::string> attributes;
79  attributes.push_back("nome");
80  attributes.push_back("nomemeso");
81 
82  std::map<std::string, te::dt::AbstractData*> specificParams;
83  specificParams["munic_goias"] =
85  specificParams["munic_goias_selected"] =
87 
88  std::string output_filename(data_dir + "/shape/identity_shptoshp_test.shp");
89  std::string tgrInfo ("file://" + output_filename);
90 
92  trgDs->open();
93 
94  std::string outDSName = "identity_shptoshp_test";
95 
96  BOOST_REQUIRE_MESSAGE(
97  !trgDs->dataSetExists(outDSName),
98  "A dataset with the same requested output dataset name already exists: " +
99  outDSName);
100 
101  std::vector<te::vp::InputParams> inputParamsVec;
102  te::vp::InputParams structInputParams;
103  te::vp::InputParams structIntersectionParams;
104 
105  structInputParams.m_inputDataSource = srcInputDs;
106  structInputParams.m_inputDataSetType = input_DsetType.release();
107  structInputParams.m_inputDataSet = input_Dset.release();
108 
109  structIntersectionParams.m_inputDataSource = srcIntersectionDs;
110  structIntersectionParams.m_inputDataSetType = intersection_DsetType.release();
111  structIntersectionParams.m_inputDataSet = intersection_Dset.release();
112 
113  inputParamsVec.push_back(structInputParams);
114  inputParamsVec.push_back(structIntersectionParams);
115 
117  params->setInputParams(inputParamsVec);
118  params->setOutputDataSource(trgDs);
119  params->setOutputDataSetName(outDSName);
120  params->setSpecificParams(specificParams);
121 
122  te::vp::Identity identity;
123  BOOST_CHECK(identity.executeMemory(params));
124 
125  delete params;
126 
127  return;
128 }
129 
130 /* Tests with shape as input and pgis as output */
131 BOOST_AUTO_TEST_CASE( identity_shptopgis_test )
132 {
133  std::string data_dir = TERRALIB_DATA_DIR;
134 
135  std::string input_filename(data_dir + "/shape/munic_goias.shp");
136  std::string srcInputInfo ("file://" + input_filename);
137 
138  std::string intersection_filename(data_dir +
139  "/shape/munic_goias_selected.shp");
140  std::string srcIntersectionInfo ("file://" + intersection_filename);
141 
142 
143  te::da::DataSourcePtr srcInputDs(
144  te::da::DataSourceFactory::make("OGR", srcInputInfo));
145  srcInputDs->open();
146 
147  te::da::DataSourcePtr srcIntersectionDs(
148  te::da::DataSourceFactory::make("OGR", srcIntersectionInfo));
149  srcIntersectionDs->open();
150 
151 
152  std::string input_DsetName = "munic_goias";
153  std::string intersection_DsetName = "munic_goias_selected";
154 
155 
156  BOOST_REQUIRE_MESSAGE(srcInputDs->dataSetExists(input_DsetName),
157  "Input dataset not found: " + input_DsetName);
158 
159  std::unique_ptr<te::da::DataSet> input_Dset =
160  srcInputDs->getDataSet(input_DsetName);
161 
162  std::unique_ptr<te::da::DataSetType> input_DsetType =
163  srcInputDs->getDataSetType(input_DsetName);
164 
165  BOOST_REQUIRE_MESSAGE(srcIntersectionDs->dataSetExists(intersection_DsetName),
166  "Input dataset not found: " + intersection_DsetName);
167 
168  std::unique_ptr<te::da::DataSet> intersection_Dset =
169  srcIntersectionDs->getDataSet(intersection_DsetName);
170 
171  std::unique_ptr<te::da::DataSetType> intersection_DsetType =
172  srcIntersectionDs->getDataSetType(intersection_DsetName);
173 
174  std::vector<std::string> attributes;
175  attributes.push_back("nome");
176  attributes.push_back("nomemeso");
177 
178  std::map<std::string, te::dt::AbstractData*> specificParams;
179  specificParams["munic_goias"] =
181  specificParams["munic_goias_selected"] =
183 
184  std::string connInfo(
185  "ppgsql://postgres:postgres@atlas.dpi.inpe.br:5433/testPostGIS");
186 
187  te::da::DataSourcePtr trgDs(
188  te::da::DataSourceFactory::make("POSTGIS", connInfo));
189  trgDs->open();
190 
191  std::string outDSName = "identity_shptopgis_test";
192 
193  BOOST_REQUIRE_MESSAGE(
194  !trgDs->dataSetExists(outDSName),
195  "A dataset with the same requested output dataset name already exists: " +
196  outDSName);
197 
198  std::vector<te::vp::InputParams> inputParamsVec;
199  te::vp::InputParams structInputParams;
200  te::vp::InputParams structIntersectionParams;
201 
202  structInputParams.m_inputDataSource = srcInputDs;
203  structInputParams.m_inputDataSetType = input_DsetType.release();
204  structInputParams.m_inputDataSet = input_Dset.release();
205 
206  structIntersectionParams.m_inputDataSource = srcIntersectionDs;
207  structIntersectionParams.m_inputDataSetType = intersection_DsetType.release();
208  structIntersectionParams.m_inputDataSet = intersection_Dset.release();
209 
210  inputParamsVec.push_back(structInputParams);
211  inputParamsVec.push_back(structIntersectionParams);
212 
214  params->setInputParams(inputParamsVec);
215  params->setOutputDataSource(trgDs);
216  params->setOutputDataSetName(outDSName);
217  params->setSpecificParams(specificParams);
218 
219  te::vp::Identity identity;
220  BOOST_CHECK(identity.executeMemory(params));
221 
222  delete params;
223 
224  return;
225 }
226 
227 /* Tests with pgis as input and output */
228 BOOST_AUTO_TEST_CASE( identity_pgistopgis_test )
229 {
230  boost::uuids::basic_random_generator<boost::mt19937> gen;
231  boost::uuids::uuid u = gen();
232  std::string dsId = boost::uuids::to_string(u);
233 
234  std::string connInfo(
235  "ppgsql://postgres:postgres@atlas.dpi.inpe.br:5433/testPostGIS");
236 
237  te::da::DataSourcePtr srcDs(
238  te::da::DataSourceFactory::make("POSTGIS", connInfo));
239  srcDs->setId(dsId);
240 
242  dsInfoPtr->setId(dsId);
243  dsInfoPtr->setConnInfo(connInfo);
244  dsInfoPtr->setType("POSTGIS");
245 
247 
248  srcDs->open();
249 
250  std::string input_DsetName = "munic_goias";
251  std::string intersection_DsetName = "munic_goias_selected";
252 
253 
254  BOOST_REQUIRE_MESSAGE(srcDs->dataSetExists(input_DsetName),
255  "Input dataset not found: " + input_DsetName);
256 
257  std::unique_ptr<te::da::DataSet> input_Dset =
258  srcDs->getDataSet(input_DsetName);
259 
260  std::unique_ptr<te::da::DataSetType> input_DsetType =
261  srcDs->getDataSetType(input_DsetName);
262 
263  BOOST_REQUIRE_MESSAGE(srcDs->dataSetExists(intersection_DsetName),
264  "Input dataset not found: " + intersection_DsetName);
265 
266  std::unique_ptr<te::da::DataSet> intersection_Dset =
267  srcDs->getDataSet(intersection_DsetName);
268 
269  std::unique_ptr<te::da::DataSetType> intersection_DsetType =
270  srcDs->getDataSetType(intersection_DsetName);
271 
272  std::vector<std::string> attributes;
273  attributes.push_back("nome");
274  attributes.push_back("nomemeso");
275 
276  std::map<std::string, te::dt::AbstractData*> specificParams;
277  specificParams["public.munic_goias"] =
279  specificParams["public.munic_goias_selected"] =
281 
282  te::da::DataSourcePtr trgDs(
283  te::da::DataSourceFactory::make("POSTGIS", connInfo));
284  trgDs->open();
285 
286  std::string outDSName = "identity_pgistopgis_test";
287 
288  BOOST_REQUIRE_MESSAGE(
289  !trgDs->dataSetExists(outDSName),
290  "A dataset with the same requested output dataset name already exists: " +
291  outDSName);
292 
293  std::vector<te::vp::InputParams> inputParamsVec;
294  te::vp::InputParams structInputParams;
295  te::vp::InputParams structIntersectionParams;
296 
297  structInputParams.m_inputDataSource = srcDs;
298  structInputParams.m_inputDataSetType = input_DsetType.release();
299  structInputParams.m_inputDataSet = input_Dset.release();
300 
301  structIntersectionParams.m_inputDataSource = srcDs;
302  structIntersectionParams.m_inputDataSetType = intersection_DsetType.release();
303  structIntersectionParams.m_inputDataSet = intersection_Dset.release();
304 
305  inputParamsVec.push_back(structInputParams);
306  inputParamsVec.push_back(structIntersectionParams);
307 
309  params->setInputParams(inputParamsVec);
310  params->setOutputDataSource(trgDs);
311  params->setOutputDataSetName(outDSName);
312  params->setSpecificParams(specificParams);
313 
314  te::vp::Identity identity;
315  BOOST_CHECK(identity.executeMemory(params));
316 
317  delete params;
318 
319  return;
320 }
321 
322 /* Tests with pgis as input and shape as output */
323 BOOST_AUTO_TEST_CASE( identity_pgistoshp_test )
324 {
325  boost::uuids::basic_random_generator<boost::mt19937> gen;
326  boost::uuids::uuid u = gen();
327  std::string dsId = boost::uuids::to_string(u);
328 
329  std::string connInfo(
330  "ppgsql://postgres:postgres@atlas.dpi.inpe.br:5433/testPostGIS");
331 
332  te::da::DataSourcePtr srcDs(
333  te::da::DataSourceFactory::make("POSTGIS", connInfo));
334  srcDs->setId(dsId);
335 
337  dsInfoPtr->setId(dsId);
338  dsInfoPtr->setConnInfo(connInfo);
339  dsInfoPtr->setType("POSTGIS");
340 
342 
343  srcDs->open();
344 
345  std::string input_DsetName = "munic_goias";
346  std::string intersection_DsetName = "munic_goias_selected";
347 
348 
349  BOOST_REQUIRE_MESSAGE(srcDs->dataSetExists(input_DsetName),
350  "Input dataset not found: " + input_DsetName);
351 
352  std::unique_ptr<te::da::DataSet> input_Dset =
353  srcDs->getDataSet(input_DsetName);
354 
355  std::unique_ptr<te::da::DataSetType> input_DsetType =
356  srcDs->getDataSetType(input_DsetName);
357 
358  BOOST_REQUIRE_MESSAGE(srcDs->dataSetExists(intersection_DsetName),
359  "Input dataset not found: " + intersection_DsetName);
360 
361  std::unique_ptr<te::da::DataSet> intersection_Dset =
362  srcDs->getDataSet(intersection_DsetName);
363 
364  std::unique_ptr<te::da::DataSetType> intersection_DsetType =
365  srcDs->getDataSetType(intersection_DsetName);
366 
367  std::vector<std::string> attributes;
368  attributes.push_back("nome");
369  attributes.push_back("nomemeso");
370 
371  std::map<std::string, te::dt::AbstractData*> specificParams;
372  specificParams["public.munic_goias"] =
374  specificParams["public.munic_goias_selected"] =
376 
377  std::string data_dir = TERRALIB_DATA_DIR;
378  std::string output_filename(data_dir + "/shape/identity_pgistoshp_test.shp");
379  std::string tgrInfo ("file://" + output_filename);
380 
382  trgDs->open();
383 
384  std::string outDSName = "identity_pgistoshp_test";
385 
386  BOOST_REQUIRE_MESSAGE(
387  !trgDs->dataSetExists(outDSName),
388  "A dataset with the same requested output dataset name already exists: " +
389  outDSName);
390 
391  std::vector<te::vp::InputParams> inputParamsVec;
392  te::vp::InputParams structInputParams;
393  te::vp::InputParams structIntersectionParams;
394 
395  structInputParams.m_inputDataSource = srcDs;
396  structInputParams.m_inputDataSetType = input_DsetType.release();
397  structInputParams.m_inputDataSet = input_Dset.release();
398 
399  structIntersectionParams.m_inputDataSource = srcDs;
400  structIntersectionParams.m_inputDataSetType = intersection_DsetType.release();
401  structIntersectionParams.m_inputDataSet = intersection_Dset.release();
402 
403  inputParamsVec.push_back(structInputParams);
404  inputParamsVec.push_back(structIntersectionParams);
405 
407  params->setInputParams(inputParamsVec);
408  params->setOutputDataSource(trgDs);
409  params->setOutputDataSetName(outDSName);
410  params->setSpecificParams(specificParams);
411 
412  te::vp::Identity identity;
413  BOOST_CHECK(identity.executeMemory(params));
414 
415  delete params;
416 
417  return;
418 }
419 
420 BOOST_AUTO_TEST_SUITE_END()
Identity operation.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
A structure to hold the input parameters of vector processing.
Definition: InputParams.h:50
boost::shared_ptr< DataSource > DataSourcePtr
void setOutputDataSetName(const std::string &outputDataSetName)
te::da::DataSourcePtr m_inputDataSource
Is Required.
Definition: InputParams.h:81
void setOutputDataSource(te::da::DataSourcePtr outputDataSource)
BOOST_AUTO_TEST_CASE(identity_shptopgis_test)
Definition: TsIdentity.cpp:131
A singleton to keep all the registered data sources.
bool executeMemory(te::vp::AlgorithmParams *mainParams)
A template for complex data types.
Definition: ComplexData.h:52
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
A factory for data sources.
te::da::DataSetType * m_inputDataSetType
Is required.
Definition: InputParams.h:82
te::da::DataSet * m_inputDataSet
Is required for operations in memory.
Definition: InputParams.h:84
BOOST_AUTO_TEST_SUITE(identity_tests) BOOST_AUTO_TEST_CASE(identity_shptoshp_test)
Definition: TsIdentity.cpp:32
A class that represents a data source component.
void setInputParams(const std::vector< te::vp::InputParams > &setInputParams)
void setSpecificParams(const std::map< std::string, te::dt::AbstractData * > &specificParams)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr