QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
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;
190 if ( d->valid == validity )
199 return !d->geometry.isNull();
205 d->attributes.resize( 0 );
208 d->attributes.resize( fieldCount );
213 if ( idx < 0 || idx >= d->attributes.size() )
220 d->attributes[idx] = value;
234 if ( fieldIdx == -1 )
238 d->attributes[fieldIdx] = value;
246 if ( fieldIdx == -1 )
250 d->attributes[fieldIdx].clear();
256 if ( fieldIdx < 0 || fieldIdx >= d->attributes.count() )
259 return d->attributes.at( fieldIdx );
265 if ( fieldIdx == -1 )
268 return d->attributes.at( fieldIdx );
279 return d->fields.lookupField( fieldName );
311 in >>
id >> attr >> geometry >> valid;
322 const auto constAttributes = key.
attributes();
323 for (
const QVariant &attr : constAttributes )
325 hash ^=
qHash( attr.toString() );
void setId(QgsFeatureId id)
Sets the feature ID for this feature.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
uint qHash(const QgsFeature &key, uint seed)
QgsFeature(QgsFeatureId id=QgsFeatureId())
Constructor for QgsFeature.
void setValid(bool validity)
Sets the validity of the feature.
bool operator==(const QgsFeature &other) const
Compares two features.
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.
bool isValid() const
Returns the validity of this feature.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.
QgsFeature & operator=(const QgsFeature &rhs)
Assignment operator.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QDataStream & operator<<(QDataStream &out, const QgsFeature &feature)
Writes the feature to stream out. QGIS version compatibility is not guaranteed.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
bool operator!=(const QgsFeature &other) const
Compares two features.
void deleteAttribute(int field)
Deletes an attribute and its value.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.