All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VectorToVectorMemory.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 VectorToVectorMemory.h
22 
23  \brief Vector to Vector processing.
24 
25  \ingroup attributefill
26  */
27 
28 //Terralib
29 #include "terralib_config.h"
30 #include "../common/Logger.h"
31 #include "../common/progress/TaskProgress.h"
32 #include "../common/STLUtils.h"
33 #include "../common/StringUtils.h"
34 #include "../common/Translator.h"
35 #include "../dataaccess/utils/Utils.h"
36 #include "../datatype/StringProperty.h"
37 #include "../datatype/SimpleData.h"
38 #include "../geometry.h"
39 #include "../memory/DataSet.h"
40 #include "../memory/DataSetItem.h"
41 #include "../statistics/core/NumericStatisticalSummary.h"
42 #include "../statistics/core/StringStatisticalSummary.h"
43 #include "../statistics/core/SummaryFunctions.h"
44 #include "../statistics/core/Enums.h"
45 
46 #include "Config.h"
47 #include "VectorToVectorMemory.h"
48 
49 // STL
50 #include <memory>
51 
52 // Boost
53 #include <boost/algorithm/string/replace.hpp>
54 #include <boost/lexical_cast.hpp>
55 
57 {
58  std::string invalidChar;
59  bool changed;
60  if(!te::da::IsValidName(name, invalidChar))
61  {
62  name = te::common::ReplaceSpecialChars(name, changed);
63 
64  boost::replace_all(name, "/", "_");
65  boost::replace_all(name, " ", "_");
66  boost::replace_all(name, ".", "");
67  boost::replace_all(name, "'", "");
68  }
69 }
70 
72 {
73 
74 }
75 
77 {
78 
79 }
80 
82 {
83  te::gm::Envelope fromEnv = m_fromLayer->getExtent();
84  std::auto_ptr<te::da::DataSet> fromDs = m_fromLayer->getData();
85  int fromSrid = m_fromLayer->getSRID();
86  std::auto_ptr<te::da::DataSetType> fromSchema = m_fromLayer->getSchema();
87 
88  te::gm::Envelope toEnv = m_toLayer->getExtent();
89  std::auto_ptr<te::da::DataSet> toDs = m_toLayer->getData();
90  std::auto_ptr<te::da::DataSetType> toSchema = m_toLayer->getSchema();
91  int toSrid = m_toLayer->getSRID();
92 
93  if(!fromEnv.intersects(toEnv))
94  {
95  throw te::common::Exception(TE_TR("The two layers do not intersect."));
96  }
97 
98  std::auto_ptr<te::da::DataSetType> outDst(getOutputDataSetType());
99 
100  std::auto_ptr<te::mem::DataSet> outDs(new te::mem::DataSet(outDst.get()));
101 
102  te::sam::rtree::Index<size_t, 8>* rtree = getRtree(fromDs.get());
103  KD_ADAPTATIVE_TREE* kdtree = 0;
104 
105  toDs->moveBeforeFirst();
106 
107  te::common::TaskProgress task("Processing Vector to Vector...");
108  task.setTotalSteps(toDs->size());
109  task.useTimer(true);
110 
111  std::string logInfo1 = "";
112  std::string logInfo2 = "";
113  while(toDs->moveNext())
114  {
115  try
116  {
117  te::mem::DataSetItem* item = new te::mem::DataSetItem(outDs.get());
118 
119  std::vector<te::dt::Property*> outProps = outDst->getProperties();
120  std::vector<te::dt::Property*> toProps = toSchema->getProperties();
121  for(std::size_t i = 0; i < outProps.size(); ++i)
122  {
123  std::string outPropName = outProps[i]->getName();
124 
125  for(std::size_t j = 0; j < toProps.size(); ++j)
126  {
127  if(toProps[j]->getName() == outPropName)
128  {
129  item->setValue(outPropName, toDs->getValue(outPropName).release());
130  break;
131  }
132  }
133  }
134 
135  std::vector<std::size_t> intersections = getIntersections(toDs.get(), fromDs.get(), rtree);
136 
137  if(intersections.empty() && !hasNoIntersectionOperations())
138  {
139  outDs->add(item);
140  continue;
141  }
142 
143  std::map<std::string, std::vector<te::attributefill::OperationType> >::iterator it = m_options.begin();
144 
145  while(it != m_options.end())
146  {
147  logInfo1 = it->first;
148 
149  te::dt::Property* prop = fromSchema->getProperty(it->first);
150 
153 
154  std::vector<double> numValues;
155  std::vector<std::string> strValues;
156  std::vector<te::dt::AbstractData*> dataValues;
157 
158  dataValues = getDataValues(fromDs.get(), intersections, prop->getName());
159 
160  if(prop->getType() == te::dt::STRING_TYPE)
161  {
162  strValues = getStrValues(dataValues);
163  te::stat::GetStringStatisticalSummary(strValues, ssStr, "");
164  }
165  else
166  {
167  numValues = getNumValues(dataValues);
168  te::stat::GetNumericStatisticalSummary(numValues, ssNum);
169  }
170 
171  std::vector<te::attributefill::OperationType> funcs = it->second;
172 
173  for(std::size_t i = 0; i < funcs.size(); ++i)
174  {
175  logInfo2 = funcs[i];
176  std::string outPropName = getPropertyName(prop, funcs[i]);
177 
178  if(funcs[i] == te::attributefill::VALUE)
179  {
180  if(prop->getType() == te::dt::STRING_TYPE)
181  item->setString(outPropName, ssStr.m_minVal);
182  else
183  item->setDouble(outPropName, ssNum.m_minVal);
184  }
185  else if(funcs[i] == te::attributefill::HIGHEST_INTERSECTION)
186  {
187  te::dt::AbstractData* value = getClassWithHighestIntersectionArea(toDs.get(), toSrid, fromDs.get(), fromSrid, intersections, prop->getName());
188 
189  item->setValue(outPropName, value);
190  }
191  else if(funcs[i] == te::attributefill::HIGHEST_OCCURRENCE)
192  {
193  te::dt::AbstractData* value = getClassWithHighestOccurrence(fromDs.get(), intersections, prop->getName());
194  item->setValue(outPropName, value);
195  }
196  else if(funcs[i] == te::attributefill::PERCENT_CLASS)
197  {
198  std::map<std::string, double> result = getPercentagePerClass(fromDs.get(), intersections, prop->getName());
199 
200  std::map<std::string, double>::iterator itAux = result.begin();
201  while(itAux != result.end())
202  {
203  std::string className = itAux->first;
204  normalizeClassName(className);
205  std::string newPropName = prop->getName() + "_" + className;
206 
207  item->setDouble(newPropName, itAux->second);
208 
209  ++itAux;
210  }
211  }
212  else if(funcs[i] == te::attributefill::PRESENCE)
213  {
214  if(intersections.size() > 0)
215  {
216  item->setInt32(outPropName, 1);
217  }
218  else
219  {
220  item->setInt32(outPropName, 0);
221  }
222  }
223  else if(funcs[i] == te::attributefill::PERCENT_TOTAL_AREA)
224  {
225  double area = getPercentageOfTotalArea(toDs.get(), toSrid, fromDs.get(), fromSrid, intersections, prop->getName());
226 
227  item->setDouble(outPropName, area);
228  }
229  else if(funcs[i] == te::attributefill::PERCENT_EACH_CLASS)
230  {
231  std::map<std::string, double> result = getPercentageOfEachClassByArea(toDs.get(), toSrid, fromDs.get(), fromSrid, intersections, prop->getName());
232 
233  std::map<std::string, double>::iterator itAux = result.begin();
234  while(itAux != result.end())
235  {
236  std::string className = itAux->first;
237  normalizeClassName(className);
238  std::string newPropName = prop->getName() + "_" + className;
239 
240  item->setDouble(newPropName, itAux->second);
241 
242  ++itAux;
243  }
244  }
245  else if(funcs[i] == te::attributefill::WEIGHTED)
246  {
247  double weigh = getWeightedByArea(toDs.get(), toSrid, fromDs.get(), fromSrid, intersections, prop->getName());
248 
249  item->setDouble(outPropName, weigh);
250  }
251  else if(funcs[i] == te::attributefill::WEIGHTED_SUM)
252  {
253  double weigh = getWeightedSumByArea(toDs.get(), toSrid, fromDs.get(), fromSrid, intersections, prop->getName());
254 
255  item->setDouble(outPropName, weigh);
256  }
257  else if(funcs[i] == te::attributefill::MIN_DISTANCE)
258  {
259  double result = 0;
260 
261  if(intersections.empty())
262  {
263  if(!kdtree)
264  kdtree = getKDtree(fromDs.get(), toSrid);
265 
266  result = getMinimumDistance(toDs.get(), toSrid, fromDs.get(), fromSrid, kdtree);
267  }
268 
269  item->setDouble(outPropName, result);
270  }
271  else if(isStatistical(funcs[i]))
272  {
273  if(prop->getType() == te::dt::STRING_TYPE)
274  {
275  std::string value = getValue(ssStr, funcs[i]);
276  item->setString(outPropName, value);
277  }
278  else
279  {
280  if(funcs[i] == te::attributefill::MODE)
281  {
282  std::string value = getModeValue(ssNum);
283  item->setString(outPropName, value);
284  }
285  else
286  {
287  double value = getValue(ssNum, funcs[i]);
288  item->setDouble(outPropName, value);
289  }
290  }
291  }
292  }
293 
294  ++it;
295  }
296 
297  outDs->add(item);
298 
299  if (task.isActive() == false)
300  throw te::common::Exception(TE_TR("Operation canceled!"), 1);
301 
302  task.pulse();
303  }
304  catch(te::common::Exception& e)
305  {
306  if(e.code() == 1)
307  {
308  throw e;
309  }
310 
311 #ifdef TERRALIB_LOGGER_ENABLED
312  std::string ex = e.what();
313  ex += " | Ref: " + logInfo1 + " : " + logInfo2;
314  te::common::Logger::logDebug("attributefill", ex.c_str());
315 #endif //TERRALIB_LOGGER_ENABLED
316 
317  m_hasErrors = true;
318  }
319  catch(std::exception& e)
320  {
321 #ifdef TERRALIB_LOGGER_ENABLED
322  std::string ex = e.what();
323  ex += " | Ref: " + logInfo1 + " : " + logInfo2;
324  te::common::Logger::logDebug("attributefill", ex.c_str());
325 #endif //TERRALIB_LOGGER_ENABLED
326  m_hasErrors = true;
327  }
328  }
329 
330  save(outDs, outDst);
331 
332  if(rtree)
333  delete rtree;
334 
335  if(kdtree)
336  delete kdtree;
337 
338  return true;
339 }
340 
342 {
343  std::auto_ptr<te::da::DataSet> fromDs = m_fromLayer->getData();
344  std::auto_ptr<te::da::DataSetType> fromSchema = m_fromLayer->getSchema();
345 
346  std::auto_ptr<te::da::DataSetType> toScheme = m_toLayer->getSchema();
347 
348  te::da::DataSetType* dst = new te::da::DataSetType(*toScheme.get());
349  dst->setName(m_outDset);
350 
351  std::vector<te::dt::Property*> outProps = dst->getProperties();
352  std::vector<te::dt::Property*> pkProps = dst->getPrimaryKey()->getProperties();
353 
354  // Keep only the properties that the user selected
355  for(std::size_t i = 0; i < outProps.size(); ++i)
356  {
357  bool isPk = false;
358  for(std::size_t j = 0; j < pkProps.size(); ++j)
359  {
360  if(outProps[i]->getName() == pkProps[j]->getName())
361  {
362  isPk = true;
363  break;
364  }
365  }
366 
367  if(outProps[i]->getType() != te::dt::GEOMETRY_TYPE && !isPk)
368  {
369  std::string name = outProps[i]->getName();
370  if(std::find(m_toLayerProps.begin(), m_toLayerProps.end(), name) == m_toLayerProps.end())
371  dst->remove(outProps[i]);
372  }
373  }
374 
375  std::map<std::string, std::vector<te::attributefill::OperationType> >::iterator it = m_options.begin();
376 
377  while(it != m_options.end())
378  {
379  te::dt::Property* currentProperty = fromSchema->getProperty(it->first);
380 
381  std::vector<te::attributefill::OperationType> funcs = it->second;
382 
383  for(std::size_t i = 0; i < funcs.size(); ++i)
384  {
385  te::dt::SimpleProperty* newProp = 0;
386 
387  std::string newName = getPropertyName(currentProperty, (te::attributefill::OperationType)funcs[i]);
388 
389  if(funcs[i] == te::attributefill::VALUE)
390  {
391  if(currentProperty->getType() == te::dt::STRING_TYPE)
392  newProp = new te::dt::StringProperty(newName);
393  else
394  newProp = new te::dt::SimpleProperty(newName, te::dt::DOUBLE_TYPE);
395  }
396  else if(funcs[i] == te::attributefill::HIGHEST_OCCURRENCE ||
398  {
399  newProp = dynamic_cast<te::dt::SimpleProperty*>(currentProperty->clone());
400  newProp->setRequired(false);
401  newProp->setName(newName);
402  }
404  {
405  continue;//Sera feito fora do for
406  }
407  else if(funcs[i] == te::attributefill::PRESENCE)
408  {
409  newProp = new te::dt::SimpleProperty(newName, te::dt::INT32_TYPE);
410  }
411  else if(funcs[i] == te::attributefill::PERCENT_TOTAL_AREA ||
413  {
414  newProp = new te::dt::SimpleProperty(newName, te::dt::DOUBLE_TYPE);
415  }
416  else if(currentProperty->getType() == te::dt::STRING_TYPE || funcs[i] == te::attributefill::MODE)
417  {
418  newProp = new te::dt::StringProperty(newName);
419  }
420  else
421  {
422  newProp = new te::dt::SimpleProperty(newName, te::dt::DOUBLE_TYPE);
423  }
424 
425  dst->add(newProp);
426  }
427 
428  if(std::find(funcs.begin(), funcs.end(), te::attributefill::PERCENT_CLASS) != funcs.end() ||
429  std::find(funcs.begin(), funcs.end(), te::attributefill::PERCENT_EACH_CLASS) != funcs.end())
430  {
431  std::vector<std::string> strClasses = getDistinctClasses(fromDs.get(), currentProperty->getName());
432 
433  for(std::size_t i = 0; i < strClasses.size(); ++i)
434  {
435  std::string className = strClasses[i];
436 
437  normalizeClassName(className);
438 
439  std::string newPropName = currentProperty->getName() + "_" + className;
440 
442 
443  dst->add(newProp);
444  }
445  }
446 
447  ++it;
448  }
449 
450  return dst;
451 }
452 
454  const std::string& propertyName)
455 {
456  std::vector<std::string> result;
457 
458  fromDs->moveBeforeFirst();
459 
460  while(fromDs->moveNext())
461  {
462  std::string strClass = fromDs->getAsString(propertyName, 9);
463 
464  if(std::find(result.begin(), result.end(), strClass) == result.end())
465  {
466  result.push_back(strClass);
467  }
468  }
469 
470  return result;
471 }
472 
474 {
476 
477  std::size_t geomPos = te::da::GetFirstSpatialPropertyPos(data);
478 
479  data->moveBeforeFirst();
480 
481  int count = 0;
482 
483  while(data->moveNext())
484  {
485  std::auto_ptr<te::gm::Geometry> geom = data->getGeometry(geomPos);
486 
487  rtree->insert(*geom->getMBR(), count);
488 
489  ++count;
490  }
491 
492  return rtree;
493 }
494 
496 {
497  std::string name = te::common::Convert2LCase(prop->getName());
498 
499  std::string newName = name + "_";
500 
501  if(func == te::attributefill::VALUE)
502  newName += "value";
503  else if(func == te::attributefill::MIN_VALUE)
504  newName += "min_val";
505  else if(func == te::attributefill::MAX_VALUE)
506  newName += "max_val";
507  else if(func == te::attributefill::MEAN)
508  newName += "mean";
509  else if(func == te::attributefill::SUM)
510  newName += "sum_values";
511  else if(func == te::attributefill::COUNT)
512  newName += "total_values";
513  else if(func == te::attributefill::VALID_COUNT)
514  newName += "total_notnull_values";
516  newName += "stand_dev";
517  else if(func == te::attributefill::VARIANCE)
518  newName += "variance";
519  else if(func == te::attributefill::SKEWNESS)
520  newName += "skewness";
521  else if(func == te::attributefill::KURTOSIS)
522  newName += "kurtosis";
523  else if(func == te::attributefill::AMPLITUDE)
524  newName += "amplitude";
525  else if(func == te::attributefill::MEDIAN)
526  newName += "median";
527  else if(func == te::attributefill::VAR_COEFF)
528  newName += "coeff_variation";
529  else if(func == te::attributefill::MODE)
530  newName += "mode";
532  newName += "class_high_occurrence";
534  newName += "class_high_area";
535  else if(func == te::attributefill::MIN_DISTANCE)
536  newName += "min_distance";
537  else if(func == te::attributefill::PRESENCE)
538  newName += "presence";
540  newName += "percent_of_total_area";
542  newName += "percent_area_class";
543  else if(func == te::attributefill::WEIGHTED)
544  newName += "weigh_area";
545  else if(func == te::attributefill::WEIGHTED_SUM)
546  newName += "weigh_sum_area";
547  else if(func == te::attributefill::PERCENT_CLASS)
548  newName += "percent_class";
549 
550  return newName;
551 }
552 
554  te::da::DataSet* fromDs,
556 {
557  int toSpatialPos = te::da::GetFirstSpatialPropertyPos(toDs);
558  int fromSpatialPos = te::da::GetFirstSpatialPropertyPos(fromDs);
559 
560  std::map<std::size_t, std::vector<std::size_t> > intersections;
561 
562  std::auto_ptr<te::gm::Geometry> geom = toDs->getGeometry(toSpatialPos);
563  geom->setSRID(m_toLayer->getSRID());
564 
565  std::vector<size_t> report;
566  rtree->search(*geom->getMBR(), report);
567 
568  std::vector<std::size_t> interVec;
569  for(std::size_t i = 0; i < report.size(); ++i)
570  {
571  fromDs->move(report[i]);
572 
573  std::auto_ptr<te::gm::Geometry> g = fromDs->getGeometry(fromSpatialPos);
574  g->setSRID(m_fromLayer->getSRID());
575 
576  if(geom->intersects(g.get()))
577  {
578  interVec.push_back(report[i]);
579  }
580  }
581  return interVec;
582 }
583 
584 std::vector<double> te::attributefill::VectorToVectorMemory::getNumValues(std::vector<te::dt::AbstractData*> data)
585 {
586  std::vector<double> result;
587 
588  for(std::size_t i = 0; i < data.size(); ++i)
589  {
590  if(!data[i])
591  {
592  result.push_back(0.0f);
593  continue;
594  }
595 
596  if(data[i]->getTypeCode() == te::dt::INT16_TYPE ||
597  data[i]->getTypeCode() == te::dt::UINT16_TYPE ||
598  data[i]->getTypeCode() == te::dt::INT32_TYPE ||
599  data[i]->getTypeCode() == te::dt::UINT32_TYPE ||
600  data[i]->getTypeCode() == te::dt::INT64_TYPE ||
601  data[i]->getTypeCode() == te::dt::UINT64_TYPE ||
602  data[i]->getTypeCode() == te::dt::FLOAT_TYPE ||
603  data[i]->getTypeCode() == te::dt::DOUBLE_TYPE ||
604  data[i]->getTypeCode() == te::dt::CINT16_TYPE ||
605  data[i]->getTypeCode() == te::dt::CINT32_TYPE ||
606  data[i]->getTypeCode() == te::dt::CFLOAT_TYPE ||
607  data[i]->getTypeCode() == te::dt::CDOUBLE_TYPE)
608  {
609  std::string strValue = data[i]->toString();
610 
611  result.push_back(boost::lexical_cast<double>(strValue));
612  }
613  }
614 
615  return result;
616 }
617 
618 std::vector<std::string> te::attributefill::VectorToVectorMemory::getStrValues(std::vector<te::dt::AbstractData*> data)
619 {
620  std::vector<std::string> result;
621 
622  for(std::size_t i = 0; i < data.size(); ++i)
623  {
624  if(!data[i])
625  {
626  result.push_back("");
627  continue;
628  }
629 
630  if(data[i]->getTypeCode() == te::dt::STRING_TYPE)
631  result.push_back(data[i]->toString());
632  }
633 
634  return result;
635 }
636 
638 {
639  if(type == te::attributefill::MIN_VALUE ||
641  type == te::attributefill::MEAN ||
642  type == te::attributefill::SUM ||
643  type == te::attributefill::COUNT ||
646  type == te::attributefill::VARIANCE ||
647  type == te::attributefill::SKEWNESS ||
648  type == te::attributefill::KURTOSIS ||
650  type == te::attributefill::MEDIAN ||
652  type == te::attributefill::MODE)
653  {
654  return true;
655  }
656 
657  return false;
658 }
659 
661 {
662  if(type == te::attributefill::AMPLITUDE)
663  return ss.m_amplitude;
664  else if(type == te::attributefill::COUNT)
665  return ss.m_count;
666  else if(type == te::attributefill::KURTOSIS)
667  return ss.m_kurtosis;
668  else if(type == te::attributefill::MAX_VALUE)
669  return ss.m_maxVal;
670  else if(type == te::attributefill::MEAN)
671  return ss.m_mean;
672  else if(type == te::attributefill::MEDIAN)
673  return ss.m_median;
674  else if(type == te::attributefill::MIN_VALUE)
675  return ss.m_minVal;
676  else if(type == te::attributefill::SKEWNESS)
677  return ss.m_skewness;
679  return ss.m_stdDeviation;
680  else if(type == te::attributefill::SUM)
681  return ss.m_sum;
682  else if(type == te::attributefill::VALID_COUNT)
683  return ss.m_validCount;
684  else if(type == te::attributefill::VAR_COEFF)
685  return ss.m_varCoeff;
686  else if(type == te::attributefill::VARIANCE)
687  return ss.m_variance;
688  else
689  return -1;
690 }
691 
693 {
694  if(type == te::attributefill::MAX_VALUE)
695  return ss.m_maxVal;
696  else if(type == te::attributefill::MIN_VALUE)
697  return ss.m_minVal;
698  else if(type == te::attributefill::MODE)
699  return ss.m_mode;
700  else if(type == te::attributefill::COUNT)
701  return boost::lexical_cast<std::string>(ss.m_count);
702  else if(type == te::attributefill::VALID_COUNT)
703  return boost::lexical_cast<std::string>(ss.m_validCount);
704  else
705  return "null";
706 }
707 
709 {
710  std::string result = "";
711  std::vector<double> values = ss.m_mode;
712  for(std::size_t i = 0; i < values.size(); ++i)
713  {
714  if(i == 0)
715  result += boost::lexical_cast<std::string>(values[i]);
716  else
717  result += ", " + boost::lexical_cast<std::string>(values[i]);
718  }
719 
720  return result;
721 }
722 
724  std::vector<std::size_t> dsPos,
725  const std::string& propertyName)
726 {
727  std::vector<te::dt::AbstractData*> result;
728 
729  for(std::size_t i = 0; i < dsPos.size(); ++i)
730  {
731  fromDs->move(dsPos[i]);
732  if(fromDs->isNull(propertyName))
733  result.push_back(0);
734  else
735  result.push_back(fromDs->getValue(propertyName).release());
736  }
737 
738  return result;
739 }
740 
742  std::vector<std::size_t> dsPos,
743  const std::string& propertyName)
744 {
745  int propIndex = te::da::GetPropertyIndex(fromDs, propertyName);
746  int propType = fromDs->getPropertyDataType(propIndex);
747 
748  std::map<std::string, std::size_t> counter;
749  for(std::size_t i = 0; i < dsPos.size(); ++i)
750  {
751  fromDs->move(dsPos[i]);
752 
753  std::string value = fromDs->getAsString(propIndex);
754 
755  if(counter.find(value) == counter.end())
756  {
757  counter[value] = 1;
758  }
759  else
760  {
761  std::size_t aux = counter[value] + 1;
762  counter[value] = aux;
763  }
764  }
765 
766  std::map<std::string, std::size_t>::iterator it = counter.begin();
767  std::string value;
768  std::size_t aux = 0;
769  while(it != counter.end())
770  {
771  if(aux < it->second)
772  {
773  aux = it->second;
774  value = it->first;
775  }
776 
777  ++it;
778  }
779 
780  // Checks if there is a tie between classes
781  std::size_t aux2 = 0;
782  it = counter.begin();
783  while(it != counter.end())
784  {
785  if(it->second == aux)
786  ++aux2;
787 
788  ++it;
789  }
790 
791  te::dt::AbstractData* data = 0;
792  if(aux2 == 1)
793  {
794  data = getDataBasedOnType(value, propType);
795  }
796  else
797  {
799  }
800 
801  return data;
802 }
803 
805  std::size_t toSrid,
806  te::da::DataSet* fromDs,
807  std::size_t fromSrid,
808  std::vector<std::size_t> dsPos,
809  const std::string& propertyName)
810 {
811  std::size_t fromGeomPos = te::da::GetFirstSpatialPropertyPos(fromDs);
812  std::size_t toGeomPos = te::da::GetFirstSpatialPropertyPos(toDs);
813 
814  int propIndex = te::da::GetPropertyIndex(fromDs, propertyName);
815  int propType = fromDs->getPropertyDataType(propIndex);
816 
817  std::auto_ptr<te::gm::Geometry> toGeom = toDs->getGeometry(toGeomPos);
818  if(toGeom->getSRID() <= 0)
819  toGeom->setSRID(toSrid);
820 
821  std::map<std::string, double> classAreaMap;
822  for(std::size_t i = 0; i < dsPos.size(); ++i)
823  {
824  fromDs->move(dsPos[i]);
825 
826  std::auto_ptr<te::gm::Geometry> fromGeom = fromDs->getGeometry(fromGeomPos);
827  if(fromGeom->getSRID() <= 0)
828  fromGeom->setSRID(fromSrid);
829 
830  std::auto_ptr<te::gm::Geometry> interGeom;
831 
832  if(!checkGeometries(fromGeom.get(), dsPos[i], toGeom.get()))
833  {
834  m_hasErrors = true;
835  continue;
836  }
837 
838  try
839  {
840  interGeom.reset(toGeom->intersection(fromGeom.get()));
841  }
842  catch(const std::exception &e)
843  {
844 #ifdef TERRALIB_LOGGER_ENABLED
845  std::string ex = e.what();
846  te::common::Logger::logDebug("attributefill", ex.c_str());
847 #endif //TERRALIB_LOGGER_ENABLED
848  m_hasErrors = true;
849  continue;
850  }
851 
852  std::string value = fromDs->getAsString(propertyName);
853 
854  double area = getArea(interGeom.get());
855 
856  if(classAreaMap.find(value) == classAreaMap.end())
857  {
858  classAreaMap[value] = area;
859  }
860  else
861  {
862  double aux = classAreaMap[value];
863  classAreaMap[value] = aux + area;
864  }
865  }
866 
867  std::map<std::string, double>::iterator it = classAreaMap.begin();
868  std::string value;
869  double aux = 0;
870  while(it != classAreaMap.end())
871  {
872  if(aux < it->second)
873  {
874  aux = it->second;
875  value = it->first;
876  }
877 
878  ++it;
879  }
880 
881  te::dt::AbstractData* data = getDataBasedOnType(value, propType);
882 
883  return data;
884 }
885 
887  std::vector<std::size_t> dsPos,
888  const std::string& propertyName)
889 {
890  std::map<std::string, double> result;
891 
892  std::map<std::string, std::size_t> aux;
893  for(std::size_t i = 0; i < dsPos.size(); ++i)
894  {
895  fromDs->move(dsPos[i]);
896 
897  std::string value = fromDs->getAsString(propertyName);
898 
899  if(aux.find(value) == aux.end())
900  {
901  aux[value] = 1;
902  }
903  else
904  {
905  aux[value] += 1;
906  }
907  }
908 
909  std::size_t total = 0;
910  std::map<std::string, std::size_t>::iterator it = aux.begin();
911  while(it != aux.end())
912  {
913  total += it->second;
914 
915  ++it;
916  }
917 
918  it = aux.begin();
919  while(it != aux.end())
920  {
921  std::string normName = it->first;
922  normalizeClassName(normName);
923  result[normName] = ((double)it->second / total);
924 
925  ++it;
926  }
927 
928  return result;
929 }
930 
932  std::size_t toSrid,
933  te::da::DataSet* fromDs,
934  std::size_t fromSrid,
935  std::vector<std::size_t> dsPos,
936  const std::string& propertyName)
937 {
938  std::size_t fromGeomPos = te::da::GetFirstSpatialPropertyPos(fromDs);
939  std::size_t toGeomPos = te::da::GetFirstSpatialPropertyPos(toDs);
940 
941  std::auto_ptr<te::gm::Geometry> toGeom = toDs->getGeometry(toGeomPos);
942  if(toGeom->getSRID() <= 0)
943  toGeom->setSRID(toSrid);
944 
945  double classArea = 0;
946  for(std::size_t i = 0; i < dsPos.size(); ++i)
947  {
948  fromDs->move(dsPos[i]);
949 
950  std::auto_ptr<te::gm::Geometry> fromGeom = fromDs->getGeometry(fromGeomPos);
951  if(fromGeom->getSRID() <= 0)
952  fromGeom->setSRID(fromSrid);
953 
954  if(checkGeometries(fromGeom.get(), dsPos[i], toGeom.get()))
955  {
956  m_hasErrors = true;
957  continue;
958  }
959 
960  std::auto_ptr<te::gm::Geometry> interGeom(toGeom->intersection(fromGeom.get()));
961 
962  classArea += getArea(interGeom.get());
963  }
964 
965  double polArea = getArea(toGeom.get());
966 
967  return classArea/polArea;
968 }
969 
971  std::size_t toSrid,
972  te::da::DataSet* fromDs,
973  std::size_t fromSrid,
974  std::vector<std::size_t> dsPos,
975  const std::string& propertyName)
976 {
977  std::map<std::string, double> result;
978 
979  std::size_t fromGeomPos = te::da::GetFirstSpatialPropertyPos(fromDs);
980  std::size_t toGeomPos = te::da::GetFirstSpatialPropertyPos(toDs);
981 
982  std::auto_ptr<te::gm::Geometry> toGeom = toDs->getGeometry(toGeomPos);
983  if(toGeom->getSRID() <= 0)
984  toGeom->setSRID(toSrid);
985 
986  double toGeomArea = getArea(toGeom.get());
987 
988  for(std::size_t i = 0; i < dsPos.size(); ++i)
989  {
990  fromDs->move(dsPos[i]);
991 
992  std::auto_ptr<te::gm::Geometry> fromGeom = fromDs->getGeometry(fromGeomPos);
993  if(fromGeom->getSRID() <= 0)
994  fromGeom->setSRID(fromSrid);
995 
996  if(checkGeometries(fromGeom.get(), dsPos[i], toGeom.get()))
997  {
998  m_hasErrors = true;
999  continue;
1000  }
1001 
1002  std::auto_ptr<te::gm::Geometry> interGeom(toGeom->intersection(fromGeom.get()));
1003 
1004  std::string value = fromDs->getAsString(propertyName);
1005 
1006  double area = getArea(interGeom.get());
1007 
1008  if(result.find(value) == result.end())
1009  {
1010  result[value] = area/toGeomArea;
1011  }
1012  else
1013  {
1014  result[value] += area/toGeomArea;
1015  }
1016  }
1017 
1018  return result;
1019 }
1020 
1022  std::size_t toSrid,
1023  te::da::DataSet* fromDs,
1024  std::size_t fromSrid,
1025  std::vector<std::size_t> dsPos,
1026  const std::string& propertyName)
1027 {
1028  std::size_t fromGeomPos = te::da::GetFirstSpatialPropertyPos(fromDs);
1029  std::size_t toGeomPos = te::da::GetFirstSpatialPropertyPos(toDs);
1030 
1031  std::auto_ptr<te::gm::Geometry> toGeom = toDs->getGeometry(toGeomPos);
1032  if(toGeom->getSRID() <= 0)
1033  toGeom->setSRID(toSrid);
1034 
1035  double toGeomArea = getArea(toGeom.get());
1036 
1037  double weigh = 0;
1038 
1039  for(std::size_t i = 0; i < dsPos.size(); ++i)
1040  {
1041  fromDs->move(dsPos[i]);
1042 
1043  std::auto_ptr<te::gm::Geometry> fromGeom = fromDs->getGeometry(fromGeomPos);
1044  if(fromGeom->getSRID() <= 0)
1045  fromGeom->setSRID(fromSrid);
1046 
1047  if(checkGeometries(fromGeom.get(), dsPos[i], toGeom.get()))
1048  {
1049  m_hasErrors = true;
1050  continue;
1051  }
1052 
1053  std::auto_ptr<te::gm::Geometry> interGeom(toGeom->intersection(fromGeom.get()));
1054 
1055  double value_num = 0;
1056 
1057  if(!fromDs->isNull(propertyName))
1058  {
1059  std::string value = fromDs->getAsString(propertyName);
1060  value_num = boost::lexical_cast<double>(value);
1061  }
1062 
1063  double intersectionArea = getArea(interGeom.get());
1064 
1065  weigh += value_num*(intersectionArea/toGeomArea);
1066  }
1067 
1068  return weigh;
1069 }
1070 
1072  std::size_t toSrid,
1073  te::da::DataSet* fromDs,
1074  std::size_t fromSrid,
1075  std::vector<std::size_t> dsPos,
1076  const std::string& propertyName)
1077 {
1078  std::size_t fromGeomPos = te::da::GetFirstSpatialPropertyPos(fromDs);
1079  std::size_t toGeomPos = te::da::GetFirstSpatialPropertyPos(toDs);
1080 
1081  std::auto_ptr<te::gm::Geometry> toGeom = toDs->getGeometry(toGeomPos);
1082  if(toGeom->getSRID() <= 0)
1083  toGeom->setSRID(toSrid);
1084 
1085  double weigh = 0;
1086 
1087  for(std::size_t i = 0; i < dsPos.size(); ++i)
1088  {
1089  fromDs->move(dsPos[i]);
1090 
1091  std::auto_ptr<te::gm::Geometry> fromGeom = fromDs->getGeometry(fromGeomPos);
1092  if(fromGeom->getSRID() <= 0)
1093  fromGeom->setSRID(fromSrid);
1094 
1095  double fromGeomArea = getArea(fromGeom.get());
1096 
1097  if(checkGeometries(fromGeom.get(), dsPos[i], toGeom.get()))
1098  {
1099  m_hasErrors = true;
1100  continue;
1101  }
1102 
1103  std::auto_ptr<te::gm::Geometry> interGeom(toGeom->intersection(fromGeom.get()));
1104 
1105  double value_num = 0;
1106 
1107  if(!fromDs->isNull(propertyName))
1108  {
1109  std::string value = fromDs->getAsString(propertyName);
1110  value_num = boost::lexical_cast<double>(value);
1111  }
1112 
1113  double intersectionArea = getArea(interGeom.get());
1114 
1115  weigh += value_num*(intersectionArea/fromGeomArea);
1116  }
1117 
1118  return weigh;
1119 }
1120 
1122 {
1123  if(type == te::gm::PolygonType ||
1124  type == te::gm::PolygonZType ||
1125  type == te::gm::PolygonMType ||
1126  type == te::gm::PolygonZMType)
1127  return true;
1128 
1129  return false;
1130 }
1131 
1133 {
1134  if(type == te::gm::LineStringType ||
1135  type == te::gm::LineStringMType ||
1136  type == te::gm::LineStringZMType ||
1137  type == te::gm::LineStringZType)
1138  return true;
1139 
1140  return false;
1141 }
1142 
1144 {
1145  if(type == te::gm::PointType ||
1146  type == te::gm::PointZType ||
1147  type == te::gm::PointMType ||
1148  type == te::gm::PointZMType)
1149  return true;
1150 
1151  return false;
1152 }
1153 
1155 {
1156  if(type == te::gm::MultiPolygonType ||
1157  type == te::gm::MultiPolygonZType ||
1158  type == te::gm::MultiPolygonMType ||
1160  return true;
1161 
1162  return false;
1163 }
1164 
1166 {
1167  if(type == te::gm::MultiLineStringMType ||
1168  type == te::gm::MultiLineStringType ||
1171  return true;
1172 
1173  return false;
1174 }
1175 
1177 {
1178  if(type == te::gm::MultiPointType ||
1179  type == te::gm::MultiPointZType ||
1180  type == te::gm::MultiPointMType ||
1181  type == te::gm::MultiPointZMType)
1182  return true;
1183 
1184  return false;
1185 }
1186 
1188 {
1189  te::gm::GeomType geomType = geom->getGeomTypeId();
1190 
1191  double area = 0;
1192 
1193  switch(geomType)
1194  {
1195  case te::gm::PolygonType:
1196  {
1197  te::gm::Polygon* g = dynamic_cast<te::gm::Polygon*>(geom);
1198  area = g->getArea();
1199  break;
1200  }
1202  {
1203  te::gm::MultiPolygon* g = dynamic_cast<te::gm::MultiPolygon*>(geom);
1204  area = g->getArea();
1205  break;
1206  }
1208  {
1209  te::gm::GeometryCollection* col = dynamic_cast<te::gm::GeometryCollection*>(geom);
1210  for(std::size_t j = 0; j < col->getNumGeometries(); ++j)
1211  {
1212  te::gm::Geometry* auxGeom = col->getGeometryN(j);
1213  if(isPolygon(auxGeom->getGeomTypeId()))
1214  {
1215  area += dynamic_cast<te::gm::Polygon*>(auxGeom)->getArea();
1216  }
1217  else if(isMultiPolygon(auxGeom->getGeomTypeId()))
1218  {
1219  area += dynamic_cast<te::gm::MultiPolygon*>(auxGeom)->getArea();
1220  }
1221  }
1222 
1223  break;
1224  }
1225  default:
1226  {
1227  throw te::common::Exception(TE_TR("Unexpected geometry type!"));
1228  }
1229  }
1230 
1231  return area;
1232 }
1233 
1235 {
1236  te::dt::AbstractData* data = 0;
1237 
1238  switch(type)
1239  {
1240  case te::dt::STRING_TYPE:
1241  {
1243  break;
1244  }
1245  case te::dt::INT16_TYPE:
1246  {
1248  break;
1249  }
1250  case te::dt::INT32_TYPE:
1251  {
1253  break;
1254  }
1255  case te::dt::INT64_TYPE:
1256  {
1258  break;
1259  }
1260  case te::dt::UINT16_TYPE:
1261  {
1263  break;
1264  }
1265  case te::dt::UINT32_TYPE:
1266  {
1268  break;
1269  }
1270  case te::dt::UINT64_TYPE:
1271  {
1273  break;
1274  }
1275  default:
1276  {
1277  throw te::common::Exception(TE_TR("Unexpected data type!"));
1278  }
1279  }
1280 
1281  return data;
1282 }
1283 
1285 {
1286  std::size_t geomPos = te::da::GetFirstSpatialPropertyPos(data);
1287 
1288  KD_ADAPTATIVE_TREE* kdtree = new KD_ADAPTATIVE_TREE(*data->getExtent(geomPos).release(), 5);
1289 
1290  std::vector<std::pair<te::gm::Coord2D, te::gm::Point> > kdset;
1291 
1292  data->moveBeforeFirst();
1293 
1294  while(data->moveNext())
1295  {
1296  std::auto_ptr<te::gm::Geometry> geom = data->getGeometry(geomPos);
1297 
1298  std::vector<te::gm::Point*> allPoints = getAllPointsOfGeometry(geom.get());
1299 
1300  for(std::size_t i = 0; i < allPoints.size(); ++i)
1301  {
1302  te::gm::Point* p = allPoints[i];
1303 
1304  if(p->getSRID() != toSrid)
1305  {
1306  p->transform(toSrid);
1307  }
1308 
1309  te::gm::Coord2D coord(p->getX(), p->getY());
1310  kdset.push_back(std::pair<te::gm::Coord2D, te::gm::Point>(coord, *p));
1311  }
1312  }
1313 
1314  kdtree->build(kdset);
1315 
1316  return kdtree;
1317 }
1318 
1320  std::size_t toSrid,
1321  te::da::DataSet* fromDs,
1322  std::size_t fromSrid,
1323  KD_ADAPTATIVE_TREE* kdtree)
1324 {
1325  std::size_t toGeomPos = te::da::GetFirstSpatialPropertyPos(toDs);
1326  std::auto_ptr<te::gm::Geometry> toGeom = toDs->getGeometry(toGeomPos);
1327 
1328  std::vector<te::gm::Point*> allPoints = getAllPointsOfGeometry(toGeom.get());
1329 
1330  std::vector<double> distances;
1331 
1332  for(std::size_t i = 0; i < allPoints.size(); ++i)
1333  {
1334  te::gm::Point* p = allPoints[i];
1335  te::gm::Coord2D key = te::gm::Coord2D(p->getX(), p->getY());
1336  std::vector<te::gm::Point> points;
1337  points.push_back(te::gm::Point(std::numeric_limits<double>::max(), std::numeric_limits<double>::max()));
1338  std::vector<double> sqrDists;
1339 
1340  kdtree->nearestNeighborSearch(key, points, sqrDists, 1);
1341 
1342  distances.push_back(sqrDists[0]);
1343  }
1344 
1345  double finalResult = std::numeric_limits<double>::max();
1346  for(std::size_t i = 0; i < distances.size(); ++i)
1347  {
1348  if(distances[i] < finalResult)
1349  finalResult = distances[i];
1350  }
1351 
1352  return sqrt(finalResult);
1353 }
1354 
1356 {
1357  std::size_t geomType = geom->getGeomTypeId();
1358 
1359  std::vector<te::gm::Point*> result;
1360 
1361  switch(geomType)
1362  {
1363  case te::gm::PointType:
1364  {
1365  te::gm::Point* g = dynamic_cast<te::gm::Point*>(geom);
1366  result.push_back(g);
1367  break;
1368  }
1370  {
1371  te::gm::MultiPoint* g = dynamic_cast<te::gm::MultiPoint*>(geom);
1372  for(std::size_t i = 0; i < g->getNumGeometries(); ++i)
1373  {
1374  te::gm::Geometry* gAux = g->getGeometryN(i);
1375 
1376  std::vector<te::gm::Point*> vec = getAllPointsOfGeometry(gAux);
1377  result.insert(result.end(), vec.begin(), vec.end());
1378  }
1379  break;
1380  }
1381  case te::gm::PolygonType:
1382  {
1383  te::gm::Polygon* g = dynamic_cast<te::gm::Polygon*>(geom);
1384 
1385  for(std::size_t i = 0; i < g->getNumRings(); ++i)
1386  {
1387 
1388  te::gm::Curve* c = g->getRingN(i);
1389 
1390  te::gm::LinearRing* lr = dynamic_cast<te::gm::LinearRing*>(c);
1391 
1392  for(std::size_t j = 0; j < lr->getNPoints(); ++j)
1393  {
1394  result.push_back(lr->getPointN(j));
1395  }
1396  }
1397 
1398  break;
1399  }
1401  {
1402  te::gm::MultiPolygon* g = dynamic_cast<te::gm::MultiPolygon*>(geom);
1403 
1404  for(std::size_t i = 0; i < g->getNumGeometries(); ++i)
1405  {
1406  te::gm::Geometry* gAux = g->getGeometryN(i);
1407 
1408  std::vector<te::gm::Point*> vec = getAllPointsOfGeometry(gAux);
1409  result.insert(result.end(), vec.begin(), vec.end());
1410  }
1411  break;
1412  }
1414  {
1415  te::gm::LineString* g = dynamic_cast<te::gm::LineString*>(geom);
1416 
1417  for(std::size_t i = 0; i < g->getNPoints(); ++i)
1418  {
1419  result.push_back(g->getPointN(i));
1420  }
1421 
1422  break;
1423  }
1425  {
1426  te::gm::MultiLineString* g = dynamic_cast<te::gm::MultiLineString*>(geom);
1427 
1428  for(std::size_t i = 0; i < g->getNumGeometries(); ++i)
1429  {
1430  te::gm::Geometry* gAux = g->getGeometryN(i);
1431 
1432  std::vector<te::gm::Point*> vec = getAllPointsOfGeometry(gAux);
1433  result.insert(result.end(), vec.begin(), vec.end());
1434  }
1435 
1436  break;
1437  }
1438  default:
1439  {
1440  return std::vector<te::gm::Point*>();
1441  }
1442  }
1443 
1444  return result;
1445 }
1446 
1448 {
1449  std::map<std::string, std::vector<te::attributefill::OperationType> >::iterator it = m_options.begin();
1450 
1451  while(it != m_options.end())
1452  {
1453  std::vector<te::attributefill::OperationType> ops = it->second;
1454 
1455  for(std::size_t i = 0; i < ops.size(); ++i)
1456  {
1457  if(ops[i] == te::attributefill::MIN_DISTANCE ||
1458  ops[i] == te::attributefill::PRESENCE)
1459  return true;
1460  }
1461  ++it;
1462  }
1463 
1464  return false;
1465 }
1466 
1468 {
1469  if(!fromGeom->isValid())
1470  {
1471  std::string ex = TE_TR("\"From\" layer geometry at position ");
1472  ex += boost::lexical_cast<std::string>(fromPos);
1473  ex += TE_TR(" is invalid.");
1474 #ifdef TERRALIB_LOGGER_ENABLED
1475  te::common::Logger::logDebug("attributefill", ex.c_str());
1476 #endif //TERRALIB_LOGGER_ENABLED
1477 
1478  return false;
1479  }
1480  else if(!toGeom->isValid())
1481  {
1482  std::string ex = TE_TR("\"To\" layer geometry is invalid.");
1483 #ifdef TERRALIB_LOGGER_ENABLED
1484  te::common::Logger::logDebug("attributefill", ex.c_str());
1485 #endif //TERRALIB_LOGGER_ENABLED
1486 
1487  return false;
1488  }
1489 
1490  return true;
1491 }
TESTATEXPORT void GetNumericStatisticalSummary(std::vector< double > &values, te::stat::NumericStatisticalSummary &ss, double nullVal)
std::vector< te::gm::Point * > getAllPointsOfGeometry(te::gm::Geometry *geom)
It get all points of a geometry.
double getValue(te::stat::NumericStatisticalSummary ss, te::attributefill::OperationType type)
It get the value of required operation type from numeric statistical summary.
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
Definition: CurvePolygon.h:153
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
void transform(int srid)
It converts the coordinate values of the point to the new spatial reference system.
bool isStatistical(te::attributefill::OperationType type)
It verify if the operation is a statistical operation.
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
Definition: Geometry.h:189
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
A structure to hold the set of statistics from a set of numerical values.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
std::vector< te::dt::AbstractData * > getDataValues(te::da::DataSet *fromDs, std::vector< std::size_t > dsPos, const std::string &propertyName)
It get the value of all positions in "To" data set that has intersection with a position of "From" da...
Configuration flags for the Attribute Fill module of TerraLib.
std::vector< std::string > getStrValues(std::vector< te::dt::AbstractData * > data)
It get the string values of a vector of abstract data.
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
Definition: Envelope.h:493
An atomic property like an integer or double.
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
Definition: StringUtils.h:197
A class that represents an R-tree.
Definition: Index.h:56
A class that models the description of a dataset.
Definition: DataSetType.h:72
Curve is an abstract class that represents 1-dimensional geometric objects stored as a sequence of co...
Definition: Curve.h:58
virtual const char * what() const
It outputs the exception message.
Definition: Exception.cpp:58
void useTimer(bool flag)
Used to define if task use progress timer information.
te::dt::AbstractData * getDataBasedOnType(const std::string &strValue, const int type)
It get a abstract data with the value based on the type.
Point * getPointN(std::size_t i) const
It returns the specified point in this LineString.
Definition: LineString.cpp:323
A class that represents a two dimensional K-d Tree (2-d Tree) that store data-elements into the leafs...
Definition: Index.h:352
virtual Property * clone() const =0
It returns a clone of the object.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
Definition: DataSetType.h:214
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
bool checkGeometries(te::gm::Geometry *fromGeom, std::size_t fromPos, te::gm::Geometry *toGeom)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
std::string ReplaceSpecialChars(const std::string &str, bool &changed)
It replace special characters of a string.
Definition: StringUtils.h:537
It models a property definition.
Definition: Property.h:59
TEDATAACCESSEXPORT int GetPropertyIndex(te::da::DataSet *dataSet, const std::string propName)
Definition: Utils.cpp:919
bool isActive() const
Verify if the task is active.
double getPercentageOfTotalArea(te::da::DataSet *toDs, std::size_t toSrid, te::da::DataSet *fromDs, std::size_t fromSrid, std::vector< std::size_t > dsPos, const std::string &propertyName)
It get the percentage of intersection area in the total area.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
Definition: PrimaryKey.h:109
virtual bool move(std::size_t i)=0
It moves the dataset internal pointer to a given position.
void setTotalSteps(int value)
Set the task total stepes.
std::string getPropertyName(te::dt::Property *prop, te::attributefill::OperationType func)
It return a name based on original property name and the selected operation.
Vector to Vector processing.
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.
std::vector< double > getNumValues(std::vector< te::dt::AbstractData * > data)
It get the numeric values of a vector of abstract data.
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Definition: DataSet.h:65
virtual int code() const
It gets the exception code.
Definition: Exception.cpp:53
void setName(const std::string &name)
It sets the property name.
Definition: Property.h:137
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
void remove(Constraint *c)
It removes the constraint.
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
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
bool isMultiPoint(te::gm::GeomType type)
It verify if the geometry is a multi point.
const double & getY() const
It returns the Point y-coordinate value.
Definition: Point.h:150
A point with x and y coordinate values.
Definition: Point.h:50
double getWeightedSumByArea(te::da::DataSet *toDs, std::size_t toSrid, te::da::DataSet *fromDs, std::size_t fromSrid, std::vector< std::size_t > dsPos, const std::string &propertyName)
It get the sum of weighted average if intersections values.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
void build(std::vector< std::pair< kdKey, kdDataItem > > &dataSet)
It inserts the data set into the tree.
Definition: Index.h:431
std::vector< std::size_t > getIntersections(te::da::DataSet *toDs, te::da::DataSet *fromDs, te::sam::rtree::Index< size_t, 8 > *rtree)
It verify all intersection between the "From" and "To" data sets.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
te::sam::kdtree::AdaptativeIndex< KD_ADAPTATIVE_NODE > KD_ADAPTATIVE_TREE
bool hasNoIntersectionOperations()
Verify if has operations that don't need the intersections.
KD_ADAPTATIVE_TREE * getKDtree(te::da::DataSet *data, std::size_t toSrid)
It return a KDTree.
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
Definition: LineString.h:193
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
virtual std::string getAsString(std::size_t i, int precision=0) const
Method for retrieving a data value as a string plain representation.
Definition: DataSet.cpp:218
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
virtual bool isValid() const
It tells if the geometry is well formed.
Definition: Geometry.cpp:168
The type for string types: FIXED_STRING, VAR_STRING or STRING.
std::string getModeValue(te::stat::NumericStatisticalSummary ss)
It get a string with the mode operation format.
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
Definition: Index.h:326
double getWeightedByArea(te::da::DataSet *toDs, std::size_t toSrid, te::da::DataSet *fromDs, std::size_t fromSrid, std::vector< std::size_t > dsPos, const std::string &propertyName)
It get the weighted average if intersections values.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Definition: Geometry.h:178
std::vector< std::string > getDistinctClasses(te::da::DataSet *fromDs, const std::string &propertyName)
It return distincts values of a property from the "From" data set.
TESTATEXPORT void GetStringStatisticalSummary(std::vector< std::string > &values, te::stat::StringStatisticalSummary &ss)
std::map< std::string, double > getPercentagePerClass(te::da::DataSet *fromDs, std::vector< std::size_t > dsPos, const std::string &propertyName)
It get the percent per class from "From" data set in "To" data set.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
te::dt::AbstractData * getClassWithHighestOccurrence(te::da::DataSet *fromDs, std::vector< std::size_t > dsPos, const std::string &propertyName)
It get the class with highest occurrence from "From" data set in "To" data set.
double getArea() const
It returns the area of this surface, as measured in the spatial reference system of this surface...
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
int getType() const
It returns the property data type.
Definition: Property.h:161
void add(Constraint *c)
It adds a new constraint.
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
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
bool run()
It execute the operations.
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...
bool isLine(te::gm::GeomType type)
It verify if the geometry is a line.
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
Definition: Index.h:313
A structure to hold the set of statistics from a set of categorical (sample) values.
virtual std::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)=0
It computes the bounding rectangle for a spatial property of the dataset.
TEDATAACCESSEXPORT bool IsValidName(const std::string &name, std::string &invalidChar)
It checks if the name is not valid as the existence of invalid characters, reserved words...
Definition: Utils.cpp:934
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
void setRequired(bool r)
It tells if the property is required or not.
bool isPolygon(te::gm::GeomType type)
It verify if the geometry is a polygon.
te::da::DataSetType * getOutputDataSetType()
It create a data set type based on selecteds properties and operations.
te::dt::AbstractData * getClassWithHighestIntersectionArea(te::da::DataSet *toDs, std::size_t toSrid, te::da::DataSet *fromDs, std::size_t fromSrid, std::vector< std::size_t > dsPos, const std::string &propertyName)
It get the class with highest intersection area from "From" data set in "To" data set...
bool isMultiLine(te::gm::GeomType type)
It verify if the geometry is a multi line.
A template for atomic data types (integers, floats, strings and others).
Definition: SimpleData.h:59
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
bool isPoint(te::gm::GeomType type)
It verify if the geometry is a point.
It is a collection of other geometric objects.
double getMinimumDistance(te::da::DataSet *toDs, std::size_t toSrid, te::da::DataSet *fromDs, std::size_t fromSrid, KD_ADAPTATIVE_TREE *kdtree)
It get the minimum distance of objects that not intersect.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
void nearestNeighborSearch(const kdKey &key, std::vector< kdDataItem > &report, std::vector< double > &sqrDists, const std::size_t &k) const
It searches the nearest data in nodes: you must pass an array of kdDataItem of size "k" with coordina...
Definition: Index.h:441
double getArea(te::gm::Geometry *geom)
It get the area of a geometry.
OperationType
Define grouping operations type.
Definition: Enums.h:39
std::map< std::string, double > getPercentageOfEachClassByArea(te::da::DataSet *toDs, std::size_t toSrid, te::da::DataSet *fromDs, std::size_t fromSrid, std::vector< std::size_t > dsPos, const std::string &propertyName)
It get the percentage of each class intersection area in the total area.
const double & getX() const
It returns the Point x-coordinate value.
Definition: Point.h:136
bool isMultiPolygon(te::gm::GeomType type)
It verify if the geometry is a multi polygon.
virtual std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
Definition: DataSet.cpp:151
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
Definition: CurvePolygon.h:193
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
te::sam::rtree::Index< size_t, 8 > * getRtree(te::da::DataSet *data)
It return a RTree with data set iterator position information.