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