PolygonToLineOp.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 PolygonToLineOp.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 "PolygonToLineOp.h"
34 
35 // STL
36 #include <vector>
37 
39  : m_oidSet(0)
40 {
41 }
42 
44  std::string inDsetName,
45  std::auto_ptr<te::da::DataSetTypeConverter> converter,
46  const te::da::ObjectIdSet* oidSet)
47 {
48  m_inDsrc = inDsrc;
49  m_inDsetName = inDsetName;
50  m_converter = converter;
51  m_oidSet = oidSet;
52 }
53 
55 {
56  m_outDsrc = outDsrc;
57  m_outDset = dsname;
58 }
59 
60 std::auto_ptr<te::da::DataSetType> te::vp::PolygonToLineOp::buildOutDataSetType()
61 {
62 
63  std::auto_ptr<te::da::DataSetType> outDsType(new te::da::DataSetType(m_outDset));
64 
65  std::string dSourceType = m_outDsrc->getType();
66 
67  std::vector<te::dt::Property*> vecProps = m_converter->getResult()->getProperties();
68 
69  std::vector<te::dt::Property*> inPk = m_converter->getResult()->getPrimaryKey()->getProperties();
70  std::string namePk = m_outDset;
71 
72  for (std::size_t p = 0; p < inPk.size(); ++p)
73  namePk += "_" + inPk[p]->getName();
74 
75  te::da::PrimaryKey* pk = new te::da::PrimaryKey(namePk + "_pk");
76 
77  if(dSourceType == "OGR")
78  {
79  for(std::size_t i = 0; i < vecProps.size(); ++i)
80  {
81  if(vecProps[i]->getType() != te::dt::GEOMETRY_TYPE && vecProps[i]->getName() != "FID")
82  {
83  outDsType->add(vecProps[i]->clone());
84  }
85  else
86  if(vecProps[i]->getType() == te::dt::GEOMETRY_TYPE)
87  {
88  te::gm::GeometryProperty* inGeom = static_cast<te::gm::GeometryProperty*>(vecProps[i]);
91  outGeom->setSRID(inGeom->getSRID());
92  outDsType->add(outGeom);
93  }
94  }
95  }
96  else
97  {
98  for(std::size_t i = 0; i < vecProps.size(); ++i)
99  {
100  if(vecProps[i]->getType() != te::dt::GEOMETRY_TYPE)
101  {
102  outDsType->add(vecProps[i]->clone());
103 
104  for (std::size_t j = 0; j < inPk.size(); ++j)
105  {
106  if (outDsType->getProperty(i)->getName() == inPk[j]->getName())
107  pk->add(outDsType->getProperty(i));
108  }
109  }
110  else
111  {
112  te::gm::GeometryProperty* inGeom = static_cast<te::gm::GeometryProperty*>(vecProps[i]);
115  outGeom->setSRID(inGeom->getSRID());
116  outDsType->add(outGeom);
117  }
118  }
119  }
120 
121  outDsType->setPrimaryKey(pk);
122 
123  return outDsType;
124 }
125 
127 {
128  if (geom == te::gm::PolygonType)
130 
131  if (geom == te::gm::LineStringType)
133 
134  if (geom == te::gm::PointType)
135  return te::gm::MultiPointType;
136 
137  return geom;
138 }
139 
141 {
142  if (!m_inDsrc.get())
143  return false;
144 
145  if (m_inDsetName.empty())
146  return false;
147 
148  if (m_outDset.empty() || !m_outDsrc.get())
149  return false;
150 
151  return true;
152 }
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.
Definition: Enums.h:41
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
Definition: DataSource.h:1435
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)
std::auto_ptr< te::da::DataSetType > buildOutDataSetType()
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
te::gm::GeomType getGeomResultType(te::gm::GeomType geom)
Polygon to line operation.
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
const std::string & getName() const
It returns the property name.
Definition: Property.h:127