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/datasource/DataSource.h"
28 #include "../dataaccess/datasource/DataSourceCapabilities.h"
29 #include "../dataaccess/utils/Utils.h"
30 
31 #include "../datatype/Property.h"
32 #include "../datatype/SimpleProperty.h"
33 #include "../datatype/StringProperty.h"
34 
35 #include "../geometry/GeometryProperty.h"
36 
37 #include "../statistics/core/Utils.h"
38 
39 #include "BufferOp.h"
40 
42  : m_oidSet(0),
43  m_distance(-1.f),
44  m_bufferPolygonRule(-1),
45  m_bufferBoundariesRule(-1),
46  m_copyInputColumns(false),
47  m_levels(-1)
48 {
49 }
50 
52  std::string inDsetName,
53  std::auto_ptr<te::da::DataSetTypeConverter> converter,
54  const te::da::ObjectIdSet* oidSet)
55 {
56  m_inDsrc = inDsrc;
57  m_inDsetName = inDsetName;
58  m_converter = converter;
59  m_oidSet = oidSet;
60 }
61 
62 void te::vp::BufferOp::setParams(const double& distance,
63  const int& bufferPolygonRule,
64  const int& bufferBoundariesRule,
65  const bool& copyInputColumns,
66  const int& levels)
67 {
68  m_distance = distance;
69  m_bufferPolygonRule = bufferPolygonRule;
70  m_bufferBoundariesRule = bufferBoundariesRule;
71  m_copyInputColumns = copyInputColumns;
72  m_levels = levels;
73 }
74 
75 void te::vp::BufferOp::setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
76 {
77  m_outDsrc = outDsrc;
78  m_outDsetName = dsname;
79 }
80 
82 {
83  if (!m_converter->getResult()->hasGeom())
84  return false;
85 
86  if (m_outDsetName.empty() || !m_outDsrc.get())
87  return false;
88 
89  return true;
90 }
91 
93 {
94  te::da::DataSetType* dsType = new te::da::DataSetType(m_outDsetName);
95 
96  //Primary key
97  te::dt::SimpleProperty* pkProperty = new te::dt::SimpleProperty(m_outDsetName + "_id", te::dt::INT32_TYPE);
98  pkProperty->setAutoNumber(true);
99  dsType->add(pkProperty);
100 
101  te::da::PrimaryKey* pk = new te::da::PrimaryKey(m_outDsetName + "_pk", dsType);
102  pk->add(pkProperty);
103  dsType->setPrimaryKey(pk);
104 
106  dsType->add(levelProperty);
107 
108  te::dt::SimpleProperty* distanceProperty = new te::dt::SimpleProperty("distance", te::dt::DOUBLE_TYPE);
109  dsType->add(distanceProperty);
110 
111 
112  if(m_copyInputColumns)
113  {
114  std::vector<te::dt::Property*> props = m_converter->getResult()->getProperties();
115 
116  for(std::size_t i = 0; i < props.size(); ++i)
117  {
118  const std::string name = props[i]->getName();
119  int type = props[i]->getType();
120 
121  if(type != te::dt::GEOMETRY_TYPE && name != "FID")
122  {
123  te::dt::SimpleProperty* s_prop = new te::dt::SimpleProperty(name, type);
124  dsType->add(s_prop);
125  }
126  }
127  }
128 
129  te::gm::GeometryProperty* gp = te::da::GetFirstGeomProperty(m_converter->getResult());
130  std::auto_ptr<te::gm::GeometryProperty> p (static_cast<te::gm::GeometryProperty*>(gp->clone()));
131  te::gm::GeometryProperty* geometry = new te::gm::GeometryProperty("geom");
133  geometry->setSRID(p->getSRID());
134  dsType->add(geometry);
135 
136  return dsType;
137 }
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
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::auto_ptr< te::da::DataSetTypeConverter > converter, const te::da::ObjectIdSet *oidSet=0)
Definition: BufferOp.cpp:51
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:92
void setParams(const double &distance, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool &copyInputColumns, const int &levels)
Definition: BufferOp.cpp:62
virtual bool paramsAreValid()
Definition: BufferOp.cpp:81
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
Definition: BufferOp.cpp:75
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.