24 #include <QDataStream> 39 d =
new QgsFeaturePrivate(
id );
44 d =
new QgsFeaturePrivate(
id );
65 if ( d->fid == other.d->fid
66 && d->valid == other.d->valid
67 && d->fields == other.d->fields
68 && d->attributes == other.d->attributes
69 && d->geometry.equals( other.d->geometry ) )
77 return !( *
this == other );
98 d->attributes.remove( field );
124 return d->attributes;
129 if ( attrs == d->attributes )
133 d->attributes = attrs;
183 if ( d->valid == validity )
192 return !d->geometry.isNull();
198 d->attributes.resize( fieldCount );
199 QVariant *ptr = d->attributes.data();
200 for (
int i = 0; i < fieldCount; ++i, ++ptr )
206 if ( idx < 0 || idx >= d->attributes.size() )
213 d->attributes[idx] = value;
227 if ( fieldIdx == -1 )
231 d->attributes[fieldIdx] = value;
239 if ( fieldIdx == -1 )
243 d->attributes[fieldIdx].clear();
249 if ( fieldIdx < 0 || fieldIdx >= d->attributes.count() )
252 return d->attributes.at( fieldIdx );
258 if ( fieldIdx == -1 )
261 return d->attributes.at( fieldIdx );
272 return d->fields.lookupField( fieldName );
304 in >>
id >> attr >> geometry >> valid;
315 Q_FOREACH (
const QVariant &attr, key.
attributes() )
317 hash ^=
qHash( attr.toString() );
bool isValid() const
Returns the validity of this feature.
QgsAttributes attributes() const
Returns the feature's attributes.
QgsFields fields() const
Returns the field map associated with the feature.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
QgsFeature & operator=(const QgsFeature &rhs)
Assignment operator.
bool operator!=(const QgsFeature &other) const
Compares two features.
uint qHash(const QgsFeature &key, uint seed)
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.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning)
add a message to the instance (and create it if necessary)
void deleteAttribute(int field)
Deletes an attribute and its value.
QDataStream & operator<<(QDataStream &out, const QgsFeature &feature)
Writes the feature to stream out. QGIS version compatibility is not guaranteed.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
void seed(uint32_t value)
void setId(QgsFeatureId id)
Sets the feature ID for this feature.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
QgsFeature(QgsFeatureId id=QgsFeatureId())
Constructor for QgsFeature.
bool operator==(const QgsFeature &other) const
Compares two features.
QgsFeatureId id() const
Get the feature ID for this feature.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
void setValid(bool validity)
Sets the validity of the feature.
int fieldNameIndex(const QString &fieldName) const
Utility method to get attribute index from name.
void clearGeometry()
Removes any geometry associated with the feature.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.