Loading...
Searching...
No Matches
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 "../sam/rtree/Index.h"
38#include "Config.h"
39#include "VectorToVectorOp.h"
40
41// STL
42#include <map>
43#include <memory>
44#include <string>
45#include <vector>
46
49
50namespace te
51{
52 namespace dt
53 {
54 class AbstractData;
55 }
56
57 namespace gm
58 {
59 class Geometry;
60 }
61
62 namespace stat
63 {
66 }
67
68 namespace attributefill
69 {
70 /*!
71 \class VectorToVector
72
73 \brief A class that execute vector to vector operations in the memory.
74
75 \sa DataSourceManager, DataSourceFactory, DataSet, DataSetType
76 */
78 {
79 public:
80
81 /*!
82 \brief Constructor.
83 */
85
87
88 /*!
89 \brief It set the input informations
90
91 \param fromLayer Te "From" Layer.
92 \param toLayer The "To" Layer.
93 */
96
97 /*!
98 \brief It set the params used to execute.
99
100 \param options Property and string vector map with informations about which property was selected
101 and which operations were selected to this property.
102 */
103 void setParams(const std::map<te::dt::Property*, std::vector<std::string> >& options);
104
105 /*!
106 \brief It set output.
107
108 \param outDsrc The Data Source that will be the result.
109 \param dsName The name of output data set.
110 */
111 void setOutput(te::da::DataSourcePtr outDsrc, std::string dsName);
112
113 /*!
114 \brief It execute the operations.
115
116 \return True if execute.
117 */
118 bool run();
119
120 protected:
121
122 /*!
123 \brief It return a RTree with data set iterator position information.
124
125 \param data The Data Set.
126
127 \return The Rtree.
128 */
130
131 /*!
132 \brief It return a KDTree.
133
134 \param data The Data Set.
135 \param toSrid Data Set srid.
136
137 \return The KDtree.
138 */
139 KD_ADAPTATIVE_TREE* getKDtree(te::da::DataSet* data, std::size_t toSrid);
140
141 /*!
142 \brief It create a data set type based on selecteds properties and operations.
143
144 \return A Data Set Type.
145 */
147
148 /*!
149 \brief It return distincts values of a property from the "From" data set.
150
151 \param fromDs The "From" data set.
152 \param propertyName The property name with the information.
153
154 \return A vector of string values.
155 */
156 std::vector<std::string> getDistinctClasses(te::da::DataSet* fromDs, const std::string& propertyName);
157
158 /*!
159 \brief It return a name based on original property name and the selected operation.
160
161 \param prop The original property.
162 \param func The selected operation.
163
164 \return A name based on the property and operation.
165 */
167
168 /*!
169 \brief It verify if the operation is a statistical operation.
170
171 \param type The operation type.
172
173 \return True if the operation were statistical.
174 */
176
177 /*!
178 \brief It verify all intersection between the "From" and "To" data sets.
179
180 \param toDs The "To" data set.
181 \param fromDs The "From" data set.
182 \param rtree A generated RTree based on the "From" data set.
183 \param hasInvalid Set true if there are any invalid geometry as intersection candidate.
184
185 \return A vector of positions that "To" data set has intersection with "From".
186 */
187 std::vector<std::size_t> getIntersections(te::da::DataSet* toDs,
188 te::da::DataSet* fromDs,
190 bool& hasInvalid);
191
192 /*!
193 \brief It get the value of all positions in "To" data set that has intersection with
194 a position of "From" data set.
195
196 \param fromDs The "From" data set.
197 \param dsPos Vector of intersections positions.
198 \param propertyName The property name.
199
200 \note The fromDs iterator must be in the correct position.
201
202 \return A vector of values.
203 */
204 std::vector<std::vector<te::dt::AbstractData*> > getDataValues(te::da::DataSet* fromDs,
205 std::vector<std::size_t> dsPos);
206
207 /*!
208 \brief It get the numeric values of a vector of abstract data.
209
210 \param data Vector of abstract data.
211
212 \return A vector of double values.
213 */
214 std::vector<double> getNumValues(std::vector< std::vector<te::dt::AbstractData*> > dataValues, std::size_t pos);
215
216 /*!
217 \brief It get the string values of a vector of abstract data.
218
219 \param data Vector of abstract data.
220
221 \return A vector of string values.
222 */
223 std::vector<std::string> getStrValues(std::vector< std::vector<te::dt::AbstractData*> > dataValues, std::size_t pos);
224
226 const std::string& propertyName,
227 std::vector< std::vector<te::dt::AbstractData*> >& dataValues);
228
229 /*!
230 \brief It get the value of required operation type from numeric statistical summary
231
232 \param ss The numeric statistical summary.
233 \param type Required operation type.
234
235 \return The double value.
236 */
238
239 /*!
240 \brief It get the value of required operation type from string statistical summary
241
242 \param ss The string statistical summary.
243 \param type Required operation type.
244
245 \return The string value.
246 */
248
249 /*!
250 \brief It get a string with the mode operation format.
251
252 \param ss The string statistical summary.
253
254 \return The string value.
255 */
257
258 /*!
259 \brief It get the class with highest occurrence from "From" data set in "To" data set.
260
261 \param fromDs The "From" data set.
262 \param dsPos Vector of "To" data set positions that intersect "From".
263 \param propertyName Required property name.
264 \param dataValues Vector that contains all values of the item that intersects the "To" data set. (line and columns).
265
266 \return The class value.
267 */
269 std::vector<std::size_t> dsPos,
270 const std::string& propertyName,
271 std::vector< std::vector<te::dt::AbstractData*> >& dataValues);
272
273 /*!
274 \brief It get the class with highest intersection area from "From" data set in "To" data set.
275
276 \param toDs The "To" data set.
277 \param toSrid The "To" data set srid.
278 \param fromDs The "From" data set.
279 \param fromSrid The "From" data set srid.
280 \param dsPos Vector of "To" data set positions that intersect "From".
281 \param propertyName Required property name.
282 \param dataValues Vector that contains all values of the item that intersects the "To" data set. (line and columns).
283
284 \return The class value.
285 */
287 std::size_t toSrid,
288 te::da::DataSet* fromDs,
289 std::size_t fromSrid,
290 std::vector<std::size_t> dsPos,
291 const std::string& propertyName,
292 std::vector< std::vector<te::dt::AbstractData*> >& dataValues);
293
294 /*!
295 \brief It get a abstract data with the value based on the type.
296
297 \param strValue The string value.
298 \param type The value type.
299
300 \return The value.
301 */
302 te::dt::AbstractData* getDataBasedOnType(const std::string& strValue, const int type);
303
304 /*!
305 \brief It get the percent per class from "From" data set in "To" data set.
306
307 \param fromDs The "From" data set.
308 \param dsPos Vector of "To" data set positions that intersect "From".
309 \param propertyName Required property name.
310 \param dataValues Vector that contains all values of the item that intersects the "To" data set. (line and columns).
311
312 \return Map with class value and percentage.
313 */
314 std::map<std::string, double> getPercentagePerClass(te::da::DataSet* fromDs,
315 std::vector<std::size_t> dsPos,
316 const std::string& propertyName,
317 std::vector< std::vector<te::dt::AbstractData*> >& dataValues);
318
319 /*!
320 \brief It get the percentage of intersection area in the total area.
321
322 \param toDs The "To" data set.
323 \param toSrid The "To" data set srid.
324 \param fromDs The "From" data set.
325 \param fromSrid The "From" data set srid.
326 \param dsPos Vector of "To" data set positions that intersect "From".
327 \param propertyName Required property name.
328 \param dataValues Vector that contains all values of the item that intersects the "To" data set. (line and columns).
329
330 \return The percentage.
331 */
333 std::size_t toSrid,
334 te::da::DataSet* fromDs,
335 std::size_t fromSrid,
336 std::vector<std::size_t> dsPos,
337 const std::string& propertyName,
338 std::vector< std::vector<te::dt::AbstractData*> >& dataValues);
339
340 /*!
341 \brief It get the percentage of each class intersection area in the total area.
342
343 \param toDs The "To" data set.
344 \param toSrid The "To" data set srid.
345 \param fromDs The "From" data set.
346 \param fromSrid The "From" data set srid.
347 \param dsPos Vector of "To" data set positions that intersect "From".
348 \param propertyName Required property name.
349 \param dataValues Vector that contains all values of the item that intersects the "To" data set. (line and columns).
350
351 \return Map of class and percentage.
352 */
353 std::map<std::string, double> getPercentageOfEachClassByArea(te::da::DataSet* toDs,
354 std::size_t toSrid,
355 te::da::DataSet* fromDs,
356 std::size_t fromSrid,
357 std::vector<std::size_t> dsPos,
358 const std::string& propertyName,
359 std::vector< std::vector<te::dt::AbstractData*> >& dataValues);
360
361 /*!
362 \brief It get the total area of each class intersection.
363
364 \param toDs The "To" data set.
365 \param toSrid The "To" data set srid.
366 \param fromDs The "From" data set.
367 \param fromSrid The "From" data set srid.
368 \param dsPos Vector of "To" data set positions that intersect "From".
369 \param propertyName Required property name.
370 \param dataValues Vector that contains all values of the item that intersects the "To" data set. (line and columns).
371
372 \return Map of class and area.
373 */
374 std::map<std::string, double> getTotalAreaByClass(te::da::DataSet* toDs,
375 std::size_t toSrid,
376 te::da::DataSet* fromDs,
377 std::size_t fromSrid,
378 std::vector<std::size_t> dsPos,
379 const std::string& propertyName,
380 std::vector< std::vector<te::dt::AbstractData*> >& dataValues);
381
382 /*!
383 \brief It get the weighted average if intersections values.
384
385 \param toDs The "To" data set.
386 \param toSrid The "To" data set srid.
387 \param fromDs The "From" data set.
388 \param fromSrid The "From" data set srid.
389 \param dsPos Vector of "To" data set positions that intersect "From".
390 \param propertyName Required property name.
391 \param dataValues Vector that contains all values of the item that intersects the "To" data set. (line and columns).
392
393 \return The weighted average.
394 */
396 std::size_t toSrid,
397 te::da::DataSet* fromDs,
398 std::size_t fromSrid,
399 std::vector<std::size_t> dsPos,
400 const std::string& propertyName,
401 std::vector< std::vector<te::dt::AbstractData*> >& dataValues);
402
403 /*!
404 \brief It get the sum of weighted average if intersections values.
405
406 \param toDs The "To" data set.
407 \param toSrid The "To" data set srid.
408 \param fromDs The "From" data set.
409 \param fromSrid The "From" data set srid.
410 \param dsPos Vector of "To" data set positions that intersect "From".
411 \param propertyName Required property name.
412 \param dataValues Vector that contains all values of the item that intersects the "To" data set. (line and columns).
413
414 \return The sum of weighted average.
415 */
417 std::size_t toSrid,
418 te::da::DataSet* fromDs,
419 std::size_t fromSrid,
420 std::vector<std::size_t> dsPos,
421 const std::string& propertyName,
422 std::vector< std::vector<te::dt::AbstractData*> >& dataValues);
423
424 /*!
425 \brief It get the minimum distance of objects that not intersect.
426
427 \param toDs The "To" data set.
428 \param toSrid The "To" data set srid.
429 \param fromDs The "From" data set.
430 \param fromSrid The "From" data set srid.
431 \param kdtree A generated KDTree based on the "From" data set.
432
433 \return The minimum distance.
434 */
436 std::size_t toSrid,
437 te::da::DataSet* fromDs,
438 std::size_t fromSrid,
439 KD_ADAPTATIVE_TREE* kdtree);
440
441 /*!
442 \brief It get the minimum distance of objects centroid that not intersect.
443
444 \param toDs The "To" data set.
445 \param toSrid The "To" data set srid.
446 \param fromDs The "From" data set.
447 \param fromSrid The "From" data set srid.
448 \param kdtree A generated KDTree based on the "From" data set.
449
450 \return The minimum distance.
451 */
453 std::size_t toSrid,
454 te::da::DataSet* fromDs,
455 std::size_t fromSrid,
456 KD_ADAPTATIVE_TREE* kdtree,
458
459 /*!
460 \brief It verify if the geometry is a polygon.
461
462 \param type The geometry type.
463
464 \return True if were polygon.
465 */
467
468 /*!
469 \brief It verify if the geometry is a line.
470
471 \param type The geometry type.
472
473 \return True if were line.
474 */
476
477 /*!
478 \brief It verify if the geometry is a point.
479
480 \param type The geometry type.
481
482 \return True if were potin.
483 */
485
486 /*!
487 \brief It verify if the geometry is a multi polygon.
488
489 \param type The geometry type.
490
491 \return True if were multi polygon.
492 */
494
495 /*!
496 \brief It verify if the geometry is a multi line.
497
498 \param type The geometry type.
499
500 \return True if were multi line.
501 */
503
504 /*!
505 \brief It verify if the geometry is a multi point.
506
507 \param type The geometry type.
508
509 \return True if were multi point.
510 */
512
513 /*!
514 \brief It get the area of a geometry.
515
516 \param geom The geometry.
517
518 \return The area.
519 */
521
522 /*!
523 \brief It get all points of a geometry.
524
525 \param geom The geometry.
526
527 \return Vector of points.
528 */
529 std::vector<te::gm::Point*> getAllPointsOfGeometry(te::gm::Geometry* geom);
530
531 /*!
532 \brief Verify if has operations that don't need the intersections.
533
534 \return True if has.
535 */
537
538 void normalizeClassName(std::string& name);
539
540 bool checkGeometries(te::gm::Geometry* fromGeom, std::size_t fromPos, te::gm::Geometry* toGeom);
541
543
544 private:
545
546 std::map<std::size_t, te::gm::Geometry*> m_mapGeom; // All geometries of "From" Layer.
547 };
548 }
549}
550#endif // __TERRALIB_ATTRIBUTEFILL_INTERNAL_VECTORTOVECTORMEMORY_H
te::sam::kdtree::AdaptativeIndex< KD_ADAPTATIVE_NODE > KD_ADAPTATIVE_TREE
te::sam::kdtree::AdaptativeNode< te::gm::Coord2D, std::vector< te::gm::Point >, te::gm::Point > KD_ADAPTATIVE_NODE
Vector To Vector operation.
std::map< std::size_t, te::gm::Geometry * > m_mapGeom
bool isLine(te::gm::GeomType type)
It verify if the geometry is a line.
std::vector< te::gm::Point * > getAllPointsOfGeometry(te::gm::Geometry *geom)
It get all points of a geometry.
bool isMultiPoint(te::gm::GeomType type)
It verify if the geometry is a multi point.
std::vector< std::vector< te::dt::AbstractData * > > getDataValues(te::da::DataSet *fromDs, std::vector< std::size_t > dsPos)
It get the value of all positions in "To" data set that has intersection with a position of "From" da...
te::dt::AbstractData * getClassWithHighestOccurrence(te::da::DataSet *fromDs, std::vector< std::size_t > dsPos, const std::string &propertyName, std::vector< std::vector< te::dt::AbstractData * > > &dataValues)
It get the class with highest occurrence from "From" data set in "To" data set.
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, std::vector< std::vector< te::dt::AbstractData * > > &dataValues)
It get the class with highest intersection area from "From" data set in "To" data set.
bool isPolygon(te::gm::GeomType type)
It verify if the geometry is a polygon.
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.
bool isStatistical(te::attributefill::OperationType type)
It verify if the operation is a statistical operation.
std::string getModeValue(te::stat::NumericStatisticalSummary ss)
It get a string with the mode operation format.
bool isMultiLine(te::gm::GeomType type)
It verify if the geometry is a multi line.
bool checkGeometries(te::gm::Geometry *fromGeom, std::size_t fromPos, te::gm::Geometry *toGeom)
std::string getPropertyName(te::dt::Property *prop, te::attributefill::OperationType func)
It return a name based on original property name and the selected operation.
bool run()
It execute the operations.
bool isMultiPolygon(te::gm::GeomType type)
It verify if the geometry is a multi polygon.
void setInput(te::map::AbstractLayerPtr fromLayer, te::map::AbstractLayerPtr toLayer)
It set the input informations.
std::map< std::string, double > getPercentagePerClass(te::da::DataSet *fromDs, std::vector< std::size_t > dsPos, const std::string &propertyName, std::vector< std::vector< te::dt::AbstractData * > > &dataValues)
It get the percent per class from "From" data set in "To" data set.
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, std::vector< std::vector< te::dt::AbstractData * > > &dataValues)
It get the percentage of each class intersection area in the total area.
bool isPoint(te::gm::GeomType type)
It verify if the geometry is a point.
std::string getValue(te::stat::StringStatisticalSummary ss, te::attributefill::OperationType type)
It get the value of required operation type from string statistical summary.
te::dt::AbstractData * getDataBasedOnType(const std::string &strValue, const int type)
It get a abstract data with the value based on the type.
std::vector< std::size_t > getIntersections(te::da::DataSet *toDs, te::da::DataSet *fromDs, te::sam::rtree::Index< size_t, 8 > *rtree, bool &hasInvalid)
It verify all intersection between the "From" and "To" data sets.
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, std::vector< std::vector< te::dt::AbstractData * > > &dataValues)
It get the percentage of intersection area in the total area.
double getValue(te::stat::NumericStatisticalSummary ss, te::attributefill::OperationType type)
It get the value of required operation type from numeric statistical summary.
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsName)
It set output.
bool hasNoIntersectionOperations()
Verify if has operations that don't need the intersections.
std::vector< double > getNumValues(std::vector< std::vector< te::dt::AbstractData * > > dataValues, std::size_t pos)
It get the numeric values of a vector of abstract data.
void normalizeClassName(std::string &name)
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, std::vector< std::vector< te::dt::AbstractData * > > &dataValues)
It get the sum of weighted average if intersections values.
std::map< std::string, double > getTotalAreaByClass(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, std::vector< std::vector< te::dt::AbstractData * > > &dataValues)
It get the total area of each class intersection.
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.
te::sam::rtree::Index< size_t, 8 > * getRtree(te::da::DataSet *data)
It return a RTree with data set iterator position information.
double getArea(te::gm::Geometry *geom)
It get the area of a geometry.
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, std::vector< std::vector< te::dt::AbstractData * > > &dataValues)
It get the weighted average if intersections values.
void setParams(const std::map< te::dt::Property *, std::vector< std::string > > &options)
It set the params used to execute.
double getMinimumDistanceFromCentroid(te::da::DataSet *toDs, std::size_t toSrid, te::da::DataSet *fromDs, std::size_t fromSrid, KD_ADAPTATIVE_TREE *kdtree, te::sam::rtree::Index< size_t, 8 > *rtree)
It get the minimum distance of objects centroid that not intersect.
std::vector< std::string > getStrValues(std::vector< std::vector< te::dt::AbstractData * > > dataValues, std::size_t pos)
It get the string values of a vector of abstract data.
te::da::DataSetType * getOutputDataSetType()
It create a data set type based on selecteds properties and operations.
KD_ADAPTATIVE_TREE * getKDtree(te::da::DataSet *data, std::size_t toSrid)
It return a KDTree.
int getTotalNumberOfDistinctValues(te::da::DataSet *fromDs, const std::string &propertyName, std::vector< std::vector< te::dt::AbstractData * > > &dataValues)
A class that models the description of a dataset.
Definition: DataSetType.h:73
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:114
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:56
It models a property definition.
Definition: Property.h:60
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
A point with x and y coordinate values.
Definition: Point.h:51
A class that represents a two dimensional K-d Tree (2-d Tree) that store data-elements into the leafs...
Definition: Index.h:375
A class that represents an Kd-tree node.
Definition: Node.h:207
A class that represents an R-tree.
Definition: Index.h:57
OperationType
Define grouping operations type.
Definition: Enums.h:40
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1449
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:42
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TerraLib.
A structure to hold the set of statistics from a set of numerical values.
A structure to hold the set of statistics from a set of categorical (sample) values.
#define TEATTRIBUTEFILLEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
Proxy configuration file for TerraView (see terraview_config.h).