All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IntersectionOp.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 IntersectionOp.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/datasource/DataSource.h"
29 #include "../dataaccess/datasource/DataSourceCapabilities.h"
30 #include "../dataaccess/utils/Utils.h"
31 
32 #include "../datatype/Property.h"
33 #include "../datatype/StringProperty.h"
34 
35 #include "../geometry/GeometryProperty.h"
36 
37 #include "../statistics/core/Utils.h"
38 
39 #include "IntersectionOp.h"
40 
42  m_outDsetName("")
43 {
44 }
45 
47  std::string inFirstDsetName,
48  std::auto_ptr<te::da::DataSetType> inFirstDsetType,
49  te::da::DataSourcePtr inSecondDsrc,
50  std::string inSecondDsetName,
51  std::auto_ptr<te::da::DataSetType> inSecondDsetType,
52  const te::da::ObjectIdSet* firstOidSet,
53  const te::da::ObjectIdSet* secondOidSet)
54 {
55  m_inFirstDsrc = inFirstDsrc;
56  m_inFirstDsetName = inFirstDsetName;
57  m_inFirstDsetType = inFirstDsetType;
58  m_inSecondDsrc = inSecondDsrc;
59  m_inSecondDsetName = inSecondDsetName;
60  m_inSecondDsetType = inSecondDsetType;
61 
62  m_firstOidSet = firstOidSet;
63  m_secondOidSet = secondOidSet;
64 }
65 
66 void te::vp::IntersectionOp::setParams( const bool& copyInputColumns,
67  std::size_t inSRID)
68 {
69  m_copyInputColumns = copyInputColumns;
70  m_SRID = inSRID;
71 }
72 
74 {
75  m_outDsrc = outDsrc;
76  m_outDsetName = dsname;
77 }
78 
80 {
81  if (geom == te::gm::PolygonType)
83 
84  if (geom == te::gm::LineStringType)
86 
87  if (geom == te::gm::PointType)
89 
90  return geom;
91 }
92 
94 {
95  if (!m_inFirstDsetType.get())
96  return false;
97 
98  if (!m_inFirstDsetType->hasGeom())
99  return false;
100 
101  if (!m_inSecondDsetType.get())
102  return false;
103 
104  if (!m_inSecondDsetType->hasGeom())
105  return false;
106 
107  if (m_outDsetName.empty() || !m_outDsrc.get())
108  return false;
109 
110  return true;
111 }
112 
113 bool te::vp::IntersectionOp::save(std::auto_ptr<te::da::DataSet> result, std::auto_ptr<te::da::DataSetType> outDsType)
114 {
115  // do any adaptation necessary to persist the output dataset
116  te::da::DataSetTypeConverter* converter = new te::da::DataSetTypeConverter(outDsType.get(), m_outDsrc->getCapabilities());
117  te::da::DataSetType* dsTypeResult = converter->getResult();
118  std::auto_ptr<te::da::DataSetAdapter> dsAdapter(te::da::CreateAdapter(result.get(), converter));
119 
120  std::map<std::string, std::string> options;
121  // create the dataset
122  m_outDsrc->createDataSet(dsTypeResult, options);
123 
124  // copy from memory to output datasource
125  result->moveBeforeFirst();
126  m_outDsrc->add(dsTypeResult->getName(),result.get(), options);
127 
128  // create the primary key if it is possible
129  if (m_outDsrc->getCapabilities().getDataSetTypeCapabilities().supportsPrimaryKey())
130  {
131  std::string pk_name = dsTypeResult->getName() + "_pkey";
132  te::da::PrimaryKey* pk = new te::da::PrimaryKey(pk_name, dsTypeResult);
133  pk->add(dsTypeResult->getProperty(0));
134  m_outDsrc->addPrimaryKey(m_outDsetName,pk);
135  }
136 
137  return true;
138 }
139 
140 std::vector<te::dt::Property*> te::vp::IntersectionOp::getTabularProps(te::da::DataSetType* dsType)
141 {
142  std::vector<te::dt::Property*> props;
143  te::dt::Property* prop;
144 
145  for(std::size_t i = 0; i < dsType->getProperties().size(); ++i)
146  {
147  prop = dsType->getProperty(i);
148 
149  if(prop->getType() != te::dt::GEOMETRY_TYPE && prop->getType() != te::dt::NUMERIC_TYPE)
150  {
151  props.push_back(prop);
152  }
153  }
154 
155  return props;
156 }
std::vector< te::dt::Property * > getTabularProps(te::da::DataSetType *dsType)
Property * getProperty(std::size_t i) const
It returns the i-th property.
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
void setInput(te::da::DataSourcePtr inFirstDsrc, std::string inFirstDsetName, std::auto_ptr< te::da::DataSetType > inFirstDsetType, te::da::DataSourcePtr inSecondDsrc, std::string inSecondDsetName, std::auto_ptr< te::da::DataSetType > inSecondDsetType, const te::da::ObjectIdSet *firstOidSet=0, const te::da::ObjectIdSet *secondOidSet=0)
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
A class that models the description of a dataset.
Definition: DataSetType.h:72
bool save(std::auto_ptr< te::da::DataSet > result, std::auto_ptr< te::da::DataSetType > outDsType)
virtual bool paramsAreValid()
It models a property definition.
Definition: Property.h:59
An converter for DataSetType.
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
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(const bool &copyInputColumns, std::size_t inSRID)
Intersection operation.
int getType() const
It returns the property data type.
Definition: Property.h:143
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
te::gm::GeomType getGeomResultType(te::gm::GeomType geom)