All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../datatype/Enums.h"
26 #include "../datatype/Property.h"
27 
28 #include "../geometry/Enums.h"
29 #include "../geometry/GeometryProperty.h"
30 
31 #include "PolygonToLineOp.h"
32 
33 // STL
34 #include <vector>
35 
37  m_outDset("")
38 {
39 }
40 
42  std::string inDsetName,
43  const te::da::ObjectIdSet* oidSet)
44 {
45  m_inDsrc = inDsrc;
46  m_inDsetName = inDsetName;
47  m_oidSet = oidSet;
48 }
49 
51 {
52  m_outDsrc = outDsrc;
53  m_outDset = dsname;
54 }
55 
56 std::auto_ptr<te::da::DataSetType> te::vp::PolygonToLineOp::buildOutDataSetType()
57 {
58  std::auto_ptr<te::da::DataSetType> inDsType = m_inDsrc->getDataSetType(m_inDsetName);
59  std::auto_ptr<te::da::DataSetType> outDsType(new te::da::DataSetType(m_outDset));
60 
61  std::string dSourceType = m_outDsrc->getType();
62 
63  std::vector<te::dt::Property*> vecProps = inDsType->getProperties();
64 
65  std::vector<te::dt::Property*> inPk = inDsType->getPrimaryKey()->getProperties();
66  std::string namePk = m_outDset;
67 
68  for (std::size_t p = 0; p < inPk.size(); ++p)
69  namePk += "_" + inPk[p]->getName();
70 
71  te::da::PrimaryKey* pk = new te::da::PrimaryKey(namePk + "_pk");
72 
73  if(dSourceType == "OGR")
74  {
75  for(std::size_t i = 0; i < vecProps.size(); ++i)
76  {
77  if(vecProps[i]->getType() != te::dt::GEOMETRY_TYPE && vecProps[i]->getName() != "FID")
78  {
79  outDsType->add(vecProps[i]->clone());
80  }
81  else
82  if(vecProps[i]->getType() == te::dt::GEOMETRY_TYPE)
83  {
84  te::gm::GeometryProperty* inGeom = static_cast<te::gm::GeometryProperty*>(vecProps[i]);
87  outGeom->setSRID(inGeom->getSRID());
88  outDsType->add(outGeom);
89  }
90  }
91  }
92  else
93  {
94  for(std::size_t i = 0; i < vecProps.size(); ++i)
95  {
96  if(vecProps[i]->getType() != te::dt::GEOMETRY_TYPE)
97  {
98  outDsType->add(vecProps[i]->clone());
99 
100  for (std::size_t j = 0; j < inPk.size(); ++j)
101  {
102  if (outDsType->getProperty(i)->getName() == inPk[j]->getName())
103  pk->add(outDsType->getProperty(i));
104  }
105  }
106  else
107  {
108  te::gm::GeometryProperty* inGeom = static_cast<te::gm::GeometryProperty*>(vecProps[i]);
111  outGeom->setSRID(inGeom->getSRID());
112  outDsType->add(outGeom);
113  }
114  }
115  }
116 
117  outDsType->setPrimaryKey(pk);
118 
119  return outDsType;
120 }
121 
123 {
124  if (geom == te::gm::PolygonType)
126 
127  if (geom == te::gm::LineStringType)
129 
130  if (geom == te::gm::PointType)
131  return te::gm::MultiPointType;
132 
133  return geom;
134 }
135 
137 {
138  if (!m_inDsrc.get())
139  return false;
140 
141  if (m_inDsetName.empty())
142  return false;
143 
144  if (m_outDset.empty() || !m_outDsrc.get())
145  return false;
146 
147  return true;
148 }
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
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
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, const te::da::ObjectIdSet *oidSet=0)
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