12
12
* (at your option) any later version. *
14
14
***************************************************************************/
15
/* $Id: qgsfeature.h 6274 2006-12-18 06:06:48Z telwertowski $ */
17
17
#ifndef QGSFEATURE_H
18
18
#define QGSFEATURE_H
27
#include "qgsfeatureattribute.h"
28
#include "qgsgeometry.h"
29
//#include "qgspoint.h"
33
/** \class QgsFeature - Feature attribute class.
34
* Encapsulates a single feature including id and field/value.
35
*@author Gary E.Sherman
29
// key = field index, value = field value
30
typedef QMap<int, QVariant> QgsAttributeMap;
32
// key = feature id, value = changed attributes
33
typedef QMap<int, QgsAttributeMap> QgsChangedAttributesMap;
35
// key = feature id, value = changed geometry
36
typedef QMap<int, QgsGeometry> QgsGeometryMap;
38
// key = field index, value = field name
39
typedef QMap<int, QString> QgsFieldNameMap;
41
typedef QList<QgsFeature> QgsFeatureList;
44
* The feature class encapsulates a single feature including its id,
45
* geometry and a list of field/values attributes.
47
* @author Gary E.Sherman
49
class CORE_EXPORT QgsFeature
44
QgsFeature(int id, QString const & typeName = "" );
46
/** create a copy of this feature in its uncommitted state.
47
To do this, you also pass in a reference to the feature's
48
layer's uncommitted attribute and geometry changes.
49
The resulting feature will have those changes applied.
51
This is useful in the cut/copy routine, where you'd
52
want a copy of the "current" feature, not the on-disk feature.
54
QgsFeature( QgsFeature const & rhs,
55
std::map<int,std::map<QString,QString> > & changedAttributes,
56
std::map<int, QgsGeometry> & changedGeometries );
53
QgsFeature( int id = 0, QString typeName = "" );
58
55
/** copy ctor needed due to internal pointer */
59
56
QgsFeature( QgsFeature const & rhs );
69
66
* Get the feature id for this feature
70
67
* @return Feature id
72
int featureId() const;
75
72
* Set the feature id for this feature
76
73
* @param id Feature id
78
void setFeatureId(int id);
75
void setFeatureId( int id );
81
78
/** returns the feature's type name
83
QString const & typeName() const;
80
QString typeName() const;
86
83
/** sets the feature's type name
88
void typeName( QString const & typeName );
85
void setTypeName( QString typeName );
91
88
* Get the attributes for this feature.
92
89
* @return A std::map containing the field name/value mapping
94
const std::vector<QgsFeatureAttribute>& attributeMap();
91
const QgsAttributeMap& attributeMap() const;
93
/**Sets all the attributes in one go*/
94
void setAttributeMap( const QgsAttributeMap& attributeMap );
97
97
* Add an attribute to the map
99
void addAttribute(QString const & field, QString const & value = "", bool numeric = false);
99
void addAttribute( int field, QVariant attr );
101
101
/**Deletes an attribute and its value*/
102
void deleteAttribute(const QString& name);
102
void deleteAttribute( int field );
104
104
/**Changes an existing attribute value
105
@param name attribute name
106
@param newval new value*/
107
void changeAttributeValue(const QString& name, const QString& newval);
109
/**Changes an existing attribute name. The value is unchanged.
110
@param name attribute name
111
@param newname new name*/
112
void changeAttributeName(const QString& name, const QString& newname);
115
* Get the fields for this feature
116
* @return A std::map containing field position (index) and field name
118
const std::map<int, QString>& fields();
105
@param field index of the field
106
@param attr attribute name and value to be set */
107
void changeAttribute( int field, QVariant attr );
121
110
* Return the validity of this feature. This is normally set by
125
114
bool isValid() const;
128
117
* Set the validity of the feature.
130
void setValid(bool validity);
119
void setValid( bool validity );
133
122
* Return the dirty state of this feature.
134
123
* Dirty is set if (e.g.) the feature's geometry has been modified in-memory.
136
125
bool isDirty() const;
139
128
* Reset the dirtiness of the feature. (i.e. make clean)
140
129
* You would normally do this after it's saved to permanent storage (e.g. disk, an ACID-compliant database)
145
134
* Get the geometry object associated with this feature
147
QgsGeometry * geometry();
136
QgsGeometry *geometry();
150
139
* Get the geometry object associated with this feature
151
140
* The caller assumes responsibility for the QgsGeometry*'s destruction.
153
QgsGeometry * geometryAndOwnership();
155
/** gets the most recent in-memory version of the geometry (deprecated function in favour of geometry()) */
156
unsigned char * getGeometry() const;
158
// /** gets only the committed version of the geometry */
159
// unsigned char * getCommittedGeometry() const;
161
// /** gets the most recent in-memory version of the geometry only
162
// if it has been modified since committed (isDirty() == TRUE) */
163
// unsigned char * getModifiedGeometry() const;
165
size_t getGeometrySize() const;
167
/* size_t getCommittedGeometrySize() const;
169
size_t getModifiedGeometrySize() const;*/
171
QString const& wellKnownText() const;
142
QgsGeometry *geometryAndOwnership();
173
144
/** Set this feature's geometry from another QgsGeometry object (deep copy)
175
void setGeometry(QgsGeometry& geom);
146
void setGeometry( const QgsGeometry& geom );
148
/** Set this feature's geometry (takes geometry ownership)
150
void setGeometry( QgsGeometry* geom );
178
153
* Set this feature's geometry from WKB
180
155
* This feature assumes responsibility for destroying geom.
182
void setGeometryAndOwnership(unsigned char * geom, size_t length);
184
/** Set bulk-modified WKB geometry
185
\note this function assumes the Geometry is not committed.
187
/* void setModifiedGeometry(unsigned char * geom, size_t length);*/
189
/** Insert a new vertex before the given vertex number,
190
* ring and item (first number is index 0)
191
* Not meaningful for Point geometries
193
// bool insertVertexBefore(double x, double y, int beforeVertex = 0, int atRing = 0, int atItem = 0);
195
/** Moves the vertex at the given position number,
196
* ring and item (first number is index 0)
197
* to the given coordinates
199
/* bool moveVertexAt(double x, double y, int atVertex = 0, int atRing = 0, int atItem = 0);*/
202
* Modifies x and y to indicate the location of
203
* the vertex at the given position number,
204
* ring and item (first number is index 0)
205
* to the given coordinates
207
/* bool vertexAt(double &x, double &y, int atVertex = 0, int atRing = 0, int atItem = 0) const;*/
209
// /**Test for intersection with a rectangle (uses GEOS)*/
210
// bool intersects(QgsRect* r) const;
212
/**Returns the Vertex closest to a given point*/
213
// QgsPoint closestVertex(const QgsPoint& point) const;
215
/** Returns the line segment closest to the given point in beforeVertex, atRing and atItem
216
Returns the SQUARE of the closest distance in minDist.
217
Returns the closest point on the line segment to the given point
221
TODO: const correctness
223
// QgsPoint closestSegment(QgsPoint& point,
224
// QgsPoint& segStart, QgsPoint& segStop,
225
// double& minSqrDist);
227
// QgsPoint QgsFeature::closestSegmentWithContext(QgsPoint& point,
228
// int& beforeVertex, int& atRing, int& atItem,
229
// double& minSqrDist);
232
/**Returns the bounding box of this feature*/
233
QgsRect boundingBox() const;
235
/** Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted.
236
@note This function is deprecated - use geometry()->geosGeometry() instead.
238
GEOS_GEOM::Geometry* geosGeometry() const;
157
void setGeometryAndOwnership( unsigned char * geom, size_t length );
245
//! std::map containing field name/value pairs
246
std::vector<QgsFeatureAttribute> attributes;
248
//! std::map containing the field index and name
249
std::map<int, QString> fieldNames;
164
/** map of attributes accessed by field index */
165
QgsAttributeMap mAttributes;
251
167
/** pointer to geometry in binary WKB format
253
169
This is usually set by a call to OGRGeometry::exportToWkb()
255
QgsGeometry* mGeometry;
171
QgsGeometry *mGeometry;
257
173
/** Indicator if the mGeometry is owned by this QgsFeature.
258
174
If so, this QgsFeature takes responsibility for the mGeometry's destruction.
262
// /** pointer to modified (dirty / uncommitted) geometry in binary WKB format
263
// This is only valid if isDirty().
265
// unsigned char * modifiedGeometry;
267
// /** size of geometry */
268
// size_t geometrySize;
270
// /** size of modified geometry */
271
// size_t modifiedGeometrySize;
273
178
//! Flag to indicate if this feature is valid
179
// TODO: still applies? [MD]
276
182
//! Flag to indicate if this feature is dirty (e.g. geometry has been modified in-memory)
183
// TODO: still applies? [MD]
279
186
/// feature type name
280
187
QString mTypeName;
282
// /**WKT representation of the geometry*/
283
// mutable QString mWKT;
285
// /**Exports the current WKB to mWKT
286
// @return true in case of success and false else*/
287
// bool exportToWKT(unsigned char * geom) const;
288
// bool exportToWKT() const;
290
// /** Squared distance from point to the given line segment
291
// * TODO: Perhaps move this to QgsPoint
293
// double distanceSquaredPointToSegment(QgsPoint& point,
294
// double *x1, double *y1,
295
// double *x2, double *y2,
296
// QgsPoint& minDistPoint);
298
190
}; // class QgsFeature