All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AggregationOp.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file AggregationOp.cpp
22  */
23 
24 #include "../dataaccess/dataset/DataSet.h"
25 #include "../dataaccess/dataset/DataSetAdapter.h"
26 #include "../dataaccess/dataset/DataSetType.h"
27 #include "../dataaccess/dataset/DataSetTypeConverter.h"
28 #include "../dataaccess/dataset/ObjectIdSet.h"
29 #include "../dataaccess/datasource/DataSource.h"
30 #include "../dataaccess/datasource/DataSourceCapabilities.h"
31 #include "../dataaccess/utils/Utils.h"
32 
33 #include "../datatype/Property.h"
34 #include "../datatype/StringProperty.h"
35 
36 #include "../geometry/GeometryProperty.h"
37 
38 #include "../statistics/core/Utils.h"
39 
40 #include "AggregationOp.h"
41 
43  m_outDset("")
44 {
45 }
46 
48  std::string inDsetName,
49  std::auto_ptr<te::da::DataSetType> inDsetType,
50  const te::da::ObjectIdSet* oidSet)
51 {
52  m_inDsrc = inDsrc;
53  m_inDsetName = inDsetName;
54  m_inDsetType = inDsetType;
55  m_oidSet = oidSet;
56 }
57 
58 void te::vp::AggregationOp::setParams(std::vector<te::dt::Property*>& groupProps,
59  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >&statSum)
60 {
61  m_groupProps = groupProps;
62  m_statSum = statSum;
63 }
64 
66 {
67  m_outDsrc = outDsrc;
68  m_outDset = dsname;
69 }
70 
72 {
73  if (geom == te::gm::PolygonType)
75 
76  if (geom == te::gm::LineStringType)
78 
79  if (geom == te::gm::PointType)
81 
82  return geom;
83 }
84 
86 {
87  if (!m_inDsetType.get())
88  return false;
89 
90  if (!m_inDsetType->hasGeom())
91  return false;
92 
93  if (m_groupProps.empty())
94  return false;
95 
96  if (m_outDset.empty() || !m_outDsrc.get())
97  return false;
98 
99  return true;
100 }
101 
102 bool te::vp::AggregationOp::save(std::auto_ptr<te::mem::DataSet> result, std::auto_ptr<te::da::DataSetType> outDsType)
103 {
104  // do any adaptation necessary to persist the output dataset
105  te::da::DataSetTypeConverter* converter = new te::da::DataSetTypeConverter(outDsType.get(), m_outDsrc->getCapabilities());
106  te::da::DataSetType* dsTypeResult = converter->getResult();
107  std::auto_ptr<te::da::DataSetAdapter> dsAdapter(te::da::CreateAdapter(result.get(), converter));
108 
109  std::map<std::string, std::string> options;
110  // create the dataset
111  m_outDsrc->createDataSet(dsTypeResult, options);
112 
113  // copy from memory to output datasource
114  result->moveBeforeFirst();
115  m_outDsrc->add(dsTypeResult->getName(),result.get(), options);
116 
117  // create the primary key if it is possible
118  if (m_outDsrc->getCapabilities().getDataSetTypeCapabilities().supportsPrimaryKey())
119  {
120  std::string pk_name = dsTypeResult->getName() + "_pkey";
121  te::da::PrimaryKey* pk = new te::da::PrimaryKey(pk_name, dsTypeResult);
122  pk->add(dsTypeResult->getProperty(0));
123  m_outDsrc->addPrimaryKey(m_outDset,pk);
124  }
125 
126  return true;
127 }
Aggregation operation.
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::auto_ptr< te::da::DataSetType > inDsetType, const te::da::ObjectIdSet *oidSet=0)
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
A class that models the description of a dataset.
Definition: DataSetType.h:72
te::gm::GeomType getGeomResultType(te::gm::GeomType geom)
It models a property definition.
Definition: Property.h:59
bool save(std::auto_ptr< te::mem::DataSet > result, std::auto_ptr< te::da::DataSetType > outDsType)
An converter for DataSetType.
virtual bool paramsAreValid()
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
void setParams(std::vector< te::dt::Property * > &groupProps, std::map< te::dt::Property *, std::vector< te::stat::StatisticalSummary > > &statSum)
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
Definition: Utils.cpp:595