All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Feature.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 terralib/edit/Feature.h
22 
23  \brief This class represents a geographic feature.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../dataaccess/dataset/ObjectId.h"
29 #include "../datatype/AbstractData.h"
30 #include "../geometry/Geometry.h"
31 #include "Feature.h"
32 #include "Utils.h"
33 
34 // STL
35 #include <cassert>
36 
38  : m_geom(0)
39 {
40  m_id = GenerateId();
41 }
42 
44  : m_id(id),
45  m_geom(0)
46 {
47  assert(m_id);
48 }
49 
51  : m_id(id),
52  m_geom(geom)
53 {
54  assert(m_id);
55  assert(m_geom);
56 }
57 
59 {
60  delete m_id;
61  delete m_geom;
63 }
64 
66 {
67  setId(id);
68  setGeometry(geom);
69 }
70 
72 {
73  assert(id);
74 
75  delete m_id;
76  m_id = id;
77 }
78 
80 {
81  assert(geom);
82 
83  delete m_geom;
84  m_geom = geom;
85 }
86 
87 void te::edit::Feature::setData(const std::map<std::size_t, te::dt::AbstractData*>& data)
88 {
90  m_data = data;
91 }
92 
94 {
95  return m_id;
96 }
97 
99 {
100  return m_geom;
101 }
102 
103 const std::map<std::size_t, te::dt::AbstractData*>& te::edit::Feature::getData() const
104 {
105  return m_data;
106 }
107 
109 {
110  assert(m_id);
111  assert(id);
112 
113  return m_id->getValueAsString() == id->getValueAsString();
114 }
115 
117 {
118  assert(m_id);
119 
120  // The clone
121  Feature* f = new Feature(m_id->clone());
122 
123  // Clone geometry
124  if(m_geom)
125  f->setGeometry(dynamic_cast<te::gm::Geometry*>(m_geom->clone()));
126 
127  // Clone data
128  std::map<std::size_t, te::dt::AbstractData*> data;
129  for(std::map<std::size_t, te::dt::AbstractData*>::const_iterator it = m_data.begin(); it != m_data.end(); ++it)
130  {
131  assert(it->second);
132  data[it->first] = it->second->clone();
133  }
134 
135  f->setData(data);
136 
137  return f;
138 }
void setId(te::da::ObjectId *id)
Definition: Feature.cpp:71
TEEDITEXPORT te::da::ObjectId * GenerateId()
Definition: Utils.cpp:361
te::gm::Geometry * m_geom
Definition: Feature.h:88
te::da::ObjectId * getId() const
Definition: Feature.cpp:93
Feature * clone() const
Definition: Feature.cpp:116
te::gm::Geometry * getGeometry() const
Definition: Feature.cpp:98
void set(te::da::ObjectId *id, te::gm::Geometry *geom)
Definition: Feature.cpp:65
This class represents a geographic feature.
This class represents an unique id for a data set element.
Definition: ObjectId.h:47
bool isEquals(te::da::ObjectId *id)
Definition: Feature.cpp:108
void setData(const std::map< std::size_t, te::dt::AbstractData * > &data)
Definition: Feature.cpp:87
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
Utility functions for TerraLib Edit module.
te::da::ObjectId * m_id
Definition: Feature.h:87
void setGeometry(te::gm::Geometry *geom)
Definition: Feature.cpp:79
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
const std::map< std::size_t, te::dt::AbstractData * > & getData() const
Definition: Feature.cpp:103