All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GeometricOpQuery.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 AggregationQuery.h
22 
23  \brief Aggregation Vector Processing functions.
24 */
25 
26 //Terralib
27 
28 #include "terralib_config.h"
29 #include "../common/progress/TaskProgress.h"
30 #include "../common/Logger.h"
31 #include "../common/Translator.h"
32 
33 #include "../dataaccess/dataset/DataSet.h"
34 
35 #include "../datatype/Property.h"
36 #include "../datatype/SimpleProperty.h"
37 #include "../datatype/StringProperty.h"
38 
39 #include "../dataaccess/query/Avg.h"
40 #include "../dataaccess/query/Count.h"
41 #include "../dataaccess/query/DataSetName.h"
42 #include "../dataaccess/query/Expression.h"
43 #include "../dataaccess/query/Field.h"
44 #include "../dataaccess/query/Fields.h"
45 #include "../dataaccess/query/From.h"
46 #include "../dataaccess/query/FromItem.h"
47 #include "../dataaccess/query/GroupBy.h"
48 #include "../dataaccess/query/GroupByItem.h"
49 #include "../dataaccess/query/Literal.h"
50 #include "../dataaccess/query/LiteralBool.h"
51 #include "../dataaccess/query/PropertyName.h"
52 #include "../dataaccess/query/Select.h"
53 #include "../dataaccess/query/ST_Area.h"
54 #include "../dataaccess/query/ST_Centroid.h"
55 #include "../dataaccess/query/ST_ConvexHull.h"
56 #include "../dataaccess/query/ST_Envelope.h"
57 #include "../dataaccess/query/ST_Length.h"
58 #include "../dataaccess/query/ST_Perimeter.h"
59 #include "../dataaccess/query/ST_Union.h"
60 #include "../dataaccess/query/Variance.h"
61 #include "../dataaccess/utils/Utils.h"
62 
63 #include "../geometry/Geometry.h"
64 #include "../geometry/GeometryCollection.h"
65 #include "../geometry/GeometryProperty.h"
66 #include "../geometry/Utils.h"
67 
68 #include "../memory/DataSet.h"
69 #include "../memory/DataSetItem.h"
70 
71 #include "../statistics/core/SummaryFunctions.h"
72 #include "../statistics/core/StringStatisticalSummary.h"
73 #include "../statistics/core/NumericStatisticalSummary.h"
74 
75 #include "GeometricOpQuery.h"
76 #include "Config.h"
77 #include "Exception.h"
78 #include "Utils.h"
79 
80 // STL
81 #include <map>
82 #include <math.h>
83 #include <string>
84 #include <vector>
85 
86 // BOOST
87 #include <boost/lexical_cast.hpp>
88 #include <boost/algorithm/string.hpp>
89 
91 {}
92 
94 {}
95 
96 bool te::vp::GeometricOpQuery::run() throw(te::common::Exception)
97 {
98 // get the geometric operation and/or tabular operation.
99  std::vector<int> opGeom;
100  std::vector<int> opTab;
101  std::vector<te::da::DataSetType*> dsTypeVec;
102 
103  for(std::size_t i = 0; i < m_operations.size(); ++i)
104  {
105  switch(m_operations[i])
106  {
107  case te::vp::CENTROID:
108  opGeom.push_back(te::vp::CENTROID);
109  break;
110  case te::vp::CONVEX_HULL:
111  opGeom.push_back(te::vp::CONVEX_HULL);
112  break;
113  case te::vp::MBR:
114  opGeom.push_back(te::vp::MBR);
115  break;
116  case te::vp::AREA:
117  opTab.push_back(te::vp::AREA);
118  break;
119  case te::vp::LINE:
120  opTab.push_back(te::vp::LINE);
121  break;
122  case te::vp::PERIMETER:
123  opTab.push_back(te::vp::PERIMETER);
124  break;
125  default:
126  {
127 #ifdef TERRALIB_LOGGER_ENABLED
128  te::common::Logger::logDebug("vp", "Geometric Operation - The operation is not valid.");
129 #endif //TERRALIB_LOGGER_ENABLED
130  }
131  }
132  }
133 
134  if(m_outputLayer)
135  {
136  bool hasMultiGeomColumns = false;
137  bool result = false;
138 
139  switch(m_objStrategy)
140  {
141  case te::vp::ALL_OBJ:
142  {
143  if(hasMultiGeomColumns) //Condição se o DataSource suporta mais de uma soluna geometrica...
144  {
145  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::ALL_OBJ, true));
146  }
147  else
148  {
149  if(opGeom.size() > 0)
150  {
151  for(std::size_t i = 0; i < opGeom.size(); ++i)
152  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::ALL_OBJ, false, opGeom[i]));
153  }
154  else
155  {
156  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::ALL_OBJ, false));
157  }
158  }
159 
160  for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
161  {
162  m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
163 
164  std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
165  std::auto_ptr<te::mem::DataSet> outDataSet(SetAllObjects(dsTypeVec[dsTypePos], opTab, opGeom));
166 
167  te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
168  result = true;
169 
170  if(!result)
171  return result;
172  }
173  }
174  break;
175  case te::vp::AGGREG_OBJ:
176  {
177  if(hasMultiGeomColumns) //Condição se o DataSource suporta mais de uma coluna geometrica...
178  {
179  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::AGGREG_OBJ, true));
180  }
181  else
182  {
183  if(opGeom.size() > 0)
184  {
185  for(std::size_t i = 0; i < opGeom.size(); ++i)
186  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::AGGREG_OBJ, false, opGeom[i]));
187  }
188  else
189  {
190  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::AGGREG_OBJ, false));
191  }
192  }
193 
194  for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
195  {
196  m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
197 
198  std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
199  std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregObj(dsTypeVec[dsTypePos], opTab, opGeom));
200  try
201  {
202  te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
203  result = true;
204  }
205  catch(...)
206  {
207  result = false;
208  }
209  if(!result)
210  return result;
211  }
212  }
213  break;
215  {
216  if(hasMultiGeomColumns) //Condição se o DataSource suporta mais de uma coluna geometrica...
217  {
219  }
220  else
221  {
222  if(opGeom.size() > 0)
223  {
224  for(std::size_t i = 0; i < opGeom.size(); ++i)
225  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::AGGREG_BY_ATTRIBUTE, false, opGeom[i]));
226  }
227  else
228  {
230  }
231  }
232 
233  for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
234  {
235  m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
236 
237  std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
238  std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregByAttribute(dsTypeVec[dsTypePos], opTab, opGeom));
239  try
240  {
241  te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
242  result = true;
243  }
244  catch(...)
245  {
246  result = false;
247  }
248  if(!result)
249  return result;
250  }
251  }
252  break;
253  default:
254  {
255 #ifdef TERRALIB_LOGGER_ENABLED
256  te::common::Logger::logDebug("vp", "Geometric Operation - Strategy Not found!");
257 #endif //TERRALIB_LOGGER_ENABLED
258  }
259  return false;
260  }
261 
262  return result;
263 
264  }
265  else
266  {
267  //Descobrir se o DataSource suporta adição de mais de uma coluna geometrica.
268  return false;
269  }
270 
271  return false;
272 }
273 
275  std::vector<int> tabVec,
276  std::vector<int> geoVec)
277 {
278  std::auto_ptr<te::mem::DataSet> outDSet(new te::mem::DataSet(dsType));
279  std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
280  std::size_t geom_pos = te::da::GetFirstSpatialPropertyPos(inDset.get());
281 
282  te::da::Fields* fields = new te::da::Fields;
283 
284  if(m_selectedProps.size() > 0)
285  {
286  for(std::size_t prop_pos = 0; prop_pos < m_selectedProps.size(); ++prop_pos)
287  {
288  te::da::Field* f_prop = new te::da::Field(m_selectedProps[prop_pos]);
289  fields->push_back(f_prop);
290  }
291  }
292 
293  std::string name = inDset->getPropertyName(geom_pos);
294 
295  if(tabVec.size() > 0)
296  {
297  for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
298  {
299  te::da::Expression* ex;
300  te::da::Field* f;
301 
302  switch(tabVec[tabPos])
303  {
304  case te::vp::AREA:
305  {
306  ex = new te::da::ST_Area(te::da::PropertyName(name));
307  f = new te::da::Field(*ex, "area");
308  fields->push_back(f);
309  }
310  break;
311  case te::vp::LINE:
312  {
313  ex = new te::da::ST_Length(te::da::PropertyName(name));
314  f = new te::da::Field(*ex, "line_length");
315  fields->push_back(f);
316  }
317  break;
318  case te::vp::PERIMETER:
319  {
321  f = new te::da::Field(*ex, "perimeter");
322  fields->push_back(f);
323  }
324  break;
325  default:
326  {
327 #ifdef TERRALIB_LOGGER_ENABLED
328  te::common::Logger::logDebug("vp", "Geometric Operation - Invalid field to add in query.");
329 #endif //TERRALIB_LOGGER_ENABLED
330  }
331  }
332  }
333  }
334 
335  if(geoVec.size() > 0)
336  {
337  for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
338  {
339  te::da::Expression* ex_geom;
340  te::da::Field* f_geom;
341 
342  switch(geoVec[geoPos])
343  {
344  case te::vp::CONVEX_HULL:
345  {
346  std::size_t pos = dsType->getPropertyPosition("convex_hull");
347  if( pos < outDSet->getNumProperties() && pos > 0)
348  {
349  ex_geom = new te::da::ST_ConvexHull(te::da::PropertyName(name));
350  f_geom = new te::da::Field(*ex_geom, "convex_hull");
351  fields->push_back(f_geom);
352  }
353  }
354  break;
355  case te::vp::CENTROID:
356  {
357  std::size_t pos = dsType->getPropertyPosition("centroid");
358  if( pos < outDSet->getNumProperties() && pos > 0)
359  {
360  ex_geom = new te::da::ST_Centroid(te::da::PropertyName(name));
361  f_geom = new te::da::Field(*ex_geom, "centroid");
362  fields->push_back(f_geom);
363  }
364  }
365  break;
366  case te::vp::MBR:
367  {
368  std::size_t pos = dsType->getPropertyPosition("mbr");
369  if( pos < outDSet->getNumProperties() && pos > 0)
370  {
371  ex_geom = new te::da::ST_Envelope(te::da::PropertyName(name));
372  f_geom = new te::da::Field(*ex_geom, "mbr");
373  fields->push_back(f_geom);
374  }
375  }
376  break;
377  default:
378  {
379 #ifdef TERRALIB_LOGGER_ENABLED
380  te::common::Logger::logDebug("vp", "Geometric Operation - Invalid field to add in query.");
381 #endif //TERRALIB_LOGGER_ENABLED
382  }
383  }
384  }
385  }
386  else
387  {
388  te::da::Field* f_prop = new te::da::Field(name);
389  fields->push_back(f_prop);
390  }
391 
392  te::da::FromItem* fromItem = new te::da::DataSetName(m_inDsetType->getName());
393  te::da::From* from = new te::da::From;
394  from->push_back(fromItem);
395 
396  te::da::Select select(fields, from);
397 
398  std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(select);
399 
400  if (dsQuery->isEmpty())
401  return false;
402 
403  SetOutputDSet(dsQuery.get(), outDSet.get());
404 
405  return outDSet.release();
406 }
407 
409  std::vector<int> tabVec,
410  std::vector<int> geoVec)
411 {
412  std::auto_ptr<te::mem::DataSet> outDSet(new te::mem::DataSet(dsType));
413 
414  std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
415  std::size_t geom_pos = te::da::GetFirstSpatialPropertyPos(inDset.get());
416  std::string name = inDset->getPropertyName(geom_pos);
417 
418  te::da::Fields* fields = new te::da::Fields;
419 
420  if(tabVec.size() > 0)
421  {
422  for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
423  {
424  te::da::Expression* ex;
425  te::da::Field* f;
426 
427  switch(tabVec[tabPos])
428  {
429  case te::vp::AREA:
430  {
432  ex = new te::da::ST_Area(*e_union);
433  f = new te::da::Field(*ex, "area");
434  fields->push_back(f);
435  }
436  break;
437  case te::vp::LINE:
438  {
440  ex = new te::da::ST_Length(*e_union);
441  f = new te::da::Field(*ex, "line_length");
442  fields->push_back(f);
443  }
444  break;
445  case te::vp::PERIMETER:
446  {
448  ex = new te::da::ST_Perimeter(*e_union);
449  f = new te::da::Field(*ex, "perimeter");
450  fields->push_back(f);
451  }
452  break;
453  default:
454  {
455 #ifdef TERRALIB_LOGGER_ENABLED
456  te::common::Logger::logDebug("vp", "Geometric Operation - Invalid field to add in query.");
457 #endif //TERRALIB_LOGGER_ENABLED
458  }
459  }
460  }
461  }
462 
463  if(geoVec.size() > 0)
464  {
465  for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
466  {
467  te::da::Expression* ex_geom;
468  te::da::Field* f_geom;
469 
470  switch(geoVec[geoPos])
471  {
472  case te::vp::CONVEX_HULL:
473  {
474  std::size_t pos = dsType->getPropertyPosition("convex_hull");
475  if( pos < outDSet->getNumProperties() && pos > 0)
476  {
478  ex_geom = new te::da::ST_ConvexHull(*e_union);
479  f_geom = new te::da::Field(*ex_geom, "convex_hull");
480  fields->push_back(f_geom);
481  }
482  }
483  break;
484  case te::vp::CENTROID:
485  {
486  std::size_t pos = dsType->getPropertyPosition("centroid");
487  if( pos < outDSet->getNumProperties() && pos > 0)
488  {
490  ex_geom = new te::da::ST_Centroid(*e_union);
491  f_geom = new te::da::Field(*ex_geom, "centroid");
492  fields->push_back(f_geom);
493  }
494  }
495  break;
496  case te::vp::MBR:
497  {
498  std::size_t pos = dsType->getPropertyPosition("mbr");
499  if( pos < outDSet->getNumProperties() && pos > 0)
500  {
502  ex_geom = new te::da::ST_Envelope(*e_union);
503  f_geom = new te::da::Field(*ex_geom, "mbr");
504  fields->push_back(f_geom);
505  }
506  }
507  break;
508  default:
509  {
510 #ifdef TERRALIB_LOGGER_ENABLED
511  te::common::Logger::logDebug("vp", "Geometric Operation - Invalid field to add in query.");
512 #endif //TERRALIB_LOGGER_ENABLED
513  }
514  }
515  }
516  }
517  else
518  {
520  te::da::Field* f_prop = new te::da::Field(*e_union, name);
521  fields->push_back(f_prop);
522  }
523 
524  te::da::FromItem* fromItem = new te::da::DataSetName(m_inDsetType->getName());
525  te::da::From* from = new te::da::From;
526  from->push_back(fromItem);
527 
528  te::da::Select select(fields, from);
529 
530  std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(select);
531 
532  if (dsQuery->isEmpty())
533  return false;
534 
535  SetOutputDSet(dsQuery.get(), outDSet.get());
536 
537  return outDSet.release();
538 }
539 
541  std::vector<int> tabVec,
542  std::vector<int> geoVec)
543 {
544  std::auto_ptr<te::mem::DataSet> outDSet(new te::mem::DataSet(dsType));
545  std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
546  std::size_t geom_pos = te::da::GetFirstSpatialPropertyPos(inDset.get());
547  std::string name = inDset->getPropertyName(geom_pos);
548 
549  te::da::Fields* fields = new te::da::Fields;
550 
551  te::da::Field* f_aggreg = new te::da::Field(m_attribute);
552  fields->push_back(f_aggreg);
553 
554  if(tabVec.size() > 0)
555  {
556  for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
557  {
558  te::da::Expression* ex;
559  te::da::Field* f;
560 
561  switch(tabVec[tabPos])
562  {
563  case te::vp::AREA:
564  {
566  ex = new te::da::ST_Area(*e_union);
567  f = new te::da::Field(*ex, "area");
568  fields->push_back(f);
569  }
570  break;
571  case te::vp::LINE:
572  {
574  ex = new te::da::ST_Length(*e_union);
575  f = new te::da::Field(*ex, "line_length");
576  fields->push_back(f);
577  }
578  break;
579  case te::vp::PERIMETER:
580  {
582  ex = new te::da::ST_Perimeter(*e_union);
583  f = new te::da::Field(*ex, "perimeter");
584  fields->push_back(f);
585  }
586  break;
587  default:
588  {
589 #ifdef TERRALIB_LOGGER_ENABLED
590  te::common::Logger::logDebug("vp", "Geometric Operation - Invalid field to add in query.");
591 #endif //TERRALIB_LOGGER_ENABLED
592  }
593  }
594  }
595  }
596 
597  if(geoVec.size() > 0)
598  {
599  for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
600  {
601  te::da::Expression* ex_geom;
602  te::da::Field* f_geom;
603 
604  switch(geoVec[geoPos])
605  {
606  case te::vp::CONVEX_HULL:
607  {
608  std::size_t pos = dsType->getPropertyPosition("convex_hull");
609  if( pos < outDSet->getNumProperties() && pos > 0)
610  {
612  ex_geom = new te::da::ST_ConvexHull(*e_union);
613  f_geom = new te::da::Field(*ex_geom, "convex_hull");
614  fields->push_back(f_geom);
615  }
616  }
617  break;
618  case te::vp::CENTROID:
619  {
620  std::size_t pos = dsType->getPropertyPosition("centroid");
621  if( pos < outDSet->getNumProperties() && pos > 0)
622  {
624  ex_geom = new te::da::ST_Centroid(*e_union);
625  f_geom = new te::da::Field(*ex_geom, "centroid");
626  fields->push_back(f_geom);
627  }
628  }
629  break;
630  case te::vp::MBR:
631  {
632  std::size_t pos = dsType->getPropertyPosition("mbr");
633  if( pos < outDSet->getNumProperties() && pos > 0)
634  {
636  ex_geom = new te::da::ST_Envelope(*e_union);
637  f_geom = new te::da::Field(*ex_geom, "mbr");
638  fields->push_back(f_geom);
639  }
640  }
641  break;
642  default:
643  {
644 #ifdef TERRALIB_LOGGER_ENABLED
645  te::common::Logger::logDebug("vp", "Geometric Operation - Invalid field to add in query.");
646 #endif //TERRALIB_LOGGER_ENABLED
647  }
648  }
649  }
650  }
651  else
652  {
654  te::da::Field* f_prop = new te::da::Field(*e_union, name);
655  fields->push_back(f_prop);
656  }
657 
658  te::da::FromItem* fromItem = new te::da::DataSetName(m_inDsetType->getName());
659  te::da::From* from = new te::da::From;
660  from->push_back(fromItem);
661 
662  te::da::Select select(fields, from);
663 
664  te::da::GroupBy* groupBy = new te::da::GroupBy();
665  te::da::GroupByItem* e_groupBy = new te::da::GroupByItem(m_attribute);
666  groupBy->push_back(e_groupBy);
667 
668  select.setGroupBy(groupBy);
669 
670  std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(select);
671 
672  if (dsQuery->isEmpty())
673  return false;
674 
675  SetOutputDSet(dsQuery.get(), outDSet.get());
676 
677  return outDSet.release();
678 }
679 
681  te::mem::DataSet* outDataSet)
682 {
683  std::size_t numProps = inDataSet->getNumProperties();
684  int pk = 0;
685 
686  bool geomFlag = true;
687 
688  inDataSet->moveBeforeFirst();
689  while(inDataSet->moveNext())
690  {
691  geomFlag = true;
692 
693  te::mem::DataSetItem* dItem = new te::mem::DataSetItem(outDataSet);
694 
695  dItem->setInt32(0, pk);
696 
697  for(std::size_t i = 0; i < numProps; ++i)
698  {
699  int type = inDataSet->getPropertyDataType(i);
700  switch(type)
701  {
702  case te::dt::INT16_TYPE:
703  dItem->setInt16(i+1, inDataSet->getInt16(i));
704  break;
705  case te::dt::INT32_TYPE:
706  dItem->setInt32(i+1, inDataSet->getInt32(i));
707  break;
708  case te::dt::INT64_TYPE:
709  dItem->setInt64(i+1, inDataSet->getInt64(i));
710  break;
711  case te::dt::DOUBLE_TYPE:
712  dItem->setDouble(i+1, inDataSet->getDouble(i));
713  break;
714  case te::dt::STRING_TYPE:
715  dItem->setString(i+1, inDataSet->getString(i));
716  break;
718  {
719  std::string inPropName = inDataSet->getPropertyName(i);
720 
721  if(inPropName == "convex_hull")
722  {
723  te::gm::Geometry* geom = inDataSet->getGeometry(i).release();
724  if(geom->isValid())
725  {
726  if(geom->getGeomTypeId() == te::gm::PolygonType)
727  dItem->setGeometry("convex_hull", geom);
728  else
729  geomFlag = false;
730  }
731  }
732  else if(inPropName == "centroid")
733  {
734  te::gm::Geometry* geom = inDataSet->getGeometry(i).release();
735  if(geom->isValid())
736  dItem->setGeometry("centroid", geom);
737  }
738  else if(inPropName == "mbr")
739  {
740  te::gm::Geometry* geom = inDataSet->getGeometry(i).release();
741  if(geom->isValid())
742  {
743  if(geom->getGeomTypeId() == te::gm::PolygonType)
744  dItem->setGeometry("mbr", geom);
745  else
746  geomFlag = false;
747  }
748  }
749  else
750  {
751  te::gm::Geometry* geom = inDataSet->getGeometry(i).release();
752 
753  switch(geom->getGeomTypeId())
754  {
755  case te::gm::PointType:
756  {
758  if(geom->isValid())
759  {
760  teGeomColl->setGeometryN(0, geom);
761  dItem->setGeometry(i+1, teGeomColl);
762  }
763  }
764  break;
766  {
768  if(geom->isValid())
769  {
770  teGeomColl->setGeometryN(0, geom);
771  dItem->setGeometry(i+1, teGeomColl);
772  }
773  }
774  break;
775  case te::gm::PolygonType:
776  {
778  if(geom->isValid())
779  {
780  teGeomColl->setGeometryN(0, geom);
781  dItem->setGeometry(i+1, teGeomColl);
782  }
783  }
784  break;
785  default:
786  {
787  dItem->setGeometry(i+1, geom);
788  }
789  break;
790  }
791  }
792  }
793  break;
794  default:
795  {
796 #ifdef TERRALIB_LOGGER_ENABLED
797  te::common::Logger::logDebug("vp", "Geometric Operation - Property type not found.");
798 #endif //TERRALIB_LOGGER_ENABLED
799  }
800  }
801  }
802  if(geomFlag)
803  {
804  ++pk;
805  outDataSet->add(dItem);
806  }
807  }
808 }
te::da::DataSetType * GetDataSetType(te::vp::GeometricOpObjStrategy, bool MultiGeomColumns, int geomOp=-1)
Definition: GeometricOp.cpp:95
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
Definition: Geometry.h:189
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
boost::ptr_vector< GroupByItem > GroupBy
A class that can be used to model a GROUP BY clause.
Definition: GroupBy.h:37
An exception class for the Vector processing module.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
Utility functions for the data access module.
A class that can be used in a GROUP BY clause.
Definition: GroupByItem.h:50
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
The Field class can be used to model an expression that takes part of the output items of a SELECT...
Definition: Field.h:50
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
The geographic operation Line.
Definition: Enums.h:106
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
The geographic operation Minimum Bounding Rectangle.
Definition: Enums.h:104
A class that models the name of any property of an object.
Definition: PropertyName.h:50
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
void Save(te::da::DataSource *source, te::da::DataSet *result, te::da::DataSetType *outDsType)
Definition: Utils.cpp:213
void setInt16(std::size_t i, boost::int16_t value)
It sets the value of the i-th property.
Spatial length operator.
Definition: ST_Length.h:50
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
Spatial envelope operator.
Definition: ST_Envelope.h:50
This is an abstract class that models a query expression.
Definition: Expression.h:47
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
Definition: DataSet.cpp:172
Spatial perimeter operator.
Definition: ST_Perimeter.h:50
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Definition: DataSet.h:65
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
Definition: Utils.cpp:462
The geographic operation Area.
Definition: Enums.h:105
Spatial area operator.
Definition: ST_Area.h:50
Aggregate all objects.
Definition: Enums.h:118
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Definition: Fields.h:37
Aggregate objects by attribute.
Definition: Enums.h:119
void SetOutputDSet(te::da::DataSet *inDataSet, te::mem::DataSet *outDataSet)
The geographic operation Perimeter.
Definition: Enums.h:107
virtual bool isValid() const
It tells if the geometry is well formed.
Definition: Geometry.cpp:168
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Definition: Geometry.h:178
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
void setGroupBy(GroupBy *g)
It sets the list of expressions used to condense the result set.
Definition: Select.cpp:957
The geographic operation Centroid.
Definition: Enums.h:103
te::mem::DataSet * SetAggregByAttribute(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
Spatial centroid operator.
Definition: ST_Centroid.h:50
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Definition: DataSetItem.h:56
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
void setGeometryN(std::size_t i, Geometry *g)
It sets the n-th geometry in this geometry collection.
The geographic operation Convex Hull.
Definition: Enums.h:102
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
te::mem::DataSet * SetAllObjects(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
Configuration flags for the Terrralib Vector Processing module.
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
void setInt64(std::size_t i, boost::int64_t value)
It sets the value of the i-th property.
It is a collection of other geometric objects.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
All objects individually.
Definition: Enums.h:117
te::mem::DataSet * SetAggregObj(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)