1
/***************************************************************************
2
qgsfeature.h - Spatial Feature Class
3
--------------------------------------
5
Copyright : (C) 2003 by Gary E.Sherman
6
email : sherman at mrcc.com
7
***************************************************************************
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. *
14
***************************************************************************/
15
/* $Id: qgsfeature.h,v 1.14.2.1 2005/10/10 20:05:09 gsherman Exp $ */
25
#include "qgsfeatureattribute.h"
31
/** \class QgsFeature - Feature attribute class.
32
* Encapsulates a single feature including id and field/value.
33
*@author Gary E.Sherman
42
QgsFeature(int id, QString const & typeName = "" );
45
/** copy ctor needed due to internal pointer */
46
QgsFeature( QgsFeature const & );
48
/** assignment operator needed due to internal pointer */
49
QgsFeature & operator=( QgsFeature const & rhs );
55
* Get the feature id for this feature
58
int featureId() const;
61
* Set the feature id for this feature
62
* @param id Feature id
64
void setFeatureId(int id);
67
/** returns the feature's type name
69
QString const & typeName() const;
72
/** sets the feature's type name
74
void typeName( QString const & typeName );
77
* Get the attributes for this feature.
78
* @return A std::map containing the field name/value mapping
80
const std::vector<QgsFeatureAttribute>& attributeMap();
83
* Add an attribute to the map
85
void addAttribute(QString const & field, QString const & value = "");
87
/**Deletes an attribute and its value*/
88
void deleteAttribute(const QString& name);
90
/**Changes an existing attribute value
91
@param name attribute name
92
@param newval new value*/
93
void changeAttributeValue(const QString& name, const QString& newval);
96
* Get the fields for this feature
97
* @return A std::map containing field position (index) and field name
99
const std::map<int, QString>& fields();
102
* Return the validity of this feature. This is normally set by
103
* the provider to indicate some problem that makes the feature
104
* invalid or to indicate a null feature.
106
bool isValid() const;
109
* Validate the feature
111
bool validate() const;
114
* Set the validity of the feature.
116
void setValid(bool validity);
118
unsigned char * getGeometry() const;
120
size_t getGeometrySize() const;
122
QString const& wellKnownText() const;
124
/** Set WKB geometry*/
125
void setGeometry(unsigned char * geometry, size_t length);
127
/**Shows a popup dialog to change attribute values
128
@return true if dialog is accepted, false if rejected*/
129
bool attributeDialog();
131
/**Test for intersection with a rectangle (uses GEOS)*/
132
bool intersects(QgsRect* r) const;
134
/**Returns the Vertex closest to a given point*/
135
QgsPoint closestVertex(const QgsPoint& point) const;
137
/**Returns the bounding box of this feature*/
138
QgsRect boundingBox() const;
140
/**Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted*/
141
geos::Geometry* geosGeometry() const;
148
//! std::map containing field name/value pairs
149
std::vector<QgsFeatureAttribute> attributes;
151
//! std::map containing the field index and name
152
std::map<int, QString> fieldNames;
154
/** pointer to geometry in binary WKB format
156
This is usually set by a call to OGRGeometry::exportToWkb()
158
unsigned char * geometry;
160
/** size of geometry */
163
//! Flag to indicate if this feature is valid
166
/// feature type name
169
/**WKT representation of the geometry*/
170
mutable QString mWKT;
172
/**Exports the current WKB to mWKT
173
@return true in case of success and false else*/
174
bool exportToWKT() const;
176
}; // class QgsFeature