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(0)
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::auto_ptr<te::da::DataSetTypeConverter> converter,
60  const te::da::ObjectIdSet* oidSet)
61 {
62  m_inDsrc = inDsrc;
63  m_inDsetName = inDsetName;
64  m_converter = converter;
65  m_oidSet = oidSet;
66 }
67 
69 {
70  m_outDsrc = outDsrc;
71  m_outDset = dsname;
72 }
73 
74 std::auto_ptr<te::da::DataSetType> te::vp::LineToPolygonOp::buildOutDataSetType()
75 {
76  std::auto_ptr<te::da::DataSetType> outDsType(new te::da::DataSetType(m_outDset));
77 
78  std::string dSourceType = m_outDsrc->getType();
79 
80  std::vector<te::dt::Property*> vecProps = m_converter->getResult()->getProperties();
81 
82  std::vector<te::dt::Property*> inPk = m_converter->getResult()->getPrimaryKey()->getProperties();
83  std::string namePk = m_outDset;
84 
85  for (std::size_t p = 0; p < inPk.size(); ++p)
86  namePk += "_" + inPk[p]->getName();
87 
88  te::da::PrimaryKey* pk = new te::da::PrimaryKey(namePk + "_pk");
89 
90  if(dSourceType == "OGR")
91  {
92  for(std::size_t i = 0; i < vecProps.size(); ++i)
93  {
94  if(vecProps[i]->getType() != te::dt::GEOMETRY_TYPE && vecProps[i]->getName() != "FID")
95  {
96  outDsType->add(vecProps[i]->clone());
97  }
98  else
99  if(vecProps[i]->getType() == te::dt::GEOMETRY_TYPE)
100  {
101  te::gm::GeometryProperty* inGeom = static_cast<te::gm::GeometryProperty*>(vecProps[i]);
104  outGeom->setSRID(inGeom->getSRID());
105  outDsType->add(outGeom);
106  }
107  }
108  }
109  else
110  {
111  for(std::size_t i = 0; i < vecProps.size(); ++i)
112  {
113  if(vecProps[i]->getType() != te::dt::GEOMETRY_TYPE)
114  {
115  outDsType->add(vecProps[i]->clone());
116 
117  for (std::size_t j = 0; j < inPk.size(); ++j)
118  {
119  if (outDsType->getProperty(i)->getName() == inPk[j]->getName())
120  pk->add(outDsType->getProperty(i));
121  }
122  }
123  else
124  {
125  te::gm::GeometryProperty* inGeom = static_cast<te::gm::GeometryProperty*>(vecProps[i]);
128  outGeom->setSRID(inGeom->getSRID());
129  outDsType->add(outGeom);
130  }
131  }
132  outDsType->setPrimaryKey(pk);
133  }
134 
135 
136 
137  return outDsType;
138 }
139 
141 {
142  if (geom == te::gm::PolygonType)
144 
145  if (geom == te::gm::LineStringType)
147 
148  if (geom == te::gm::PointType)
149  return te::gm::MultiPointType;
150 
151  return geom;
152 }
153 
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)
std::auto_ptr< te::da::DataSetType > buildOutDataSetType()
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::auto_ptr< te::da::DataSetTypeConverter > converter, const te::da::ObjectIdSet *oidSet=0)
virtual bool paramsAreValid()
const std::string & getName() const
It returns the property name.
Definition: Property.h:127