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;
147 d->geometry =
QgsGeometry( std::move( geometry ) );
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 Q_FOREACH (
const QVariant &attr, key.
attributes() )
324 hash ^=
qHash( attr.toString() );
QgsFeatureId id() const
Gets the feature ID for this feature.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
bool isValid() const
Returns the validity of this feature.
int fieldNameIndex(const QString &fieldName) const
Utility method to get attribute index from name.
QgsFeature & operator=(const QgsFeature &rhs)
Assignment operator.
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...
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.
QgsFields fields() const
Returns the field map associated with the feature.
void deleteAttribute(int field)
Deletes an attribute and its value.
QgsAttributes attributes() const
Returns the feature's attributes.
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.
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).
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.
void setValid(bool validity)
Sets the validity of the feature.
void clearGeometry()
Removes any geometry associated with the feature.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool operator==(const QgsFeature &other) const
Compares two features.