LineToPolygonOp.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 LineToPolygonOp.cpp
22  */
23 
24 // Terralib
25 #include "../common/StringUtils.h"
26 
27 #include "../datatype/Enums.h"
28 #include "../datatype/Property.h"
29 
30 #include "../geometry/Enums.h"
31 #include "../geometry/GeometryProperty.h"
32 
33 #include "LineToPolygonOp.h"
34 
35 // STL
36 #include <vector>
37 
39  : m_oidSet(nullptr)
40 {
41 }
42 
44 {
45  if (!m_inDsrc.get())
46  return false;
47 
48  if (m_inDsetName.empty())
49  return false;
50 
51  if (m_outDset.empty() || !m_outDsrc.get())
52  return false;
53 
54  return true;
55 }
56 
58  std::string inDsetName,
59  std::unique_ptr<te::da::DataSetTypeConverter> converter,
60  const te::da::ObjectIdSet* oidSet)
61 {
62  m_inDsrc = inDsrc;
63  m_inDsetName = inDsetName;
64  m_converter = std::move(converter);
65  m_oidSet = oidSet;
66 }
67 
69 {
70  m_forceClose = forceClose;
71 }
72 
74 {
75  m_outDsrc = outDsrc;
76  m_outDset = dsname;
77 }
78 
79 std::unique_ptr<te::da::DataSetType> te::vp::LineToPolygonOp::buildOutDataSetType()
80 {
81  std::unique_ptr<te::da::DataSetType> outDsType(new te::da::DataSetType(m_outDset));
82 
83  std::string dSourceType = m_outDsrc->getType();
84 
85  std::vector<te::dt::Property*> vecProps = m_converter->getResult()->getProperties();
86 
87  std::vector<te::dt::Property*> inPk = m_converter->getResult()->getPrimaryKey()->getProperties();
88  std::string namePk = m_outDset;
89 
90  for (std::size_t p = 0; p < inPk.size(); ++p)
91  namePk += "_" + inPk[p]->getName();
92 
93  te::da::PrimaryKey* pk = new te::da::PrimaryKey(namePk + "_pk");
94 
95  if(dSourceType == "OGR")
96  {
97  for(std::size_t i = 0; i < vecProps.size(); ++i)
98  {
99  if(vecProps[i]->getType() != te::dt::GEOMETRY_TYPE && vecProps[i]->getName() != "FID")
100  {
101  outDsType->add(vecProps[i]->clone());
102  }
103  else
104  if(vecProps[i]->getType() == te::dt::GEOMETRY_TYPE)
105  {
106  te::gm::GeometryProperty* inGeom = static_cast<te::gm::GeometryProperty*>(vecProps[i]);
109  outGeom->setSRID(inGeom->getSRID());
110  outDsType->add(outGeom);
111  }
112  }
113  }
114  else
115  {
116  for(std::size_t i = 0; i < vecProps.size(); ++i)
117  {
118  if(vecProps[i]->getType() != te::dt::GEOMETRY_TYPE)
119  {
120  outDsType->add(vecProps[i]->clone());
121 
122  for (std::size_t j = 0; j < inPk.size(); ++j)
123  {
124  if (outDsType->getProperty(i)->getName() == inPk[j]->getName())
125  pk->add(outDsType->getProperty(i));
126  }
127  }
128  else
129  {
130  te::gm::GeometryProperty* inGeom = static_cast<te::gm::GeometryProperty*>(vecProps[i]);
133  outGeom->setSRID(inGeom->getSRID());
134  outDsType->add(outGeom);
135  }
136  }
137  outDsType->setPrimaryKey(pk);
138  }
139 
140 
141 
142  return outDsType;
143 }
144 
146 {
147  if (geom == te::gm::PolygonType)
149 
150  if (geom == te::gm::LineStringType)
152 
153  if (geom == te::gm::PointType)
154  return te::gm::MultiPointType;
155 
156  return geom;
157 }
158 
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
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the description of a dataset.
Definition: DataSetType.h:72
const te::da::ObjectIdSet * m_oidSet
te::da::DataSourcePtr m_outDsrc
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetTypeConverter > converter, const te::da::ObjectIdSet *oidSet=0)
void setParams(bool forceClose=false)
Line to polygon operation.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
std::unique_ptr< te::da::DataSetTypeConverter > m_converter
te::gm::Polygon * p
te::da::DataSourcePtr m_inDsrc
te::gm::GeomType getGeomResultType(te::gm::GeomType geom)
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
virtual bool paramsAreValid()
std::unique_ptr< te::da::DataSetType > buildOutDataSetType()
const std::string & getName() const
It returns the property name.
Definition: Property.h:127