QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
26 #include <QDataStream>
41 d =
new QgsFeaturePrivate(
id );
46 d =
new QgsFeaturePrivate(
id );
67 if ( d->fid == other.d->fid
68 && d->valid == other.d->valid
69 && d->fields == other.d->fields
70 && d->attributes == other.d->attributes
71 && d->geometry.equals( other.d->geometry ) )
79 return !( *
this == other );
100 d->attributes.remove(
field );
126 return d->attributes;
131 if ( attrs == d->attributes )
135 d->attributes = attrs;
192 if ( d->valid == validity )
201 return !d->geometry.isNull();
207 d->attributes.resize( 0 );
210 d->attributes.resize( fieldCount );
215 if ( idx < 0 || idx >= d->attributes.size() )
222 d->attributes[idx] = value;
236 if ( fieldIdx == -1 )
240 d->attributes[fieldIdx] = value;
248 if ( fieldIdx == -1 )
252 d->attributes[fieldIdx].clear();
258 if ( fieldIdx < 0 || fieldIdx >= d->attributes.count() )
261 return d->attributes.at( fieldIdx );
267 if ( fieldIdx == -1 )
270 return d->attributes.at( fieldIdx );
281 return d->fields.lookupField( fieldName );
284 static size_t qgsQStringApproximateMemoryUsage(
const QString &str )
286 return sizeof( QString ) + str.size() *
sizeof( QChar );
289 static size_t qgsQVariantApproximateMemoryUsage(
const QVariant &v )
293 size_t s =
sizeof( QVariant ) +
sizeof(
long long ) +
sizeof( int );
294 if ( v.type() == QVariant::String )
296 s += qgsQStringApproximateMemoryUsage( v.toString() );
298 else if ( v.type() == QVariant::StringList )
300 for (
const QString &str : v.toStringList() )
301 s += qgsQStringApproximateMemoryUsage( str );
303 else if ( v.type() == QVariant::List )
305 for (
const QVariant &subV : v.toList() )
306 s += qgsQVariantApproximateMemoryUsage( subV );
313 size_t s =
sizeof( *this ) +
sizeof( *d );
316 for (
const QVariant &attr : qgis::as_const( d->attributes ) )
318 s += qgsQVariantApproximateMemoryUsage( attr );
322 s +=
sizeof( QAtomicInt ) +
sizeof(
void * );
325 s += d->geometry.wkbSize();
328 s +=
sizeof( QgsFieldsPrivate );
330 s += d->fields.size() * (
sizeof(
QgsField ) +
sizeof( QgsFieldPrivate ) );
332 return static_cast<int>( s );
365 in >>
id >> attr >> geometry >> valid;
376 const auto constAttributes = key.
attributes();
377 for (
const QVariant &attr : constAttributes )
379 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)
Container of fields for a vector layer.
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.
int approximateMemoryUsage() const
Returns the approximate RAM usage of the feature, in bytes.
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.
A geometry is the spatial representation of a feature.
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.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void deleteAttribute(int field)
Deletes an attribute and its value.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsFeature(QgsFeatureId id=FID_NULL)
Constructor for QgsFeature.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Encapsulate a field in an attribute table or data source.