All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VectorToVectorMemory.h
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 terralib/attributefill/VectorToVectorMemory.h
22 
23  \brief A class that execute vector to vector operations in the memory.
24 */
25 
26 #ifndef __TERRALIB_ATTRIBUTEFILL_INTERNAL_VECTORTOVECTORMEMORY_H
27 #define __TERRALIB_ATTRIBUTEFILL_INTERNAL_VECTORTOVECTORMEMORY_H
28 
29 //Terralib
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "../dataaccess/dataset/DataSetType.h"
32 #include "../dataaccess/datasource/DataSource.h"
33 #include "../datatype/Property.h"
34 #include "../maptools/AbstractLayer.h"
35 #include "../memory/DataSet.h"
36 #include "../sam/kdtree.h"
37 #include "Config.h"
38 #include "VectorToVectorOp.h"
39 
40 // STL
41 #include <map>
42 #include <memory>
43 #include <string>
44 #include <vector>
45 
48 
49 namespace te
50 {
51  namespace dt
52  {
53  class AbstractData;
54  }
55 
56  namespace gm
57  {
58  class Geometry;
59  }
60 
61  namespace stat
62  {
65  }
66 
67  namespace attributefill
68  {
69  /*!
70  \class VectorToVector
71 
72  \brief A class that execute vector to vector operations in the memory.
73 
74  \sa DataSourceManager, DataSourceFactory, DataSet, DataSetType
75  */
77  {
78  public:
79 
80  /*!
81  \brief Constructor.
82  */
84 
86 
87  /*!
88  \brief It set the input informations
89 
90  \param fromLayer Te "From" Layer.
91  \param toLayer The "To" Layer.
92  */
93  void setInput(te::map::AbstractLayerPtr fromLayer,
95 
96  /*!
97  \brief It set the params used to execute.
98 
99  \param options Property and string vector map with informations about which property was selected
100  and which operations were selected to this property.
101  */
102  void setParams(const std::map<te::dt::Property*, std::vector<std::string> >& options);
103 
104  /*!
105  \brief It set output.
106 
107  \param outDsrc The Data Source that will be the result.
108  \param dsName The name of output data set.
109  */
110  void setOutput(te::da::DataSourcePtr outDsrc, std::string dsName);
111 
112  /*!
113  \brief It execute the operations.
114 
115  \return True if execute.
116  */
117  bool run();
118 
119  protected:
120 
121  /*!
122  \brief It return a RTree with data set iterator position information.
123 
124  \param data The Data Set.
125 
126  \return The Rtree.
127  */
129 
130  /*!
131  \brief It return a KDTree.
132 
133  \param data The Data Set.
134  \param toSrid Data Set srid.
135 
136  \return The KDtree.
137  */
138  KD_ADAPTATIVE_TREE* getKDtree(te::da::DataSet* data, std::size_t toSrid);
139 
140  /*!
141  \brief It create a data set type based on selecteds properties and operations.
142 
143  \return A Data Set Type.
144  */
145  te::da::DataSetType* getOutputDataSetType();
146 
147  /*!
148  \brief It return distincts values of a property from the "From" data set.
149 
150  \param fromDs The "From" data set.
151  \param propertyName The property name with the information.
152 
153  \return A vector of string values.
154  */
155  std::vector<std::string> getDistinctClasses(te::da::DataSet* fromDs, const std::string& propertyName);
156 
157  /*!
158  \brief It return a name based on original property name and the selected operation.
159 
160  \param prop The original property.
161  \param func The selected operation.
162 
163  \return A name based on the property and operation.
164  */
165  std::string getPropertyName(te::dt::Property* prop, te::attributefill::OperationType func);
166 
167  /*!
168  \brief It verify if the operation is a statistical operation.
169 
170  \param type The operation type.
171 
172  \return True if the operation were statistical.
173  */
174  bool isStatistical(te::attributefill::OperationType type);
175 
176  /*!
177  \brief It verify all intersection between the "From" and "To" data sets.
178 
179  \param toDs The "To" data set.
180  \param fromDs The "From" data set.
181  \param rtree A generated RTree based on the "From" data set.
182 
183  \return A vector of positions that "To" data set has intersection with "From".
184  */
185  std::vector<std::size_t> getIntersections(te::da::DataSet* toDs,
186  te::da::DataSet* fromDs,
188 
189  /*!
190  \brief It get the value of all positions in "To" data set that has intersection with
191  a position of "From" data set.
192 
193  \param fromDs The "From" data set.
194  \param dsPos Vector of intersections positions.
195  \param propertyName The property name.
196 
197  \note The fromDs iterator must be in the correct position.
198 
199  \return A vector of values.
200  */
201  std::vector<te::dt::AbstractData*> getDataValues(te::da::DataSet* fromDs,
202  std::vector<std::size_t> dsPos,
203  const std::string& propertyName);
204 
205  /*!
206  \brief It get the numeric values of a vector of abstract data.
207 
208  \param data Vector of abstract data.
209 
210  \return A vector of double values.
211  */
212  std::vector<double> getNumValues(std::vector<te::dt::AbstractData*> data);
213 
214  /*!
215  \brief It get the string values of a vector of abstract data.
216 
217  \param data Vector of abstract data.
218 
219  \return A vector of string values.
220  */
221  std::vector<std::string> getStrValues(std::vector<te::dt::AbstractData*> data);
222 
223  /*!
224  \brief It get the value of required operation type from numeric statistical summary
225 
226  \param ss The numeric statistical summary.
227  \param type Required operation type.
228 
229  \return The double value.
230  */
232 
233  /*!
234  \brief It get the value of required operation type from string statistical summary
235 
236  \param ss The string statistical summary.
237  \param type Required operation type.
238 
239  \return The string value.
240  */
242 
243  /*!
244  \brief It get a string with the mode operation format.
245 
246  \param ss The string statistical summary.
247 
248  \return The string value.
249  */
250  std::string getModeValue(te::stat::NumericStatisticalSummary ss);
251 
252  /*!
253  \brief It get the class with highest occurrence from "From" data set in "To" data set.
254 
255  \param fromDs The "From" data set.
256  \param dsPos Vector of "To" data set positions that intersect "From".
257  \param propertyName Required property name.
258 
259  \return The class value.
260  */
261  te::dt::AbstractData* getClassWithHighestOccurrence(te::da::DataSet* fromDs,
262  std::vector<std::size_t> dsPos,
263  const std::string& propertyName);
264 
265  /*!
266  \brief It get the class with highest intersection area from "From" data set in "To" data set.
267 
268  \param toDs The "To" data set.
269  \param toSrid The "To" data set srid.
270  \param fromDs The "From" data set.
271  \param fromSrid The "From" data set srid.
272  \param dsPos Vector of "To" data set positions that intersect "From".
273  \param propertyName Required property name.
274 
275  \return The class value.
276  */
277  te::dt::AbstractData* getClassWithHighestIntersectionArea(te::da::DataSet* toDs,
278  std::size_t toSrid,
279  te::da::DataSet* fromDs,
280  std::size_t fromSrid,
281  std::vector<std::size_t> dsPos,
282  const std::string& propertyName);
283 
284  /*!
285  \brief It get a abstract data with the value based on the type.
286 
287  \param strValue The string value.
288  \param type The value type.
289 
290  \return The value.
291  */
292  te::dt::AbstractData* getDataBasedOnType(const std::string& strValue, const int type);
293 
294  /*!
295  \brief It get the percent per class from "From" data set in "To" data set.
296 
297  \param fromDs The "From" data set.
298  \param dsPos Vector of "To" data set positions that intersect "From".
299  \param propertyName Required property name.
300 
301  \return Map with class value and percentage.
302  */
303  std::map<std::string, double> getPercentagePerClass(te::da::DataSet* fromDs,
304  std::vector<std::size_t> dsPos,
305  const std::string& propertyName);
306 
307  /*!
308  \brief It get the percentage of intersection area in the total area.
309 
310  \param toDs The "To" data set.
311  \param toSrid The "To" data set srid.
312  \param fromDs The "From" data set.
313  \param fromSrid The "From" data set srid.
314  \param dsPos Vector of "To" data set positions that intersect "From".
315  \param propertyName Required property name.
316 
317  \return The percentage.
318  */
319  double getPercentageOfTotalArea(te::da::DataSet* toDs,
320  std::size_t toSrid,
321  te::da::DataSet* fromDs,
322  std::size_t fromSrid,
323  std::vector<std::size_t> dsPos,
324  const std::string& propertyName);
325 
326  /*!
327  \brief It get the percentage of each class intersection area in the total area.
328 
329  \param toDs The "To" data set.
330  \param toSrid The "To" data set srid.
331  \param fromDs The "From" data set.
332  \param fromSrid The "From" data set srid.
333  \param dsPos Vector of "To" data set positions that intersect "From".
334  \param propertyName Required property name.
335 
336  \return Map of class and percentage.
337  */
338  std::map<std::string, double> getPercentageOfEachClassByArea(te::da::DataSet* toDs,
339  std::size_t toSrid,
340  te::da::DataSet* fromDs,
341  std::size_t fromSrid,
342  std::vector<std::size_t> dsPos,
343  const std::string& propertyName);
344 
345  /*!
346  \brief It get the weighted average if intersections values.
347 
348  \param toDs The "To" data set.
349  \param toSrid The "To" data set srid.
350  \param fromDs The "From" data set.
351  \param fromSrid The "From" data set srid.
352  \param dsPos Vector of "To" data set positions that intersect "From".
353  \param propertyName Required property name.
354 
355  \return The weighted average.
356  */
357  double getWeightedByArea(te::da::DataSet* toDs,
358  std::size_t toSrid,
359  te::da::DataSet* fromDs,
360  std::size_t fromSrid,
361  std::vector<std::size_t> dsPos,
362  const std::string& propertyName);
363 
364  /*!
365  \brief It get the sum of weighted average if intersections values.
366 
367  \param toDs The "To" data set.
368  \param toSrid The "To" data set srid.
369  \param fromDs The "From" data set.
370  \param fromSrid The "From" data set srid.
371  \param dsPos Vector of "To" data set positions that intersect "From".
372  \param propertyName Required property name.
373 
374  \return The sum of weighted average.
375  */
376  double getWeightedSumByArea(te::da::DataSet* toDs,
377  std::size_t toSrid,
378  te::da::DataSet* fromDs,
379  std::size_t fromSrid,
380  std::vector<std::size_t> dsPos,
381  const std::string& propertyName);
382 
383  /*!
384  \brief It get the minimum distance of objects that not intersect.
385 
386  \param toDs The "To" data set.
387  \param toSrid The "To" data set srid.
388  \param fromDs The "From" data set.
389  \param fromSrid The "From" data set srid.
390  \param kdtree A generated KDTree based on the "From" data set.
391 
392  \return The minimum distance.
393  */
394  double getMinimumDistance(te::da::DataSet* toDs,
395  std::size_t toSrid,
396  te::da::DataSet* fromDs,
397  std::size_t fromSrid,
398  KD_ADAPTATIVE_TREE* kdtree);
399 
400  /*!
401  \brief It verify if the geometry is a polygon.
402 
403  \param type The geometry type.
404 
405  \return True if were polygon.
406  */
407  bool isPolygon(te::gm::GeomType type);
408 
409  /*!
410  \brief It verify if the geometry is a line.
411 
412  \param type The geometry type.
413 
414  \return True if were line.
415  */
416  bool isLine(te::gm::GeomType type);
417 
418  /*!
419  \brief It verify if the geometry is a point.
420 
421  \param type The geometry type.
422 
423  \return True if were potin.
424  */
425  bool isPoint(te::gm::GeomType type);
426 
427  /*!
428  \brief It verify if the geometry is a multi polygon.
429 
430  \param type The geometry type.
431 
432  \return True if were multi polygon.
433  */
434  bool isMultiPolygon(te::gm::GeomType type);
435 
436  /*!
437  \brief It verify if the geometry is a multi line.
438 
439  \param type The geometry type.
440 
441  \return True if were multi line.
442  */
443  bool isMultiLine(te::gm::GeomType type);
444 
445  /*!
446  \brief It verify if the geometry is a multi point.
447 
448  \param type The geometry type.
449 
450  \return True if were multi point.
451  */
452  bool isMultiPoint(te::gm::GeomType type);
453 
454  /*!
455  \brief It get the area of a geometry.
456 
457  \param geom The geometry.
458 
459  \return The area.
460  */
461  double getArea(te::gm::Geometry* geom);
462 
463  /*!
464  \brief It get all points of a geometry.
465 
466  \param geom The geometry.
467 
468  \return Vector of points.
469  */
470  std::vector<te::gm::Point*> getAllPointsOfGeometry(te::gm::Geometry* geom);
471 
472  /*!
473  \brief Verify if has operations that don't need the intersections.
474 
475  \return True if has.
476  */
477  bool hasNoIntersectionOperations();
478 
479  void normalizeClassName(std::string& name);
480 
481  bool checkGeometries(te::gm::Geometry* fromGeom, std::size_t fromPos, te::gm::Geometry* toGeom);
482  };
483  }
484 }
485 #endif // __TERRALIB_ATTRIBUTEFILL_INTERNAL_VECTORTOVECTORMEMORY_H
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
Configuration flags for the Attribute Fill module of TerraLib.
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
A class that represents an R-tree.
Definition: Index.h:56
A class that models the description of a dataset.
Definition: DataSetType.h:72
A class that represents a two dimensional K-d Tree (2-d Tree) that store data-elements into the leafs...
Definition: Index.h:352
te::sam::kdtree::AdaptativeNode< te::gm::Coord2D, std::vector< te::gm::Point >, te::gm::Point > KD_ADAPTATIVE_NODE
It models a property definition.
Definition: Property.h:59
#define TEATTRIBUTEFILLEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:64
A point with x and y coordinate values.
Definition: Point.h:50
te::sam::kdtree::AdaptativeIndex< KD_ADAPTATIVE_NODE > KD_ADAPTATIVE_TREE
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
A structure to hold the set of statistics from a set of categorical (sample) values.
Vector To Vector operation.
A class that represents an Kd-tree node.
Definition: Node.h:206
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
OperationType
Define grouping operations type.
Definition: Enums.h:39