src/terralib/vp/Dissolve.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 /*!
21  \file Dissolve.cpp
22  */
23 
24 #include "../core/logger/Logger.h"
25 #include "../common/progress/TaskProgress.h"
26 #include "../common/StringUtils.h"
27 #include "../common/STLUtils.h"
28 #include "../core/translator/Translator.h"
29 
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "../dataaccess/dataset/DataSetAdapter.h"
32 #include "../dataaccess/dataset/DataSetType.h"
33 #include "../dataaccess/dataset/DataSetTypeConverter.h"
34 #include "../dataaccess/dataset/ObjectIdSet.h"
35 #include "../dataaccess/datasource/DataSource.h"
36 #include "../dataaccess/datasource/DataSourceInfo.h"
37 #include "../dataaccess/datasource/DataSourceInfoManager.h"
38 #include "../dataaccess/datasource/DataSourceCapabilities.h"
39 #include "../dataaccess/datasource/DataSourceTransactor.h"
40 
41 #include "../dataaccess/query/Avg.h"
42 #include "../dataaccess/query/Cast.h"
43 #include "../dataaccess/query/Count.h"
44 #include "../dataaccess/query/Field.h"
45 #include "../dataaccess/query/Fields.h"
46 #include "../dataaccess/query/GroupBy.h"
47 #include "../dataaccess/query/GroupByItem.h"
48 #include "../dataaccess/query/Insert.h"
49 #include "../dataaccess/query/LiteralInt32.h"
50 #include "../dataaccess/query/Max.h"
51 #include "../dataaccess/query/Min.h"
52 #include "../dataaccess/query/PropertyName.h"
53 #include "../dataaccess/query/Select.h"
54 #include "../dataaccess/query/Sub.h"
55 #include "../dataaccess/query/SubSelect.h"
56 #include "../dataaccess/query/Sum.h"
57 #include "../dataaccess/query/ST_Dump.h"
58 #include "../dataaccess/query/ST_Multi.h"
59 #include "../dataaccess/query/ST_Union.h"
60 #include "../dataaccess/query/StdDev.h"
61 #include "../dataaccess/query/Variance.h"
62 
63 #include "../dataaccess/utils/Utils.h"
64 
65 #include "../datatype/Property.h"
66 #include "../datatype/SimpleData.h"
67 #include "../datatype/StringProperty.h"
68 
69 #include "../geometry/Geometry.h"
70 #include "../geometry/GeometryCollection.h"
71 #include "../geometry/GeometryProperty.h"
72 #include "../geometry/MultiLineString.h"
73 #include "../geometry/MultiPoint.h"
74 #include "../geometry/MultiPolygon.h"
75 #include "../geometry/Utils.h"
76 
77 #include "../memory/DataSet.h"
78 #include "../memory/DataSetItem.h"
79 
80 #include "../statistics/core/Utils.h"
81 
82 #include "AlgorithmParams.h"
83 #include "Dissolve.h"
84 #include "ComplexData.h"
85 #include "GroupThreadManager.h"
86 #include "Utils.h"
87 
88 // BOOST
89 #include <boost/algorithm/string.hpp>
90 #include <boost/thread.hpp>
91 
92 // STL
93 #include <iostream>
94 #include <memory>
95 #include <vector>
96 
97 std::vector<std::string> te::vp::GetDissolveProps(
98  const std::map<std::string, te::dt::AbstractData*>& specificParams)
99 {
100  std::vector<std::string> propNames;
101 
102  if (specificParams.empty())
103  return propNames;
104 
105  std::map<std::string, te::dt::AbstractData*>::const_iterator it = specificParams.begin();
106 
107  while (it != specificParams.end())
108  {
109  if (it->first != "DISSOLVE")
110  {
111  ++it;
112  continue;
113  }
114 
116  dynamic_cast<te::vp::ComplexData<std::vector<std::string> >* >(it->second);
117 
118  if (cd)
119  propNames = cd->getValue();
120 
121  ++it;
122  }
123 
124  return propNames;
125 }
126 
127 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >
129  const std::map<std::string, te::dt::AbstractData*>& specificParams)
130 {
131  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > statisticalSummaryMap;
132 
133  if (specificParams.empty())
134  return statisticalSummaryMap;
135 
136  std::map<std::string, te::dt::AbstractData*>::const_iterator it = specificParams.begin();
137 
138 
139  while (it != specificParams.end())
140  {
141  if (it->first != "SUMMARY")
142  {
143  ++it;
144  continue;
145  }
146 
147  te::vp::ComplexData<std::map<
148  te::dt::Property*, std::vector<te::stat::StatisticalSummary> > >* cd =
149  dynamic_cast<te::vp::ComplexData<std::map<
150  te::dt::Property*, std::vector<te::stat::StatisticalSummary> > >*>(
151  it->second);
152 
153  if (cd)
154  statisticalSummaryMap = cd->getValue();
155 
156  ++it;
157  }
158 
159  return statisticalSummaryMap;
160 }
161 
162 bool te::vp::IsCollection(const std::map<std::string, te::dt::AbstractData*>& specificParams)
163 {
164  bool isCollection = false;
165 
166  std::map<std::string, te::dt::AbstractData*>::const_iterator it = specificParams.begin();
167  while (it != specificParams.end())
168  {
169  if (it->first != "IS_COLLECTION")
170  {
171  ++it;
172  continue;
173  }
174 
176  dynamic_cast<te::dt::SimpleData<bool, te::dt::BOOLEAN_TYPE >* >(it->second);
177 
178  if (sd)
179  isCollection = sd->getValue();
180 
181  ++it;
182  }
183 
184  return isCollection;
185 }
186 
188 {
189  // Get the input parameters
190  std::vector<te::vp::InputParams> inputParams = mainParams->getInputParams();
191 
192  // Get the output dataset name.
193  std::string outputDataSetName = mainParams->getOutputDataSetName();
194  te::da::DataSetType* outputDataSetType = new te::da::DataSetType(outputDataSetName);
195 
196 
197  // Set to output datasettype the primary key property.
198  if (mainParams->getOutputDataSource()->getType() != "OGR")
199  {
200  te::dt::SimpleProperty* pkProperty = new te::dt::SimpleProperty(outputDataSetName + "_id", te::dt::INT32_TYPE);
201  pkProperty->setAutoNumber(true);
202  outputDataSetType->add(pkProperty);
203 
204  te::da::PrimaryKey* pk = new te::da::PrimaryKey(outputDataSetName + "_pk", outputDataSetType);
205  pk->add(pkProperty);
206  outputDataSetType->setPrimaryKey(pk);
207  }
208 
209 
210  // Get specific parameters.
211  te::da::DataSetType* dsType = nullptr;
212  if (inputParams[0].m_inputDataSetType)
213  {
214  dsType = inputParams[0].m_inputDataSetType;
215  }
216  else
217  {
218  dsType = te::da::GetDataSetType(inputParams[0].m_inputDataSetName, inputParams[0].m_inputDataSource->getId());
219  }
220 
221 
222  // Set the Attribute to do the dissolve.
223  const std::map<std::string, te::dt::AbstractData*>& specificParams = mainParams->getSpecificParams();
224  std::vector<std::string> propNames = GetDissolveProps(specificParams);
225 
226  for (std::size_t i = 0; i < propNames.size(); ++i)
227  {
228  te::dt::Property* prop = dsType->getProperty(propNames[i])->clone();
229  prop->setParent(nullptr);
230 
231  if (!prop)
232  continue;
233 
234  outputDataSetType->add(prop);
235  }
236 
237  // Verify if the output geometry type is multi or single geometry.
238  bool isCollection = IsCollection(specificParams);
239 
240  // Is not allow to compute summary function if the output geometry is single type.
241  if (isCollection)
242  {
243  // The number of dissolved objects.
244  te::dt::SimpleProperty* numDissolvedProperty = new te::dt::SimpleProperty("NUM_OBJ", te::dt::INT32_TYPE);
245  outputDataSetType->add(numDissolvedProperty);
246 
247 
248  // Set the Summary Attribute to do the dissolve.
249  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > summaryAtt = GetSummaryProps(specificParams);
250  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator itSummaryAtt = summaryAtt.begin();
251 
252  while (itSummaryAtt != summaryAtt.end())
253  {
254  std::vector<te::stat::StatisticalSummary> vectorResult = itSummaryAtt->second;
255 
256  int p_type = itSummaryAtt->first->getType();
257 
258  for (std::size_t s = 0; s < vectorResult.size(); ++s)
259  {
260  std::string attName = itSummaryAtt->first->getName();
261  attName += "_" + te::stat::GetStatSummaryShortName(vectorResult[s]);
262 
263  if (p_type == te::dt::STRING_TYPE || vectorResult[s] == te::stat::MODE)
264  {
266 
267  outputDataSetType->add(funcProp);
268  }
269  else
270  {
272 
273  outputDataSetType->add(funcProp);
274  }
275  }
276 
277  ++itSummaryAtt;
278  }
279  }
280 
281  // Creating the geometry property
282  te::gm::GeometryProperty* newGeomProp = new te::gm::GeometryProperty("geom");
283 
284  te::gm::GeometryProperty* intputGeomProp = te::da::GetFirstGeomProperty(dsType);
285 
286  te::gm::GeomType type = SetGeomResultType(intputGeomProp->getGeometryType(), isCollection);
287  newGeomProp->setGeometryType(type);
288  newGeomProp->setSRID(mainParams->getOutputSRID());
289 
290  outputDataSetType->add(newGeomProp);
291 
292  return outputDataSetType;
293 }
294 
295 te::gm::GeomType te::vp::SetGeomResultType(const te::gm::GeomType& geomType, const bool& isCollection)
296 {
297  if (isCollection)
298  {
299  if (te::gm::IsMultiType(geomType))
300  return geomType;
301  else
302  return te::gm::GetMultiType(geomType);
303  }
304  else
305  {
306  if (te::gm::IsMultiType(geomType))
307  return te::gm::GetSimpleType(geomType);
308  else
309  return geomType;
310  }
311 }
312 
313 std::vector<te::gm::Geometry*> te::vp::ExtractGeometry(
314  te::gm::Geometry& inputGeometry,
315  const te::gm::GeomType& outputGeomType)
316 {
317  std::vector<te::gm::Geometry*> extractGeometryVec;
318 
319  // Add geometry result in a vector, with the correct geometry type.
320  if (IsMultiType(outputGeomType))
321  {
322  std::unique_ptr<te::gm::Geometry> outputGeometry = nullptr;
323 
324  if (IsMultiType(inputGeometry.getGeomTypeId()))
325  outputGeometry.reset(dynamic_cast<te::gm::Geometry*>(inputGeometry.clone()));
326  else
327  outputGeometry.reset(SetGeomAsMulti(inputGeometry));
328 
329  if (outputGeometry->getGeomTypeId() == outputGeomType)
330  extractGeometryVec.push_back(outputGeometry.release());
331  }
332  else
333  {
334  if (IsMultiType(inputGeometry.getGeomTypeId()))
335  {
336  // It can return a vector with heterogeneous geometries.
337  te::gm::Multi2Single(&inputGeometry, extractGeometryVec);
338 
339  // It ensures that the geometries are of the same type
340  std::vector<te::gm::Geometry*>filteredGeometryVec;
341 
342  for (std::size_t i = 0; i < extractGeometryVec.size(); ++i)
343  {
344  if (extractGeometryVec[i]->getGeomTypeId() == outputGeomType)
345  {
346  filteredGeometryVec.push_back(extractGeometryVec[i]);
347  }
348  else
349  {
350  delete extractGeometryVec[i];
351  }
352  }
353 
354  extractGeometryVec = filteredGeometryVec;
355  }
356  else
357  {
358  if (inputGeometry.getGeomTypeId() == outputGeomType)
359  {
360  extractGeometryVec.push_back(dynamic_cast<te::gm::Geometry*>(inputGeometry.clone()));
361  }
362  }
363  }
364 
365  return extractGeometryVec;
366 }
367 
369  const te::da::DataSetType* inputDataSetType,
370  const std::vector<te::mem::DataSetItem*> inputItens,
371  const std::map<std::string, te::dt::AbstractData*> specificParams,
372  std::vector<te::mem::DataSetItem*>& outputItemVec)
373 {
374 // Populate dissolve properties.
375  std::vector<std::string> dissolvePropNames = GetDissolveProps(specificParams);
376 
377  for (std::size_t i = 0; i < dissolvePropNames.size(); ++i)
378  {
379  te::dt::Property* prop = inputDataSetType->getProperty(dissolvePropNames[i]);
380  std::size_t prop_position = inputDataSetType->getPropertyPosition(dissolvePropNames[i]);
381 
382  if (!prop)
383  continue;
384 
385  std::string propName = prop->getName();
386 
387  if (!inputItens[0]->isNull(prop_position))
388  {
389  for (std::size_t j = 0; j < outputItemVec.size(); ++j)
390  outputItemVec[j]->setValue(propName, inputItens[0]->getValue(prop_position)->clone());
391  }
392  }
393 
394 
395  bool isCollection = IsCollection(specificParams);
396 
397  if (isCollection)
398  {
399 // Populate Number of dissolved objects.
400  for (std::size_t n = 0; n < outputItemVec.size(); ++n)
401  outputItemVec[n]->setInt32("NUM_OBJ", (int)inputDataSetType->size());
402 
403 
404 // Get statistical summarization for the chosen attributes
405  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > summaryProps = GetSummaryProps(specificParams);
406  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::iterator summaryPropsIt = summaryProps.begin();
407 
408  while (summaryPropsIt != summaryProps.end())
409  {
410  te::dt::Property* currentProp = summaryPropsIt->first;
411 
412  std::string propertyName = currentProp->getName();
413 
414  std::size_t currentPropPosition = inputDataSetType->getPropertyPosition(propertyName);
415 
416  std::size_t numberOutputProps = outputItemVec[0]->getNumProperties();
417 
418  if (summaryPropsIt->first->getType() == te::dt::STRING_TYPE)
419  {
420  std::vector<std::string> inputValueStatSummary;
421 
422  for (std::size_t i = 0; i < inputItens.size(); ++i)
423  {
424  if (inputItens[i]->isNull(currentPropPosition))
425  continue;
426 
427  std::string valueString = inputItens[i]->getString(currentPropPosition);
428  inputValueStatSummary.push_back(valueString);
429  }
430 
432  te::stat::GetStringStatisticalSummary(inputValueStatSummary, ss);
433 
434  for (std::size_t p = 0; p < numberOutputProps; ++p)
435  {
436  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_MIN_VALUE")
437  outputItemVec[0]->setString(propertyName + "_MIN_VALUE", ss.m_minVal);
438 
439  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_MAX_VALUE")
440  outputItemVec[0]->setString(propertyName + "_MAX_VALUE", ss.m_maxVal);
441 
442  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_COUNT")
443  outputItemVec[0]->setString(propertyName + "_COUNT", boost::lexical_cast<std::string>(ss.m_count));
444 
445  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_VALID_COUNT")
446  outputItemVec[0]->setString(propertyName + "_VALID_COUNT", boost::lexical_cast<std::string>(ss.m_validCount));
447  }
448  }
449  else
450  {
451  std::vector<double> inputValueStatSummary;
452 
453  for (std::size_t i = 0; i < inputItens.size(); ++i)
454  {
455  if (inputItens[i]->isNull(currentPropPosition))
456  continue;
457 
458  double valueDouble;
459 
460  switch (currentProp->getType())
461  {
462  case te::dt::INT16_TYPE:
463  valueDouble = inputItens[i]->getInt16(currentPropPosition);
464  break;
465  case te::dt::INT32_TYPE:
466  valueDouble = inputItens[i]->getInt32(currentPropPosition);
467  break;
468  case te::dt::INT64_TYPE:
469  valueDouble = (double)inputItens[i]->getInt64(currentPropPosition);
470  break;
471  case te::dt::FLOAT_TYPE:
472  valueDouble = inputItens[i]->getFloat(currentPropPosition);
473  break;
474  case te::dt::DOUBLE_TYPE:
475  valueDouble = inputItens[i]->getDouble(currentPropPosition);
476  break;
477  default:
478  continue;
479  break;
480  }
481 
482  inputValueStatSummary.push_back(valueDouble);
483  }
484 
486  te::stat::GetNumericStatisticalSummary(inputValueStatSummary, ss);
487 
488  for (std::size_t p = 0; p < numberOutputProps; ++p)
489  {
490  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_MIN_VALUE")
491  outputItemVec[0]->setDouble(propertyName + "_MIN_VALUE", ss.m_minVal);
492 
493  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_MAX_VALUE")
494  outputItemVec[0]->setDouble(propertyName + "_MAX_VALUE", ss.m_maxVal);
495 
496  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_COUNT")
497  outputItemVec[0]->setDouble(propertyName + "_COUNT", ss.m_count);
498 
499  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_VALID_COUNT")
500  outputItemVec[0]->setDouble(propertyName + "_VALID_COUNT", ss.m_validCount);
501 
502  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_MEAN")
503  outputItemVec[0]->setDouble(propertyName + "_MEAN", ss.m_mean);
504 
505  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_SUM")
506  outputItemVec[0]->setDouble(propertyName + "_SUM", ss.m_sum);
507 
508  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_STANDARD_DEVIATION")
509  outputItemVec[0]->setDouble(propertyName + "_STANDARD_DEVIATION", ss.m_stdDeviation);
510 
511  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_VARIANCE")
512  outputItemVec[0]->setDouble(propertyName + "_VARIANCE", ss.m_variance);
513 
514  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_SKEWNESS")
515  outputItemVec[0]->setDouble(propertyName + "_SKEWNESS", ss.m_skewness);
516 
517  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_KURTOSIS")
518  outputItemVec[0]->setDouble(propertyName + "_KURTOSIS", ss.m_kurtosis);
519 
520  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_AMPLITUDE")
521  outputItemVec[0]->setDouble(propertyName + "_AMPLITUDE", ss.m_amplitude);
522 
523  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_MEDIAN")
524  outputItemVec[0]->setDouble(propertyName + "_MEDIAN", ss.m_median);
525 
526  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_VAR_COEFF")
527  outputItemVec[0]->setDouble(propertyName + "_VAR_COEFF", ss.m_varCoeff);
528 
529  if (outputItemVec[0]->getPropertyName(p) == propertyName + "_MODE")
530  {
531  std::string modeValues;
532 
533  if (!ss.m_mode.empty())
534  {
535  modeValues = boost::lexical_cast<std::string>(ss.m_mode[0]);
536  for (std::size_t i = 1; i < ss.m_mode.size(); ++i)
537  {
538  modeValues += ",";
539  modeValues += boost::lexical_cast<std::string>(ss.m_mode[i]);
540  }
541  }
542 
543  outputItemVec[0]->setString(propertyName + "_MODE", modeValues);
544 
545  }
546  }
547  }
548 
549  ++summaryPropsIt;
550  }
551  }
552 }
553 
554 te::vp::Dissolve::Dissolve() = default;
555 
557 {
558  // Validating parameters
559  std::vector<te::vp::InputParams> inputParams = mainParams->getInputParams();
560 
561  // Get DataSetType and Geometry Property of InputLayer Layer.
562  if (!inputParams[0].m_inputDataSetType)
563  throw te::common::Exception(TE_TR("It is necessary to set the DataSetType from Input Layer."));
564 
565  std::unique_ptr<te::da::DataSetType> dsType_input(inputParams[0].m_inputDataSetType);
566 
567 
568  // Verify if the operation has DataSet.
569  if (!inputParams[0].m_inputDataSet)
570  throw te::common::Exception(TE_TR("It is necessary to set the Input DataSet."));
571 
572  std::unique_ptr<te::da::DataSet>inputDataSet(inputParams[0].m_inputDataSet);
573 
574 
575  // Get Output DataSource.
576  if (!mainParams->getOutputDataSource())
577  throw te::common::Exception(TE_TR("It is necessary to set the Output DataSource."));
578 
579  te::da::DataSourcePtr outputDataSource = mainParams->getOutputDataSource();
580 
581  // Build output dataset type
582  std::unique_ptr<te::da::DataSetType> outputDataSetType(GetOutputDataSetType(mainParams));
583 
584  // Create output dataset in memory.
585  std::unique_ptr<te::mem::DataSet> outputDataSet(new te::mem::DataSet(outputDataSetType.get()));
586 
587  //Get specific parameters.
588  std::map<std::string, te::dt::AbstractData*> specificParams = mainParams->getSpecificParams();
589 
590  // Get attributes that composes the dissolve operation
591  std::vector<std::string> dissolveProps = GetDissolveProps(specificParams);
592  if (dissolveProps.empty())
593  throw te::common::Exception(TE_TR("Select at least one grouping attribute."));
594 
595  // Get the positions of the dissolve properties
596  std::vector<size_t> groupPropIdxs;
597 
598  for (std::size_t i = 0; i < dissolveProps.size(); ++i)
599  {
600  std::size_t position = dsType_input->getPropertyPosition(dissolveProps[i]);
601  if (position < dsType_input->size())
602  groupPropIdxs.push_back(position);
603  }
604 
605  // Creates groups to dissolve the geometries and calculate the statistical summary.
606  std::map<std::string, std::vector<int> > groups;
607  std::map<std::string, std::vector<int> >::iterator it_groups;
608 
609  int dataSetPos = 0;
610  inputDataSet->moveBeforeFirst();
611 
612  while (inputDataSet->move(dataSetPos))
613  {
614  std::string key;
615 
616  for (std::size_t i = 0; i < groupPropIdxs.size(); ++i)
617  {
618  if (inputDataSet->isNull(groupPropIdxs[i]))
619  {
620  std::string message = TE_TR("The selected attribute to aggregate has null values.");
621  mainParams->addWarning(message);
622 
623  TE_LOG_INFO(TE_TR("Vector Processing") + "- " + TE_TR("Dissolve") + ": " + message);
624  }
625  else
626  {
627  if (!key.empty())
628  key += "_";
629 
630  key += inputDataSet->getAsString(groupPropIdxs[i]);
631  }
632  }
633 
634  it_groups = groups.find(key);
635  if (it_groups == groups.end())
636  {
637  std::vector<int> dataSetPosVector;
638  dataSetPosVector.push_back(dataSetPos);
639  groups.insert(std::pair<std::string, std::vector<int> >(key, dataSetPosVector));
640  }
641  else
642  {
643  it_groups->second.push_back(dataSetPos);
644  }
645 
646  ++dataSetPos;
647  }
648 
649  TE_LOG_INFO(TE_TR("Vector Processing") + "- " + TE_TR("Dissolve") + ": " +
650  TE_TR("Started."));
651 
652  GroupThreadManager* manager = new GroupThreadManager(groups
653  , inputDataSet.get()
654  , dsType_input.get()
655  , outputDataSet.get()
656  , outputDataSetType.get()
657  , outputDataSource.get()
658  , specificParams);
659 
660  boost::thread_group threadGroup;
661  threadGroup.add_thread(new boost::thread(threadSave, manager));
662 
663  std::size_t numProcs = 8;
664  for (std::size_t i = 0; i < numProcs; ++i)
665  {
666  threadGroup.add_thread(new boost::thread(threadUnion, manager));
667  }
668 
669  threadGroup.join_all();
670 
671  // Get warnings from threads.
672  std::vector<std::string> threadWarnings = manager->getWarnings();
673  for (std::size_t w = 0; w < threadWarnings.size(); ++w)
674  {
675  mainParams->addWarning(threadWarnings[w]);
676  }
677 
678  delete manager;
679 
680  TE_LOG_INFO(TE_TR("Vector Processing") + "- " + TE_TR("Dissolve") + ": " +
681  TE_TR("Finalized."));
682 
683  return true;
684 }
685 
687 {
688 // Validating parameters
689  std::vector<te::vp::InputParams> inputParams = mainParams->getInputParams();
690 
691 
692 // Get DataSetType and Geometry Property of InputLayer Layer.
693  if (!inputParams[0].m_inputDataSetType)
694  throw te::common::Exception(TE_TR("It is necessary to set the DataSetType from Input Layer."));
695 
696  std::unique_ptr<te::da::DataSetType> dsType_input(inputParams[0].m_inputDataSetType);
697 
698  te::gm::GeometryProperty* geom_input = te::da::GetFirstGeomProperty(dsType_input.get());
699 
700  std::string aliasInput = dsType_input->getName();
701 
702 
703 // Verify if the operation has Query.
704  if (!inputParams[0].m_inputQuery)
705  throw te::common::Exception(TE_TR("It is necessary to set the Input Query."));
706 
707  te::da::Select* selectInput = inputParams[0].m_inputQuery;
708  te::da::SubSelect* subSelectInput = new te::da::SubSelect(selectInput, "inputLayer");
709  aliasInput = subSelectInput->getAlias();
710 
711 
712 // Fields represents the properties from layer to compose the select query.
713  te::da::Fields fields;
714 
715 // Get specift parameters.
716  const std::map<std::string, te::dt::AbstractData*>& specificParams = mainParams->getSpecificParams();
717 
718 // Get attributes to dissolve.
719  std::vector<std::string> dissolveAttributes = GetDissolveProps(specificParams);
720 
721  if (dissolveAttributes.size() < 1)
722  throw te::common::Exception(TE_TR("It is necessary to set at least one attribute to dissolve."));
723 
724  for (std::size_t d = 0; d < dissolveAttributes.size(); ++d)
725  {
726  te::da::Field* f_dissolveAtt = new te::da::Field(dissolveAttributes[d]);
727  fields.push_back(f_dissolveAtt);
728  }
729 
730  // Get geometry to spatial operation
731  bool isCollection = IsCollection(specificParams);
732 
733  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > summaryAttributes;
734 
735  if (isCollection)
736  {
737  // Number of objects in each group (mandatory)
738  te::da::Expression* e_aggCount = new te::da::Count(new te::da::PropertyName(dissolveAttributes[0]));
740 
741  te::da::Expression* e_cast = new te::da::Cast(e_aggCount, e_literalInt32);
742  te::da::Field* f_aggCount = new te::da::Field(*e_cast, "NUM_OBJ");
743  fields.push_back(f_aggCount);
744 
745 
746  // Get attributes to summary.
747  summaryAttributes = GetSummaryProps(specificParams);
748  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator itSummaryAtt = summaryAttributes.begin();
749 
750  while (itSummaryAtt != summaryAttributes.end())
751  {
752  std::vector<te::stat::StatisticalSummary>::const_iterator itFunc = itSummaryAtt->second.begin();
753  while (itFunc != itSummaryAtt->second.end())
754  {
755  te::da::PropertyName* p_name = new te::da::PropertyName(itSummaryAtt->first->getName());
756 
757  te::da::Field* s_field;
758  switch (*itFunc)
759  {
760  te::da::Expression *s_exp, *e_max, *e_min;
761 
763  {
764  s_exp = new te::da::Min(p_name);
765  s_field = new te::da::Field(*s_exp, p_name->getName() + "_MIN_VALUE");
766  }
767  break;
768 
770  {
771  s_exp = new te::da::Max(p_name);
772  s_field = new te::da::Field(*s_exp, p_name->getName() + "_MAX_VALUE");
773  }
774  break;
775 
777  {
778  s_exp = new te::da::Avg(p_name);
779  s_field = new te::da::Field(*s_exp, p_name->getName() + "_MEAN");
780  }
781  break;
782 
784  {
785  s_exp = new te::da::Sum(p_name);
786  s_field = new te::da::Field(*s_exp, p_name->getName() + "_SUM");
787  }
788 
789  break;
790 
792  {
793  te::da::Expression* countName = new te::da::PropertyName("*");
794  te::da::Expression* s_count = new te::da::Count(countName);
796  s_exp = new te::da::Cast(s_count, s_literalInt32);
797  s_field = new te::da::Field(*s_exp, p_name->getName() + "_COUNT");
798  }
799  break;
800 
802  {
803  te::da::Expression* s_vaidCount = new te::da::Count(p_name);
805  s_exp = new te::da::Cast(s_vaidCount, s_literalInt32);
806  s_field = new te::da::Field(*s_exp, p_name->getName() + "_VALID_COUNT");
807  }
808  break;
809 
811  {
812  s_exp = new te::da::StdDev(p_name);
813  s_field = new te::da::Field(*s_exp, p_name->getName() + "_STANDARD_DEVIATION");
814  }
815  break;
816 
818  {
819  s_exp = new te::da::Variance(p_name);
820  s_field = new te::da::Field(*s_exp, p_name->getName() + "_VARIANCE");
821  }
822  break;
823 
825  {
826  e_min = new te::da::Min(p_name);
827  e_max = new te::da::Max(p_name);
828  s_exp = new te::da::Sub(*e_max, *e_min);
829  s_field = new te::da::Field(*s_exp, p_name->getName() + "_AMPLITUDE");
830  }
831  break;
832 
833  default:
834  ++itFunc;
835  continue;
836  }
837 
838  fields.push_back(s_field);
839  ++itFunc;
840  }
841 
842  ++itSummaryAtt;
843  }
844  }
845 
846  te::da::Expression* e_union = new te::da::ST_Union(te::da::PropertyName(geom_input->getName()));
847  te::da::Expression* e_collection = nullptr;
848 
849  if (isCollection)
850  e_collection = new te::da::ST_Multi(*e_union);
851  else
852  e_collection = new te::da::ST_Dump(*e_union);
853 
854  te::da::Field* f_union = new te::da::Field(*e_collection, "geom");
855  fields.push_back(f_union);
856 
857 
858 // FROM clause - This from clause is for input layer.
859  if (!subSelectInput)
860  {
861  TE_LOG_INFO(TE_TR("Vector Processing") + "- " + TE_TR("Dissolve") + ": " +
862  TE_TR("A problem was found. SubSelect Input with problem."));
863 
864  throw te::common::Exception(TE_TR("A problem was found. SubSelect Input with problem."));
865  }
866 
867  te::da::From fromDissolve;
868  fromDissolve.push_back(subSelectInput);
869 
870  te::da::Select select(fields, fromDissolve);
871 
872 // Group by attribute to dissolve.
873  te::da::GroupBy* groupBy = new te::da::GroupBy();
874 
875  for (std::size_t i = 0; i < dissolveAttributes.size(); ++i)
876  {
877  te::da::GroupByItem* e_groupBy = new te::da::GroupByItem(dissolveAttributes[i]);
878  groupBy->push_back(e_groupBy);
879  }
880  select.setGroupBy(groupBy);
881 
882 
883 /*Check if the input and output dataSource are the same, if so,
884  persists the result of select query into database with insert command.*/
885  te::da::DataSourcePtr outputDataSource = mainParams->getOutputDataSource();
886 
887  te::da::DataSourceInfoPtr inDataSourceInfoPtr = te::da::DataSourceInfoManager::getInstance().get(inputParams[0].m_inputDataSource->getId());
888  te::da::DataSourceInfoPtr outDataSourceInfoPtr = te::da::DataSourceInfoManager::getInstance().get(outputDataSource->getId());
889 
890 // Create output dataset
891  std::unique_ptr<te::da::DataSourceTransactor> t = outputDataSource->getTransactor();
892  std::map<std::string, std::string> options;
893 
894 // Build output dataset type
895  std::unique_ptr<te::da::DataSetType> outputDataSetType(GetOutputDataSetType(mainParams));
896 
897  if (outputDataSource->getType() == "OGR")
898  {
899  outputDataSource->createDataSet(outputDataSetType.get(), options);
900  }
901  else
902  {
903  t->begin();
904  t->createDataSet(outputDataSetType.get(), options);
905  t->commit();
906 
907  if (!inDataSourceInfoPtr)
908  {
909  TE_LOG_INFO(TE_TR("Vector Processing") + "- " + TE_TR("Dissolve") + ": " +
910  TE_TR("Input DataSource ID not found."));
911 
912  t->rollBack();
913  throw te::common::Exception(TE_TR("Input DataSource ID not found."));
914  }
915 
916  if (!outDataSourceInfoPtr)
917  {
918  TE_LOG_INFO(TE_TR("Vector Processing") + "- " + TE_TR("Dissolve") + ": " +
919  TE_TR("Output DataSource ID not found."));
920 
921  t->rollBack();
922  throw te::common::Exception(TE_TR("Output DataSource ID not found."));
923  }
924  }
925 
926  std::string inputConnection = inDataSourceInfoPtr->getConnInfoAsString();
927 
928  std::string outputConnection;
929  if(outDataSourceInfoPtr.get())
930  outputConnection = outDataSourceInfoPtr->getConnInfoAsString();
931 
932 
933 // Execute Query
934  if (inputConnection == outputConnection)
935  {
936  te::da::Fields insertFields;
937 
938 // Add the dissolve attributes.
939  for (std::size_t p = 0; p < dissolveAttributes.size(); ++p)
940  {
941  te::da::Field* f_att = new te::da::Field(dissolveAttributes[p]);
942  insertFields.push_back(f_att);
943  }
944 
945  if (isCollection)
946  {
947  te::da::Field* f_numObj = new te::da::Field("NUM_OBJ");
948  insertFields.push_back(f_numObj);
949 
950  // Add summary attributes.
951  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator itInsert = summaryAttributes.begin();
952 
953  while (itInsert != summaryAttributes.end())
954  {
955  std::vector<te::stat::StatisticalSummary>::const_iterator itFunc = itInsert->second.begin();
956  while (itFunc != itInsert->second.end())
957  {
958  te::da::PropertyName* p_name = new te::da::PropertyName(itInsert->first->getName());
959 
960  te::da::Field* s_field;
961  switch (*itFunc)
962  {
964  s_field = new te::da::Field(p_name->getName() + "_MIN_VALUE");
965  break;
966 
968  s_field = new te::da::Field(p_name->getName() + "_MAX_VALUE");
969  break;
970 
972  s_field = new te::da::Field(p_name->getName() + "_MEAN");
973  break;
974 
976  s_field = new te::da::Field(p_name->getName() + "_SUM");
977  break;
978 
980  s_field = new te::da::Field(p_name->getName() + "_COUNT");
981  break;
982 
984  s_field = new te::da::Field(p_name->getName() + "_VALID_COUNT");
985  break;
986 
988  s_field = new te::da::Field(p_name->getName() + "_STANDARD_DEVIATION");
989  break;
990 
992  s_field = new te::da::Field(p_name->getName() + "_VARIANCE");
993  break;
994 
996  s_field = new te::da::Field(p_name->getName() + "_AMPLITUDE");
997  break;
998 
999  default:
1000  ++itFunc;
1001  continue;
1002  }
1003 
1004  insertFields.push_back(s_field);
1005  ++itFunc;
1006  }
1007 
1008  ++itInsert;
1009  }
1010  }
1011 
1012  te::da::Field* f_insert = new te::da::Field("geom");
1013  insertFields.push_back(f_insert);
1014 
1015  te::da::Insert* insert = new te::da::Insert(new te::da::DataSetName(mainParams->getOutputDataSetName()), &insertFields, &select);
1016  outputDataSource->execute(*insert);
1017  }
1018  else
1019  {
1020  std::unique_ptr<te::da::DataSet> dsQuery = inputParams[0].m_inputDataSource->query(select);
1021  dsQuery->moveBeforeFirst();
1022 
1023  if (dsQuery->size() == 0)
1024  {
1025  TE_LOG_INFO(TE_TR("Vector Processing") + "- " + TE_TR("Dissolve") + ": " +
1026  TE_TR("The resultant layer is empty!"));
1027 
1028  throw te::common::Exception(TE_TR("The resultant layer is empty!"));
1029  }
1030 
1031  std::string outputDsName = mainParams->getOutputDataSetName();
1032 
1033  if (outputDataSource->getType() == "OGR")
1034  {
1035  outputDataSource->add(outputDsName, dsQuery.get(), options);
1036  }
1037  else
1038  {
1039  t->add(outputDsName, dsQuery.get(), options);
1040  t->commit();
1041  }
1042  }
1043 
1044  return true;
1045 }
1046 
1048 {
1049 // Input
1050  te::da::DataSetType* dataSetType = manager->getDataSetType();
1051  te::gm::GeometryProperty* geomProp = te::da::GetFirstGeomProperty(dataSetType);
1052  std::size_t geomPos = dataSetType->getPropertyPosition(geomProp->getName());
1053 
1054 // Input vector itens
1055  std::vector<te::mem::DataSetItem*> dsItemVec;
1056 
1057 // Output
1058  te::da::DataSetType* outputDataSetType = manager->getOutputDataSetType();
1059 
1060  te::gm::GeometryProperty* outputGeomProp =
1061  te::da::GetFirstGeomProperty(outputDataSetType);
1062 
1063  std::size_t outputGeomPos =
1064  outputDataSetType->getPropertyPosition(outputGeomProp->getName());
1065 
1066 // Specific Params
1067  std::map<std::string, te::dt::AbstractData*> specificParams =
1068  manager->getSpecificParameters();
1069 
1070  while (manager->getNextGroup(dsItemVec))
1071  {
1072  std::vector<te::mem::DataSetItem*> outputItemVec;
1073 
1074  std::vector<te::gm::Geometry*> geomVec;
1075  for (std::size_t i = 0; i < dsItemVec.size(); ++i)
1076  {
1077  std::unique_ptr<te::gm::Geometry> geom = dsItemVec[i]->getGeometry(geomPos);
1078 
1079  geomVec.push_back(geom.release());
1080  }
1081 
1082  if(geomVec.empty())
1083  continue;
1084 
1085  // Output geometry.
1086  std::unique_ptr<te::gm::Geometry> unionGeometry;
1087  try
1088  {
1089  unionGeometry = te::gm::GetGeometryUnion(geomVec);
1090 
1091  te::common::FreeContents(geomVec);
1092 
1093  if(unionGeometry == nullptr)
1094  {
1095  std::string message = TE_TR("Vector Processing") + std::string(" - ") +
1096  TE_TR("Dissolve") + std::string(": ") +
1097  TE_TR("The result of a to dissolved group returned an empty geometry. Check the log file.");
1098  manager->addWarning(message);
1099 
1100  TE_LOG_ERROR(message);
1101 
1102  continue;
1103  }
1104 
1105  }
1106  catch (const te::common::Exception& e)
1107  {
1108  te::common::FreeContents(geomVec);
1109 
1110  std::string message = TE_TR("Vector Processing") + std::string(" - ") +
1111  TE_TR("Dissolve") + std::string(": ") +
1112  TE_TR("GEOS Exception") + std::string(": ");
1113  message += e.what();
1114 
1115  manager->addWarning(message);
1116 
1117  manager->addOutput(outputItemVec);
1118 
1119  TE_LOG_ERROR(message);
1120 
1121  continue;
1122  }
1123  catch(...)
1124  {
1125  te::common::FreeContents(geomVec);
1126 
1127  std::string message = TE_TR("Vector Processing") + std::string(" - ") +
1128  TE_TR("Dissolve") + std::string(": ") +
1129  TE_TR("Unknown Excption.");
1130 
1131  manager->addWarning(message);
1132 
1133  manager->addOutput(outputItemVec);
1134 
1135  TE_LOG_ERROR(message);
1136 
1137  continue;
1138  }
1139 
1140  //Extract geometry result.
1141  std::vector<te::gm::Geometry*> geometryResultVec =
1142  ExtractGeometry(*unionGeometry.get(), outputGeomProp->getGeometryType());
1143 
1144  // Ouput Item
1145  for (std::size_t g = 0; g < geometryResultVec.size(); ++g)
1146  {
1147  te::mem::DataSetItem* item = manager->createOutputItem();
1148 
1149  item->setGeometry(outputGeomPos, geometryResultVec[g]);
1150 
1151  outputItemVec.push_back(item);
1152  }
1153 
1154  PopulateItems(dataSetType, dsItemVec, specificParams, outputItemVec);
1155 
1156  manager->addOutput(outputItemVec);
1157 
1158  geomVec.clear();
1159  }
1160 }
1161 
1163 {
1164  te::da::DataSource* outputDataSource = manager->getOutputDataSource();
1165  te::da::DataSetType* outputDataType = manager->getOutputDataSetType();
1166 
1167  std::vector<te::mem::DataSetItem*> outputItemVec;
1168  while (manager->getNextOutput(outputItemVec))
1169  {
1170  //save the data
1171  if (outputItemVec.empty())
1172  {
1173  boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
1174  continue;
1175  }
1176 
1177  //Create a empty dataSet.
1178  te::mem::DataSet* outputDataSet = manager->getClearOutputDataSet();
1179 
1180  //Popular o dataSet
1181  for (std::size_t i = 0; i < outputItemVec.size(); ++i)
1182  {
1183  outputDataSet->add(outputItemVec[i]);
1184  }
1185 
1186  // Persiste
1187  te::da::DataSet* dataSetPrepared = PrepareAdd(outputDataSet, outputDataType).release();
1188 
1189  if (!dataSetPrepared)
1190  {
1191  manager->addWarning("Output DataSet was not prepared to save.");
1192 
1193  TE_LOG_INFO(TE_TR("Vector Processing") + "- " + TE_TR("Dissolve") + ": " +
1194  TE_TR("Output DataSet was not prepared to save."));
1195  }
1196 
1197  if (dataSetPrepared->isEmpty())
1198  {
1199  manager->addWarning("The resultant layer is empty!");
1200 
1201  TE_LOG_INFO(TE_TR("Vector Processing") + "- " + TE_TR("Dissolve") + ": " +
1202  TE_TR("The resultant layer is empty!"));
1203  }
1204 
1205  Save(outputDataSource, dataSetPrepared, outputDataType, false);
1206  outputItemVec.clear();
1207  }
1208 
1209  manager->getClearOutputDataSet();
1210 }
1211 
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
Property * getProperty(std::size_t i) const
It returns the i-th property.
te::da::DataSetType * getDataSetType()
const std::string & getName() const
It returns the property name.
Dissolve operation.
boost::ptr_vector< GroupByItem > GroupBy
A class that can be used to model a GROUP BY clause.
Definition: GroupBy.h:37
Geometric property.
A structure to hold the set of statistics from a set of numerical values.
TEVPEXPORT std::unique_ptr< te::da::DataSet > PrepareAdd(te::da::DataSet *ds, te::da::DataSetType *dt)
void addOutput(std::vector< te::mem::DataSetItem * > &itemGroup)
te::da::DataSetType * GetOutputDataSetType(te::vp::AlgorithmParams *mainParams)
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
te::mem::DataSetItem * createOutputItem()
A class that can be used in a GROUP BY clause.
Definition: GroupByItem.h:50
The Field class can be used to model an expression that takes part of the output items of a SELECT...
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
An atomic property like an integer or double.
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the name of any property of an object.
A class that models the description of a dataset.
Definition: DataSetType.h:72
TEGEOMEXPORT te::gm::GeomType GetMultiType(te::gm::GeomType geomType)
Get the collection type of GeomType.
virtual const char * what() const
It outputs the exception message.
TEMNTEXPORT te::gm::Point Max(te::gm::Point &p1, te::gm::Point &p2)
std::vector< std::string > GetDissolveProps(const std::map< std::string, te::dt::AbstractData * > &specificParams)
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
bool executeQuery(te::vp::AlgorithmParams *mainParams)
Spatial multi operator.
Definition: ST_Multi.h:50
TESTATEXPORT std::string GetStatSummaryShortName(const int &e)
Get the statistical parameter short name from its enumerator.
Count statistical function.
Definition: Count.h:46
TEGEOMEXPORT bool IsMultiType(te::gm::GeomType geomType)
Verifies if the geomType is a collection type.
std::vector< te::vp::InputParams > getInputParams()
T getValue() const
It returns the associated value.
Definition: SimpleData.h:139
TEGEOMEXPORT std::unique_ptr< te::gm::Geometry > GetGeometryUnion(const std::vector< te::gm::Geometry * > &geomVec)
It returns the union of a geometry vector.
TEGEOMEXPORT te::gm::GeomType GetSimpleType(te::gm::GeomType geomType)
Get the simple type of GeomType.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
bool getNextOutput(std::vector< te::mem::DataSetItem * > &nextOutput)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
Algorithm Parameters.
virtual Property * clone() const =0
It returns a clone of the object.
#define TE_LOG_INFO(message)
Use this tag in order to log a message to the TerraLib default logger with the INFO level...
Definition: Logger.h:315
The Insert object can add the return of a select object.
Definition: Insert.h:50
TEGEOMEXPORT void Multi2Single(const te::gm::Geometry *g, std::vector< te::gm::Geometry * > &geoms)
It will get a GeometryCollection and distribute in a vector.
Class to manager group values in threads.
It models a property definition.
Definition: Property.h:59
Avg statistical function.
Definition: Avg.h:46
te::gm::GeomType SetGeomResultType(const te::gm::GeomType &geomType, const bool &isCollection)
static void threadSave(GroupThreadManager *manager)
T getValue() const
It returns the associated value.
Definition: ComplexData.h:129
This is an abstract class that models a query expression.
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
StdDev statistical function.
Definition: StdDev.h:46
static void threadUnion(GroupThreadManager *manager)
TEVPEXPORT void Save(te::da::DataSource *source, te::da::DataSet *result, te::da::DataSetType *outDsType, const bool &enableProgress=true)
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
virtual bool isEmpty() const =0
It returns true if the collection is empty.
TESAEXPORT double Sum(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx)
Function used to calculate sum of a specific attribute from a gpm.
A template for complex data types.
Definition: ComplexData.h:52
void PopulateItems(const te::da::DataSetType *inputDataSetType, const std::vector< te::mem::DataSetItem * > inputItens, const std::map< std::string, te::dt::AbstractData * > specificParams, std::vector< te::mem::DataSetItem * > &outputItemVec)
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
const std::string & getOutputDataSetName()
bool executeMemory(te::vp::AlgorithmParams *mainParams)
const std::string & getAlias() const
It returns the alias associated to the source item.
Definition: FromItem.cpp:47
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Definition: Fields.h:37
TESTATEXPORT void GetNumericStatisticalSummary(std::vector< double > &values, te::stat::NumericStatisticalSummary &ss, double nullValue)
te::gm::Polygon * p
virtual AbstractData * clone() const =0
It returns a clone of this object.
te::da::DataSourcePtr getOutputDataSource()
The type for string types: FIXED_STRING, VAR_STRING or STRING.
const std::map< std::string, te::dt::AbstractData * > & getSpecificParams()
std::size_t size() const
It returns the number of properties of the CompositeProperty.
line< nLines;++line) for(col=0;col< nCols;++col){rasterPointer-> setValue(col, line, pixelValue, band)
Utility functions for the data access module.
void setGroupBy(GroupBy *g)
It sets the list of expressions used to condense the result set.
Definition: Select.cpp:809
ST_Dump statistical function.
Definition: ST_Dump.h:46
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
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.
Definition: Select.h:65
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
std::map< te::dt::Property *, std::vector< te::stat::StatisticalSummary > > GetSummaryProps(const std::map< std::string, te::dt::AbstractData * > &specificParams)
int getType() const
It returns the property data type.
Definition: Property.h:161
void add(Constraint *c)
It adds a new constraint.
std::vector< std::string > getWarnings()
TESTATEXPORT void GetStringStatisticalSummary(std::vector< std::string > &values, te::stat::StringStatisticalSummary &ss, const std::string &nullValue)
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
A dataset is the unit of information manipulated by the data access module of TerraLib.
void addWarning(const std::string &warning, const bool &appendIfExist=false)
te::da::DataSetType * getOutputDataSetType()
The subtraction operator.
A structure to hold the set of statistics from a set of categorical (sample) values.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
Variance statistical function.
Definition: Variance.h:46
bool getNextGroup(std::vector< te::mem::DataSetItem * > &nextGroup)
Cast a expression function.
Definition: Cast.h:46
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
Definition: Logger.h:337
std::size_t getPropertyPosition(const std::string &name) const
It returns the property position based on its name.
ST_Union statistical function.
Definition: ST_Union.h:46
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
TEMNTEXPORT te::gm::Point Min(te::gm::Point &p1, te::gm::Point &p2)
te::mem::DataSet * getClearOutputDataSet()
void addWarning(const std::string &warning, const bool &appendIfExists=false)
A template for atomic data types (integers, floats, strings and others).
Definition: SimpleData.h:59
A Select can be used as a source of information in another query.
Definition: SubSelect.h:49
std::vector< te::gm::Geometry * > ExtractGeometry(te::gm::Geometry &inputGeometry, const te::gm::GeomType &outputGeomType)
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
te::da::DataSource * getOutputDataSource()
TEVPEXPORT te::gm::Geometry * SetGeomAsMulti(const te::gm::Geometry &geom)
std::map< std::string, te::dt::AbstractData * > getSpecificParameters()
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
bool IsCollection(const std::map< std::string, te::dt::AbstractData * > &specificParams)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
void setParent(Property *p)
It associate this property to the informed parent.
Definition: Property.h:177