24 #include <QDataStream> 34 d =
new QgsFeaturePrivate(
id );
39 d =
new QgsFeaturePrivate(
id );
73 d->attributes.remove( field );
90 d->ownsGeometry =
false;
112 return d->attributes;
117 if ( attrs == d->attributes )
121 d->attributes = attrs;
136 QgsFeaturePrivate* old_d = d.
data();
137 bool ownedGeom = d->ownsGeometry;
141 d->ownsGeometry =
false;
145 if ( old_d != d.
data() )
147 old_d->ownsGeometry = ownedGeom;
149 else if ( ownedGeom )
155 d->ownsGeometry =
true;
190 return &( d->fields );
206 if ( d->valid == validity )
216 d->attributes.resize( fieldCount );
218 for (
int i = 0; i < fieldCount; ++i, ++ptr )
224 if ( idx < 0 || idx >= d->attributes.size() )
231 d->attributes[idx] = value;
244 if ( fieldIdx == -1 )
248 d->attributes[fieldIdx] = value;
255 if ( fieldIdx == -1 )
259 d->attributes[fieldIdx].clear();
265 if ( fieldIdx < 0 || fieldIdx >= d->attributes.count() )
268 return d->attributes.at( fieldIdx );
274 if ( fieldIdx == -1 )
277 return d->attributes.at( fieldIdx );
288 return d->fields.fieldNameIndex( fieldName );
320 in >>
id >> attr >> *geometry >> valid;
bool isValid() const
Returns the validity of this feature.
QgsAttributes attributes() const
Returns the feature's attributes.
virtual ~QgsFeature()
Destructor.
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length...
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString tr(const char *sourceText, const char *disambiguation, int n)
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature.
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object.
void deleteAttribute(int field)
Deletes an attribute and its value.
const QgsFields * fields() const
Returns the field map associated with the feature.
void setFeatureId(QgsFeatureId id)
Sets the feature ID for this feature.
QDataStream & operator<<(QDataStream &out, const QgsFeature &feature)
Writes the feature to stream out.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
QgsFeature & operator=(QgsFeature const &rhs)
Assignment operator.
Q_DECL_DEPRECATED void setFields(const QgsFields *fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
QgsFeature(QgsFeatureId id=QgsFeatureId())
Constructor for QgsFeature.
QgsFeatureId id() const
Get the feature ID for this feature.
QgsGeometry * geometry()
Get the geometry object associated with this feature.
void setValid(bool validity)
Sets the validity of the feature.
int fieldNameIndex(const QString &fieldName) const
Utility method to get attribute index from name.
Q_DECL_DEPRECATED void setGeometryAndOwnership(unsigned char *geom, int length)
Set this feature's geometry from WKB.
Q_DECL_DEPRECATED QgsGeometry * geometryAndOwnership()
Get the geometry object associated with this feature, and transfer ownership of the geometry to the c...
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.