All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BufferOp.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 BufferOp.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/SimpleProperty.h"
34 #include "../datatype/StringProperty.h"
35 
36 #include "../geometry/GeometryProperty.h"
37 
38 #include "../statistics/core/Utils.h"
39 
40 #include "BufferOp.h"
41 
43  m_outDsetName("")
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::BufferOp::setParams(const double& distance,
59  const int& bufferPolygonRule,
60  const int& bufferBoundariesRule,
61  const bool& copyInputColumns,
62  const int& levels)
63 {
64  m_distance = distance;
65  m_bufferPolygonRule = bufferPolygonRule;
66  m_bufferBoundariesRule = bufferBoundariesRule;
67  m_copyInputColumns = copyInputColumns;
68  m_levels = levels;
69 }
70 
71 void te::vp::BufferOp::setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
72 {
73  m_outDsrc = outDsrc;
74  m_outDsetName = dsname;
75 }
76 
78 {
79  if (!m_inDsetType->hasGeom())
80  return false;
81 
82  if (m_outDsetName.empty() || !m_outDsrc.get())
83  return false;
84 
85  return true;
86 }
87 
89 {
90  te::da::DataSetType* dsType = new te::da::DataSetType(m_outDsetName);
91 
92  //Primary key
93  te::dt::SimpleProperty* pkProperty = new te::dt::SimpleProperty(m_outDsetName + "_id", te::dt::INT32_TYPE);
94  pkProperty->setAutoNumber(true);
95  dsType->add(pkProperty);
96 
97  te::da::PrimaryKey* pk = new te::da::PrimaryKey(m_outDsetName + "_pk", dsType);
98  pk->add(pkProperty);
99  dsType->setPrimaryKey(pk);
100 
102  dsType->add(levelProperty);
103 
104  te::dt::SimpleProperty* distanceProperty = new te::dt::SimpleProperty("distance", te::dt::DOUBLE_TYPE);
105  dsType->add(distanceProperty);
106 
107 
108  if(m_copyInputColumns)
109  {
110  std::vector<te::dt::Property*> props = m_inDsetType->getProperties();
111 
112  for(std::size_t i = 0; i < props.size(); ++i)
113  {
114  const std::string name = props[i]->getName();
115  int type = props[i]->getType();
116 
117  if(type != te::dt::GEOMETRY_TYPE && name != "FID")
118  {
119  te::dt::SimpleProperty* s_prop = new te::dt::SimpleProperty(name, type);
120  dsType->add(s_prop);
121  }
122  }
123  }
124 
125  te::gm::GeometryProperty* gp = te::da::GetFirstGeomProperty(m_inDsetType.get());
126  std::auto_ptr<te::gm::GeometryProperty> p (static_cast<te::gm::GeometryProperty*>(gp->clone()));
127  te::gm::GeometryProperty* geometry = new te::gm::GeometryProperty("geom");
129  geometry->setSRID(p->getSRID());
130  dsType->add(geometry);
131 
132  return dsType;
133 }
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
Geometric property.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
An atomic property like an integer or double.
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
Buffer operation.
A class that models the description of a dataset.
Definition: DataSetType.h:72
te::dt::Property * clone() const
It returns a clone of the object.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
te::da::DataSetType * GetDataSetType()
Definition: BufferOp.cpp:88
void setParams(const double &distance, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool &copyInputColumns, const int &levels)
Definition: BufferOp.cpp:58
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::auto_ptr< te::da::DataSetType > inDsetType, const te::da::ObjectIdSet *oidSet=0)
Definition: BufferOp.cpp:47
virtual bool paramsAreValid()
Definition: BufferOp.cpp:77
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
Definition: BufferOp.cpp:71
void add(Constraint *c)
It adds a new constraint.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Definition: Utils.cpp:557
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.