Quantum GIS API Documentation
1.7.5-Wroclaw
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
core
qgsfeature.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsfeature.cpp - Spatial Feature Implementation
3
--------------------------------------
4
Date : 09-Sep-2003
5
Copyright : (C) 2003 by Gary E.Sherman
6
email : sherman at mrcc.com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
/* $Id$ */
16
17
#include "
qgsfeature.h
"
18
#include "
qgsgeometry.h
"
19
#include "
qgsrectangle.h
"
20
25
QgsFeature::QgsFeature
(
int
id
, QString typeName )
26
: mFid( id )
27
, mGeometry( 0 )
28
, mOwnsGeometry( 0 )
29
, mValid( false )
30
, mDirty( 0 )
31
, mTypeName( typeName )
32
{
33
// NOOP
34
}
35
36
QgsFeature::QgsFeature
(
QgsFeature
const
& rhs )
37
: mFid( rhs.mFid )
38
, mAttributes( rhs.mAttributes )
39
, mGeometry( 0 )
40
, mOwnsGeometry( false )
41
, mValid( rhs.mValid )
42
, mDirty( rhs.mDirty )
43
, mTypeName( rhs.mTypeName )
44
{
45
46
// copy embedded geometry
47
if
( rhs.
mGeometry
)
48
{
49
setGeometry
( *rhs.
mGeometry
);
50
}
51
}
52
53
54
QgsFeature
&
QgsFeature::operator=
(
QgsFeature
const
& rhs )
55
{
56
if
( &rhs ==
this
)
57
return
*
this
;
58
59
mFid
= rhs.
mFid
;
60
mDirty
= rhs.
mDirty
;
61
mAttributes
= rhs.
mAttributes
;
62
mValid
= rhs.
mValid
;
63
mTypeName
= rhs.
mTypeName
;
64
65
// make sure to delete the old geometry (if exists)
66
if
(
mGeometry
&&
mOwnsGeometry
)
67
delete
mGeometry
;
68
69
mGeometry
= 0;
70
mOwnsGeometry
=
false
;
71
72
if
( rhs.
mGeometry
)
73
setGeometry
( *rhs.
mGeometry
);
74
75
return
*
this
;
76
}
// QgsFeature::operator=( QgsFeature const & rhs )
77
78
79
81
QgsFeature::~QgsFeature
()
82
{
83
// Destruct the attached geometry only if we still own it.
84
if
(
mOwnsGeometry
&&
mGeometry
)
85
delete
mGeometry
;
86
}
87
92
int
QgsFeature::id
()
const
93
{
94
return
mFid
;
95
}
96
101
const
QgsAttributeMap
&
QgsFeature::attributeMap
()
const
102
{
103
return
mAttributes
;
104
}
105
107
void
QgsFeature::setAttributeMap
(
const
QgsAttributeMap
& attributes )
108
{
109
mAttributes
= attributes;
110
}
111
113
void
QgsFeature::clearAttributeMap
()
114
{
115
mAttributes
.clear();
116
}
117
121
void
QgsFeature::addAttribute
(
int
field, QVariant attr )
122
{
123
mAttributes
.insert( field, attr );
124
}
125
127
void
QgsFeature::deleteAttribute
(
int
field )
128
{
129
mAttributes
.remove( field );
130
}
131
132
133
void
QgsFeature::changeAttribute
(
int
field, QVariant attr )
134
{
135
mAttributes
[field] = attr;
136
}
137
138
QgsGeometry
*
QgsFeature::geometry
()
139
{
140
return
mGeometry
;
141
}
142
143
QgsGeometry
*
QgsFeature::geometryAndOwnership
()
144
{
145
mOwnsGeometry
=
false
;
146
147
return
mGeometry
;
148
}
149
150
151
154
void
QgsFeature::setFeatureId
(
int
id
)
155
{
156
mFid
=
id
;
157
}
158
159
160
QString
QgsFeature::typeName
()
const
161
{
162
return
mTypeName
;
163
}
// QgsFeature::typeName
164
165
166
169
void
QgsFeature::setTypeName
( QString typeName )
170
{
171
mTypeName
=
typeName
;
172
}
// QgsFeature::typeName
173
174
175
void
QgsFeature::setGeometry
(
const
QgsGeometry
& geom )
176
{
177
setGeometry
(
new
QgsGeometry
( geom ) );
178
}
179
180
void
QgsFeature::setGeometry
(
QgsGeometry
* geom )
181
{
182
// Destruct the attached geometry only if we still own it, before assigning new one.
183
if
(
mOwnsGeometry
&&
mGeometry
)
184
{
185
delete
mGeometry
;
186
mGeometry
= 0;
187
}
188
189
mGeometry
= geom;
190
mOwnsGeometry
=
true
;
191
}
192
195
void
QgsFeature::setGeometryAndOwnership
(
unsigned
char
*geom,
size_t
length )
196
{
197
QgsGeometry
*g =
new
QgsGeometry
();
198
g->
fromWkb
( geom, length );
199
setGeometry
( g );
200
}
201
202
203
bool
QgsFeature::isValid
()
const
204
{
205
return
mValid
;
206
}
207
208
void
QgsFeature::setValid
(
bool
validity )
209
{
210
mValid
= validity;
211
}
212
213
bool
QgsFeature::isDirty
()
const
214
{
215
return
mDirty
;
216
}
217
218
void
QgsFeature::clean
()
219
{
220
mDirty
=
false
;
221
}
Generated on Wed Jun 13 2012 13:54:10 for Quantum GIS API Documentation by
1.8.1