All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GeometricOpMemory.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 GeographicOpMemory.h
22 
23  \brief Geographic Vector Processing functions.
24 */
25 
26 //Terralib
27 
28 #include "../common/progress/TaskProgress.h"
29 #include "../common/Logger.h"
30 #include "../common/Translator.h"
31 
32 #include "../dataaccess/dataset/DataSet.h"
33 #include "../dataaccess/utils/Utils.h"
34 #include "../datatype/Property.h"
35 #include "../datatype/SimpleProperty.h"
36 #include "../datatype/StringProperty.h"
37 
38 #include "../geometry/Geometry.h"
39 #include "../geometry/GeometryProperty.h"
40 #include "../geometry/GeometryCollection.h"
41 #include "../geometry/LineString.h"
42 #include "../geometry/MultiLineString.h"
43 #include "../geometry/MultiPolygon.h"
44 #include "../geometry/Point.h"
45 #include "../geometry/Polygon.h"
46 #include "../geometry/Utils.h"
47 
48 #include "../memory/DataSet.h"
49 #include "../memory/DataSetItem.h"
50 
51 #include "GeometricOpMemory.h"
52 #include "Config.h"
53 #include "Exception.h"
54 #include "Utils.h"
55 
56 // STL
57 #include <map>
58 #include <math.h>
59 #include <string>
60 #include <vector>
61 
62 // BOOST
63 #include <boost/lexical_cast.hpp>
64 #include <boost/algorithm/string.hpp>
65 
67 {}
68 
70 {}
71 
72 
74 {
75 // get the geometric operation and/or tabular operation.
76  std::vector<int> opGeom;
77  std::vector<int> opTab;
78  std::vector<te::da::DataSetType*> dsTypeVec;
79 
80  for(std::size_t i = 0; i < m_operations.size(); ++i)
81  {
82  switch(m_operations[i])
83  {
84  case te::vp::CENTROID:
85  opGeom.push_back(te::vp::CENTROID);
86  break;
88  opGeom.push_back(te::vp::CONVEX_HULL);
89  break;
90  case te::vp::MBR:
91  opGeom.push_back(te::vp::MBR);
92  break;
93  case te::vp::AREA:
94  opTab.push_back(te::vp::AREA);
95  break;
96  case te::vp::LINE:
97  opTab.push_back(te::vp::LINE);
98  break;
99  case te::vp::PERIMETER:
100  opTab.push_back(te::vp::PERIMETER);
101  break;
102  default:
103  te::common::Logger::logDebug("vp", "Geometric Operation - The operation is not valid.");
104  }
105  }
106 
107  if(m_outputLayer)
108  {
109  bool hasMultiGeomColumns = false;
110  bool result = false;
111 
112  switch(m_objStrategy)
113  {
114  case te::vp::ALL_OBJ:
115  {
116  if(hasMultiGeomColumns) //Condição se o DataSource suporta mais de uma coluna geometrica...
117  {
118  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::ALL_OBJ, true));
119  }
120  else
121  {
122  if(opGeom.size() > 0)
123  {
124  for(std::size_t i = 0; i < opGeom.size(); ++i)
125  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::ALL_OBJ, false, opGeom[i]));
126  }
127  else
128  {
129  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::ALL_OBJ, false));
130  }
131  }
132 
133  for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
134  {
135  m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
136 
137  std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
138  std::auto_ptr<te::mem::DataSet> outDataSet(SetAllObjects(dsTypeVec[dsTypePos], opTab, opGeom));
139  result = save(outDataSet, outDataSetType);
140 
141  if(!result)
142  return result;
143  }
144 
145  }
146  break;
147  case te::vp::AGGREG_OBJ:
148  {
149  if(hasMultiGeomColumns) //Condição se o DataSource suporta mais de uma coluna geometrica...
150  {
151  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::AGGREG_OBJ, true));
152  }
153  else
154  {
155  if(opGeom.size() > 0)
156  {
157  for(std::size_t i = 0; i < opGeom.size(); ++i)
158  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::AGGREG_OBJ, false, opGeom[i]));
159  }
160  else
161  {
162  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::AGGREG_OBJ, false));
163  }
164  }
165 
166  for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
167  {
168  m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
169 
170  std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
171  std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregObj(dsTypeVec[dsTypePos], opTab, opGeom));
172  result = save(outDataSet, outDataSetType);
173 
174  if(!result)
175  return result;
176  }
177 
178  }
179  break;
181  {
182  if(hasMultiGeomColumns) //Condição se o DataSource suporta mais de uma coluna geometrica...
183  {
185  }
186  else
187  {
188  if(opGeom.size() > 0)
189  {
190  for(std::size_t i = 0; i < opGeom.size(); ++i)
191  dsTypeVec.push_back(te::vp::GeometricOp::GetDataSetType(te::vp::AGGREG_BY_ATTRIBUTE, false, opGeom[i]));
192  }
193  else
194  {
196  }
197  }
198 
199  for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
200  {
201  m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
202 
203  std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
204  std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregByAttribute(dsTypeVec[dsTypePos], opTab, opGeom));
205  result = save(outDataSet, outDataSetType);
206 
207  if(!result)
208  return result;
209  }
210  }
211  break;
212  default:
213  te::common::Logger::logDebug("vp", "Geometric Operation - Strategy Not found!");
214  return false;
215  }
216 
217  return result;
218  }
219  else
220  {
221  //Descobrir se o DataSource suporta adição de mais de uma coluna geometrica.
222  return false;
223  }
224 }
225 
226 
228  std::vector<int> tabVec,
229  std::vector<int> geoVec)
230 {
231  std::auto_ptr<te::mem::DataSet> outDSet(new te::mem::DataSet(dsType));
232 
233  int pk = 0;
234  std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
235  inDset->moveBeforeFirst();
236 
237  std::size_t geom_pos = te::da::GetFirstSpatialPropertyPos(inDset.get());
238 
239  while(inDset->moveNext())
240  {
241  te::mem::DataSetItem* item = new te::mem::DataSetItem(outDSet.get());
242 
243  item->setInt32(0, pk);
244  bool geom = true;
245 
246  if(m_selectedProps.size() > 0)
247  {
248  for(std::size_t prop_pos = 0; prop_pos < m_selectedProps.size(); ++prop_pos)
249  {
250  item->setValue(m_selectedProps[prop_pos], inDset->getValue(m_selectedProps[prop_pos]).release());
251  }
252  }
253 
254  std::auto_ptr<te::gm::Geometry> in_geom = inDset->getGeometry(geom_pos);
255 
256  if(tabVec.size() > 0)
257  {
258  for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
259  {
260  switch(tabVec[tabPos])
261  {
262  case te::vp::AREA:
263  {
264  double area = 0;
265  area = CalculateTabularOp(tabVec[tabPos], in_geom.get());
266  item->setDouble("area", area);
267  }
268  break;
269  case te::vp::LINE:
270  {
271  double line = 0;
272  line = CalculateTabularOp(tabVec[tabPos], in_geom.get());
273  item->setDouble("line_length", line);
274  }
275  break;
276  case te::vp::PERIMETER:
277  {
278  double perimeter = 0;
279  perimeter = CalculateTabularOp(tabVec[tabPos], in_geom.get());
280  item->setDouble("perimeter", perimeter);
281  }
282  break;
283  default:
284  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the tabular value.");
285  }
286  }
287  }
288 
289  if(geoVec.size() > 0)
290  {
291  for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
292  {
293  switch(geoVec[geoPos])
294  {
295  case te::vp::CONVEX_HULL:
296  {
297  std::size_t pos = te::da::GetPropertyPos(dsType, "convex_hull");
298  if(pos < dsType->size())
299  {
300  std::auto_ptr<te::gm::Geometry> convexHull(in_geom->convexHull());
301  convexHull->setSRID(in_geom->getSRID());
302 
303  if(convexHull->getGeomTypeId() == te::gm::PolygonType)
304  {
305  item->setGeometry("convex_hull", convexHull.release());
306  geom = true;
307  }
308  else
309  geom = false;
310  }
311  }
312  break;
313  case te::vp::CENTROID:
314  {
315  std::size_t pos = te::da::GetPropertyPos(dsType, "centroid");
316  if(pos < dsType->size())
317  {
318  const te::gm::Envelope* env = in_geom->getMBR();
319  te::gm::Coord2D center = env->getCenter();
320  te::gm::Point* point = new te::gm::Point(center.x, center.y, in_geom->getSRID());
321  item->setGeometry("centroid", point);
322  }
323  }
324  break;
325  case te::vp::MBR:
326  {
327  std::size_t pos = te::da::GetPropertyPos(dsType, "mbr");
328  if(pos < dsType->size())
329  {
330  std::auto_ptr<te::gm::Geometry> mbr(in_geom->getEnvelope());
331  mbr->setSRID(in_geom->getSRID());
332  if(mbr->getGeomTypeId() == te::gm::PolygonType)
333  item->setGeometry("mbr", mbr.release());
334  else
335  geom = false;
336  }
337  }
338  break;
339  default:
340  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the geometric value.");
341  }
342  }
343  }
344  else
345  {
346  std::auto_ptr<te::gm::Geometry> g(in_geom.release());
348 
349  switch(g->getGeomTypeId())
350  {
351  case te::gm::PointType:
352  {
353  if(g->isValid())
354  teGeomColl->add(g.release());
355  }
356  break;
358  {
359  if(g->isValid())
360  teGeomColl->add(g.release());
361  }
362  break;
363  case te::gm::PolygonType:
364  {
365  if(g->isValid())
366  teGeomColl->add(g.release());
367  }
368  break;
369  default:
370  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the geometry in collection.");
371  }
372  if(teGeomColl->getNumGeometries() != 0)
373  item->setGeometry("geom", teGeomColl);
374  else
375  item->setGeometry("geom", g.release());
376  }
377 
378  if(geom)
379  {
380  outDSet->add(item);
381  ++pk;
382  }
383  }
384 
385  return outDSet.release();
386 }
387 
388 
390  std::vector<int> tabVec,
391  std::vector<int> geoVec)
392 {
393  std::auto_ptr<te::mem::DataSet> outDSet(new te::mem::DataSet(dsType));
394 
395  int pk = 0;
396  std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
397  std::size_t geom_pos = te::da::GetFirstSpatialPropertyPos(inDset.get());
398  // move first to take a seed geom.
399  inDset->moveFirst();
400  te::mem::DataSetItem* item = new te::mem::DataSetItem(outDSet.get());
401 
402  item->setInt32(0, pk);
403 
404  std::auto_ptr<te::gm::Geometry> seedGeom = inDset->getGeometry(geom_pos);
405  int srid = seedGeom->getSRID();
407 
408  if(inDset->size() > 1)
409  {
410  while(inDset->moveNext())
411  {
412  std::auto_ptr<te::gm::Geometry> c_geom = inDset->getGeometry(geom_pos);
413  if(c_geom->isValid())
414  teGeomColl->add(c_geom.release());
415  }
416  }
417 
418  if(teGeomColl->getNumGeometries() > 1)
419  {
420  seedGeom.reset(seedGeom->Union(teGeomColl));
421  seedGeom->setSRID(srid);
422  }
423 
424  if(tabVec.size() > 0)
425  {
426  for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
427  {
428  switch(tabVec[tabPos])
429  {
430  case te::vp::AREA:
431  {
432  double area = 0;
433  area = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
434  item->setDouble("area", area);
435  }
436  break;
437  case te::vp::LINE:
438  {
439  double line = 0;
440  line = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
441  item->setDouble("line_length", line);
442  }
443  break;
444  case te::vp::PERIMETER:
445  {
446  double perimeter = 0;
447  perimeter = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
448  item->setDouble("perimeter", perimeter);
449  }
450  break;
451  default:
452  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the tabular value.");
453  }
454  }
455  }
456 
457  if(geoVec.size() > 0)
458  {
459  for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
460  {
461  switch(geoVec[geoPos])
462  {
463  case te::vp::CONVEX_HULL:
464  {
465  std::size_t pos = te::da::GetPropertyPos(dsType, "convex_hull");
466  if(pos < dsType->size())
467  {
468  std::auto_ptr<te::gm::Geometry> convexHull(seedGeom->convexHull());
469  convexHull->setSRID(seedGeom->getSRID());
470  item->setGeometry("convex_hull", convexHull.release());
471  }
472  }
473  break;
474  case te::vp::CENTROID:
475  {
476  std::size_t pos = te::da::GetPropertyPos(dsType, "centroid");
477  if(pos < dsType->size())
478  {
479  const te::gm::Envelope* env = seedGeom->getMBR();
480  te::gm::Coord2D center = env->getCenter();
481  te::gm::Point* point = new te::gm::Point(center.x, center.y, seedGeom->getSRID());
482  item->setGeometry("centroid", point);
483  }
484  }
485  break;
486  case te::vp::MBR:
487  {
488  std::size_t pos = te::da::GetPropertyPos(dsType, "mbr");
489  if(pos < dsType->size())
490  {
491  std::auto_ptr<te::gm::Geometry> mbr(seedGeom->getEnvelope());
492  mbr->setSRID(seedGeom->getSRID());
493  item->setGeometry("mbr", mbr.release());
494  }
495  }
496  break;
497  default:
498  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the geometry in collection.");
499  }
500  }
501  }
502  else
503  {
504  std::auto_ptr<te::gm::Geometry> g(seedGeom.release());
506 
507  switch(g->getGeomTypeId())
508  {
509  case te::gm::PointType:
510  {
511  if(g->isValid())
512  teGeomColl->add(g.release());
513  }
514  break;
516  {
517  if(g->isValid())
518  teGeomColl->add(g.release());
519  }
520  break;
521  case te::gm::PolygonType:
522  {
523  if(g->isValid())
524  teGeomColl->add(g.release());
525  }
526  break;
527  default:
528  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the geometry in collection.");
529  }
530  if(teGeomColl->getNumGeometries() != 0)
531  item->setGeometry("geom", teGeomColl);
532  else
533  item->setGeometry("geom", g.release());
534  }
535 
536  outDSet->add(item);
537 
538  return outDSet.release();
539 }
540 
542  std::vector<int> tabVec,
543  std::vector<int> geoVec)
544 {
545  std::map<std::string, te::gm::Geometry*> geometries;
546 
547  std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
548 
549  te::gm::GeometryProperty* propGeom = static_cast<te::gm::GeometryProperty*>(m_inDsetType->findFirstPropertyOfType(te::dt::GEOMETRY_TYPE));
550  std::size_t geom_pos = te::da::GetFirstSpatialPropertyPos(inDset.get());
551 
552  // move first to take a seed geom.
553  inDset->moveFirst();
554  std::auto_ptr<te::gm::Geometry> seedGeom = inDset->getGeometry(geom_pos);
555  int srid = seedGeom->getSRID();
556 
557  if(inDset->size() > 1)
558  {
559  std::map<std::string, std::vector<te::mem::DataSetItem*> > groups;
560  std::map<std::string, std::vector<te::mem::DataSetItem*> >::iterator itg;
561  size_t nprops = inDset->getNumProperties();
562 
563  // move first to take a seed geom.
564  inDset->moveBeforeFirst();
565  while(inDset->moveNext())
566  {
567  std::string key = inDset->getAsString(m_attribute);
568  te::mem::DataSetItem* item = new te::mem::DataSetItem(inDset.get());
569  for(std::size_t j=0; j<nprops; ++j)
570  {
571  if (!inDset->isNull(j))
572  {
573  std::auto_ptr<te::dt::AbstractData> val = inDset->getValue(j);
574  item->setValue(j,val.release());
575  }
576  }
577 
578  itg = groups.find(key);
579  if (itg==groups.end())
580  {
581  std::vector<te::mem::DataSetItem*> dataSetItemVector;
582  dataSetItemVector.push_back(item);
583  groups.insert(std::pair<std::string, std::vector<te::mem::DataSetItem*> >(key,dataSetItemVector));
584  }
585  else
586  itg->second.push_back(item);
587  }
588 
589  itg = groups.begin();
590  while(itg != groups.end())
591  {
592  // calculate the spatial aggregation
593  te::gm::Geometry* geometry = te::vp::GetGeometryUnion(itg->second, geom_pos, propGeom->getGeometryType());
594 
595  if(geometry->isValid())
596  geometries.insert(std::pair<std::string, te::gm::Geometry*>(itg->first,geometry));
597 
598  ++itg;
599  }
600 
601  }
602  else
603  {
604  geometries.insert(std::pair<std::string, te::gm::Geometry*>(inDset->getAsString(m_attribute), seedGeom.release()));
605  }
606 
607 // insert result in dataset.
608  std::auto_ptr<te::mem::DataSet> outDSet(new te::mem::DataSet(dsType));
609  std::map<std::string, te::gm::Geometry*>::iterator itGeom;
610  int i = 0;
611 
612  itGeom = geometries.begin();
613  while(itGeom != geometries.end())
614  {
615  te::mem::DataSetItem* outItem = new te::mem::DataSetItem(outDSet.get());
616 
617  // inserting the id in dataSet.
618  outItem->setInt32(0, i);
619  // inserting aggregated attribute.
620  te::dt::Property* prop = m_inDsetType->getProperty(m_attribute);
621  switch(prop->getType())
622  {
623  case te::dt::STRING_TYPE:
624  outItem->setString(1, itGeom->first);
625  break;
626  case te::dt::INT16_TYPE:
627  outItem->setInt16(1, boost::lexical_cast<int>(itGeom->first));
628  break;
629  case te::dt::INT32_TYPE:
630  outItem->setInt32(1, boost::lexical_cast<int>(itGeom->first));
631  break;
632  case te::dt::INT64_TYPE:
633  outItem->setInt64(1, boost::lexical_cast<int>(itGeom->first));
634  break;
635  case te::dt::DOUBLE_TYPE:
636  outItem->setDouble(1, boost::lexical_cast<double>(itGeom->first));
637  break;
638  default:
639  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the aggregated value.");
640  }
641 
642  // inserting geometries.
643  if(tabVec.size() > 0)
644  {
645  for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
646  {
647  switch(tabVec[tabPos])
648  {
649  case te::vp::AREA:
650  {
651  double area = 0;
652  area = CalculateTabularOp(tabVec[tabPos], itGeom->second);
653  outItem->setDouble("area", area);
654  }
655  break;
656  case te::vp::LINE:
657  {
658  double line = 0;
659  line = CalculateTabularOp(tabVec[tabPos], itGeom->second);
660  outItem->setDouble("line_length", line);
661  }
662  break;
663  case te::vp::PERIMETER:
664  {
665  double perimeter = 0;
666  perimeter = CalculateTabularOp(tabVec[tabPos], itGeom->second);
667  outItem->setDouble("perimeter", perimeter);
668  }
669  break;
670  default:
671  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the tabular value.");
672  }
673  }
674  }
675 
676  if(geoVec.size() > 0)
677  {
678  for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
679  {
680  switch(geoVec[geoPos])
681  {
682  case te::vp::CONVEX_HULL:
683  {
684  std::size_t pos = te::da::GetPropertyPos(dsType, "convex_hull");
685  if(pos < dsType->size())
686  {
687  std::auto_ptr<te::gm::Geometry> convexHull(itGeom->second->convexHull());
688  convexHull->setSRID(seedGeom->getSRID());
689  outItem->setGeometry("convex_hull", convexHull.release());
690  }
691  }
692  break;
693  case te::vp::CENTROID:
694  {
695  std::size_t pos = te::da::GetPropertyPos(dsType, "centroid");
696  if(pos < dsType->size())
697  {
698  const te::gm::Envelope* env = itGeom->second->getMBR();
699  te::gm::Coord2D center = env->getCenter();
700  te::gm::Point* point = new te::gm::Point(center.x, center.y, itGeom->second->getSRID());
701  outItem->setGeometry("centroid", point);
702  }
703  }
704  break;
705  case te::vp::MBR:
706  {
707  std::size_t pos = te::da::GetPropertyPos(dsType, "mbr");
708  if(pos < dsType->size())
709  {
710  std::auto_ptr<te::gm::Geometry> mbr(itGeom->second->getEnvelope());
711  mbr->setSRID(seedGeom->getSRID());
712  outItem->setGeometry("mbr", mbr.release());
713  }
714  }
715  break;
716  default:
717  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the geometric value.");
718  }
719  }
720  }
721  else
722  {
723  te::gm::GeometryCollection* teGeomColl = new te::gm::GeometryCollection(0, te::gm::GeometryCollectionType, itGeom->second->getSRID());
724 
725  switch(itGeom->second->getGeomTypeId())
726  {
727  case te::gm::PointType:
728  {
729  if(itGeom->second->isValid())
730  teGeomColl->add(itGeom->second);
731  }
732  break;
734  {
735  if(itGeom->second->isValid())
736  teGeomColl->add(itGeom->second);
737  }
738  break;
739  case te::gm::PolygonType:
740  {
741  if(itGeom->second->isValid())
742  teGeomColl->add(itGeom->second);
743  }
744  break;
745  default:
746  te::common::Logger::logDebug("vp", "Geometric Operation - Could not insert the geometry in collection.");
747  }
748  if(teGeomColl->getNumGeometries() != 0)
749  outItem->setGeometry("geom", teGeomColl);
750  else
751  outItem->setGeometry("geom", itGeom->second);
752  }
753 
754  outDSet->add(outItem);
755  ++itGeom;
756  ++i;
757  }
758 
759  return outDSet.release();
760 }
761 
762 
764  te::gm::Geometry* geom)
765 {
766  double value = 0;
767  te::gm::GeomType geomType = geom->getGeomTypeId();
768 
769  switch(tabOperation)
770  {
771  case te::vp::AREA:
772  {
773  if(geomType == te::gm::PolygonType)
774  {
775  te::gm::Polygon* pol = dynamic_cast<te::gm::Polygon*>(geom);
776  if(pol)
777  value = pol->getArea();
778  }
779  if(geomType == te::gm::MultiPolygonType)
780  {
781  std::string type = geom->getGeometryType();
782 
783  if(type == "GeometryCollection")
784  {
785  te::gm::GeometryCollection* m_geoColl = dynamic_cast<te::gm::GeometryCollection*>(geom);
786 
787  if(m_geoColl)
788  {
789  std::vector<te::gm::Geometry*> geomVec = m_geoColl->getGeometries();
790  for(std::size_t i = 0; i < geomVec.size(); ++i)
791  {
792  te::gm::GeomType inType = geomVec[i]->getGeomTypeId();
793  if(inType == te::gm::PolygonType)
794  {
795  te::gm::Polygon* m_pol = dynamic_cast<te::gm::Polygon*>(geomVec[i]);
796  if(m_pol)
797  value += m_pol->getArea();
798  }
799  if(inType == te::gm::MultiPolygonType)
800  {
801  te::gm::MultiPolygon* m_pol = dynamic_cast<te::gm::MultiPolygon*>(geomVec[i]);
802  if(m_pol)
803  value += m_pol->getArea();
804  }
805  }
806  }
807  }
808  else
809  {
810  te::gm::MultiPolygon* m_pol = dynamic_cast<te::gm::MultiPolygon*>(geom);
811  if(m_pol)
812  value = m_pol->getArea();
813  }
814  }
815  return value;
816  }
817  break;
818  case te::vp::LINE:
819  {
820  if(geomType == te::gm::LineStringType)
821  {
822  te::gm::LineString* lineString = dynamic_cast<te::gm::LineString*>(geom);
823  if(lineString)
824  value = lineString->getLength();
825  }
826  if(geomType == te::gm::MultiLineStringType)
827  {
828  te::gm::MultiLineString* m_lineString = dynamic_cast<te::gm::MultiLineString*>(geom);
829  if(m_lineString)
830  value = m_lineString->getLength();
831  }
832  return value;
833  }
834  break;
835  case te::vp::PERIMETER:
836  {
837  if(geomType == te::gm::PolygonType)
838  {
839  te::gm::Polygon* pol = dynamic_cast<te::gm::Polygon*>(geom);
840  if(pol)
841  value = pol->getPerimeter();
842  }
843  if(geomType == te::gm::MultiPolygonType)
844  {
845  std::string type = geom->getGeometryType();
846 
847  if(type == "GeometryCollection")
848  {
849  te::gm::GeometryCollection* m_geoColl = dynamic_cast<te::gm::GeometryCollection*>(geom);
850 
851  if(m_geoColl)
852  {
853  std::vector<te::gm::Geometry*> geomVec = m_geoColl->getGeometries();
854  for(std::size_t i = 0; i < geomVec.size(); ++i)
855  {
856  te::gm::GeomType inType = geomVec[i]->getGeomTypeId();
857  if(inType == te::gm::PolygonType)
858  {
859  te::gm::Polygon* m_pol = dynamic_cast<te::gm::Polygon*>(geomVec[i]);
860  if(m_pol)
861  value += m_pol->getPerimeter();
862  }
863  if(inType == te::gm::MultiPolygonType)
864  {
865  te::gm::MultiPolygon* m_pol = dynamic_cast<te::gm::MultiPolygon*>(geomVec[i]);
866  if(m_pol)
867  value += m_pol->getPerimeter();
868  }
869  }
870  }
871  }
872  else
873  {
874  te::gm::MultiPolygon* m_pol = dynamic_cast<te::gm::MultiPolygon*>(geom);
875  if(m_pol)
876  value = m_pol->getPerimeter();
877  }
878  }
879  return value;
880  }
881  break;
882  default:
883  te::common::Logger::logDebug("vp", "Geometric Operation - Could not calculate the operation.");
884  }
885 
886  return value;
887 }
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
te::da::DataSetType * GetDataSetType(te::vp::GeometricOpObjStrategy, bool MultiGeomColumns, int geomOp=-1)
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
Geometric property.
An exception class for the Vector processing module.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
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.
double y
y-coordinate.
Definition: Coord2D.h:87
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
double CalculateTabularOp(int tabOperation, te::gm::Geometry *geom)
The geographic operation Minimum Bounding Rectangle.
Definition: Enums.h:104
double x
x-coordinate.
Definition: Coord2D.h:86
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual double getLength() const
The length of this curve in the unit associated to its spatial reference system.
Definition: Curve.cpp:49
std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
It returns the value of the i-th property.
double getPerimeter() const
It returns the length of the boundary for the surface.
te::gm::Geometry * GetGeometryUnion(const std::vector< te::mem::DataSetItem * > &items, size_t geomIdx, te::gm::GeomType outGeoType)
It returns the union of a geometry vector.
Definition: Utils.cpp:47
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
Definition: Utils.cpp:451
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
te::mem::DataSet * SetAggregObj(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
void setInt16(std::size_t i, boost::int16_t value)
It sets the value of the i-th property.
double getPerimeter() const
It returns the length of the boundary for the surface.
It models a property definition.
Definition: Property.h:59
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
Definition: Envelope.cpp:49
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:413
The geographic operation Area.
Definition: Enums.h:105
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
Aggregate all objects.
Definition: Enums.h:118
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
te::mem::DataSet * SetAggregByAttribute(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
te::mem::DataSet * SetAllObjects(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
virtual const std::string & getGeometryType() const =0
It returns the name of the geometry subclass.
Aggregate objects by attribute.
Definition: Enums.h:119
The geographic operation Perimeter.
Definition: Enums.h:107
virtual bool isValid() const
It tells if the geometry is well formed.
Definition: Geometry.cpp:167
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Definition: Geometry.h:178
The geographic operation Centroid.
Definition: Enums.h:103
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
double getArea() const
It returns the area of this surface, as measured in the spatial reference system of this surface...
int getType() const
It returns the property data type.
Definition: Property.h:143
MultiLineString is a MultiCurve whose elements are LineStrings.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Definition: DataSetItem.h:56
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
double getArea() const
It returns the area of this MultiSurface, as measured in the spatial reference system of this multisu...
void add(Geometry *g)
It adds the geometry into the collection.
const std::vector< Geometry * > & getGeometries() const
It returns a reference to the internal list of geometries.
The geographic operation Convex Hull.
Definition: Enums.h:102
double getLength() const
It returns the Length of this MultiCurve which is equal to the sum of the lengths of the element Curv...
Definition: MultiCurve.cpp:71
Configuration flags for the Terrralib Vector Processing module.
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.
All objects individually.
Definition: Enums.h:117