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(nullptr),
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::unique_ptr<te::da::DataSetTypeConverter> converter,
54  const te::da::ObjectIdSet* oidSet)
55 {
56  m_inDsrc = inDsrc;
57  m_inDsetName = inDsetName;
58  m_converter = std::move(converter);
59  m_oidSet = oidSet;
60 }
61 
62 void te::vp::BufferOp::setParams(const double& distance,
63  const int& newSrid,
64  const int& bufferPolygonRule,
65  const int& bufferBoundariesRule,
66  const bool& copyInputColumns,
67  const int& levels,
68  const int& attributePosition)
69 {
70  m_distance = distance;
71  m_newSRID = newSrid;
72  m_bufferPolygonRule = bufferPolygonRule;
73  m_bufferBoundariesRule = bufferBoundariesRule;
74  m_copyInputColumns = copyInputColumns;
75  m_levels = levels;
76  m_attributePosition = attributePosition;
77 }
78 
79 void te::vp::BufferOp::setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
80 {
81  m_outDsrc = outDsrc;
82  m_outDsetName = dsname;
83 }
84 
86 {
87  if (!m_converter->getResult()->hasGeom())
88  return false;
89 
90  if (m_outDsetName.empty() || !m_outDsrc.get())
91  return false;
92 
93  return true;
94 }
95 
97 {
99 
100  //Primary key
102  pkProperty->setAutoNumber(true);
103  dsType->add(pkProperty);
104 
105  te::da::PrimaryKey* pk = new te::da::PrimaryKey(m_outDsetName + "_pk", dsType);
106  pk->add(pkProperty);
107  dsType->setPrimaryKey(pk);
108 
110  dsType->add(levelProperty);
111 
112  te::dt::SimpleProperty* distanceProperty = new te::dt::SimpleProperty("distance", te::dt::DOUBLE_TYPE);
113  dsType->add(distanceProperty);
114 
115 
117  {
118  std::vector<te::dt::Property*> props = m_converter->getResult()->getProperties();
119 
120  for(std::size_t i = 0; i < props.size(); ++i)
121  {
122  const std::string name = props[i]->getName();
123  int type = props[i]->getType();
124 
125  if(type != te::dt::GEOMETRY_TYPE && name != "FID")
126  {
127  te::dt::SimpleProperty* s_prop = new te::dt::SimpleProperty(name, type);
128  dsType->add(s_prop);
129  }
130  }
131  }
132 
134  std::unique_ptr<te::gm::GeometryProperty> p (static_cast<te::gm::GeometryProperty*>(gp->clone()));
135  te::gm::GeometryProperty* geometry = new te::gm::GeometryProperty("geom");
137  geometry->setSRID(p->getSRID());
138  dsType->add(geometry);
139 
140  return dsType;
141 }
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
double m_distance
The fixed distance.
Definition: BufferOp.h:142
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
Buffer operation.
A class that models the description of a dataset.
Definition: DataSetType.h:72
const te::da::ObjectIdSet * m_oidSet
The input objectid set.
Definition: BufferOp.h:140
void setParams(const double &distance, const int &newSrid, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool &copyInputColumns, const int &levels, const int &attributePosition=-1)
It sets the input parameters that will be consumed to execute the operation.
Definition: BufferOp.cpp:62
std::unique_ptr< te::da::DataSetTypeConverter > m_converter
The input datasettype.
Definition: BufferOp.h:139
te::dt::Property * clone() const
It returns a clone of the object.
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetTypeConverter > converter, const te::da::ObjectIdSet *oidSet=0)
It sets the input data will be calculated.
Definition: BufferOp.cpp:51
std::string m_outDsetName
The output dataset name.
Definition: BufferOp.h:151
int m_bufferPolygonRule
The buffer polygon rule (INSIDE_OUTSIDE = 0, ONLY_OUTSIDE = 1, ONLY_INSIDE = 2).
Definition: BufferOp.h:144
int m_levels
The number of levels buffer will have.
Definition: BufferOp.h:147
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()
It builds the output DataSetType.
Definition: BufferOp.cpp:96
int m_bufferBoundariesRule
The buffer boundary rule (DISSOLVE = 0 and NOT_DISSOLVE = 1).
Definition: BufferOp.h:145
virtual bool paramsAreValid()
It verifies if the parameters are valid.
Definition: BufferOp.cpp:85
te::gm::Polygon * p
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
It sets the output parameters that will be used to persist operation result.
Definition: BufferOp.cpp:79
void add(Constraint *c)
It adds a new constraint.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
int m_attributePosition
The buffer can be calculated by attribute values. The attribute must be numeric type.
Definition: BufferOp.h:148
bool m_copyInputColumns
Copy columns from input DataSet.
Definition: BufferOp.h:146
te::da::DataSourcePtr m_inDsrc
The input datasource.
Definition: BufferOp.h:137
te::da::DataSourcePtr m_outDsrc
The output datasource.
Definition: BufferOp.h:150
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
BufferOp()
Default constructor that can be called by subclasses.
Definition: BufferOp.cpp:41
std::string m_inDsetName
The input dataset name.
Definition: BufferOp.h:138
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
int m_newSRID
A new SRID if it&#39;s necessary to transform the data.
Definition: BufferOp.h:143