QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
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->symbol == other.d->symbol ) )
75 if ( d->geometry.isNull() && other.d->geometry.isNull() )
77 else if ( d->geometry.isNull() || other.d->geometry.isNull() )
79 else if ( !d->geometry.equals( other.d->geometry ) )
87 return !( *
this == other );
108 d->attributes.remove(
field );
134 return d->attributes;
140 const int fieldSize = d->fields.size();
141 const int attributeSize = d->attributes.size();
142 if ( fieldSize != attributeSize )
144 QgsDebugMsg( QStringLiteral(
"Attribute size (%1) does not match number of fields (%2)" ).arg( attributeSize ).arg( fieldSize ) );
145 return QVariantMap();
148 for (
int i = 0; i < attributeSize; ++i )
150 res[d->fields.at( i ).name()] = d->attributes.at( i );
157 return d->attributes.size();
162 if ( attrs == d->attributes )
166 d->attributes = attrs;
223 if ( d->valid == validity )
232 return !d->geometry.isNull();
238 d->attributes.resize( 0 );
241 d->attributes.resize( fieldCount );
246 if ( fieldCount == d->attributes.size() )
250 d->attributes.resize( fieldCount );
259 d->attributes.resize( d->attributes.size() + count );
264 if ( idx < 0 || idx >= d->attributes.size() )
266 QgsMessageLog::logMessage( QObject::tr(
"Attribute index %1 out of bounds [0;%2]" ).arg( idx ).arg( d->attributes.size() ), QString(), Qgis::MessageLevel::Warning );
271 d->attributes[idx] = value;
285 if ( fieldIdx == -1 )
289 d->attributes[fieldIdx] = value;
297 if ( fieldIdx == -1 )
301 d->attributes[fieldIdx].clear();
307 if ( fieldIdx < 0 || fieldIdx >= d->attributes.count() )
310 return d->attributes.at( fieldIdx );
315 return d->symbol.get();
320 if ( symbol == d->symbol.get() )
324 d->symbol.reset( symbol );
330 if ( fieldIdx == -1 )
333 return d->attributes.at( fieldIdx );
344 return d->fields.lookupField( fieldName );
347 static size_t qgsQStringApproximateMemoryUsage(
const QString &
str )
349 return sizeof( QString ) +
str.size() *
sizeof( QChar );
352 static size_t qgsQVariantApproximateMemoryUsage(
const QVariant &v )
356 size_t s =
sizeof( QVariant ) +
sizeof(
long long ) +
sizeof( int );
357 if ( v.type() == QVariant::String )
359 s += qgsQStringApproximateMemoryUsage( v.toString() );
361 else if ( v.type() == QVariant::StringList )
363 for (
const QString &
str : v.toStringList() )
364 s += qgsQStringApproximateMemoryUsage(
str );
366 else if ( v.type() == QVariant::List )
368 for (
const QVariant &subV : v.toList() )
369 s += qgsQVariantApproximateMemoryUsage( subV );
376 size_t s =
sizeof( *this ) +
sizeof( *d );
379 for (
const QVariant &attr : std::as_const( d->attributes ) )
381 s += qgsQVariantApproximateMemoryUsage( attr );
385 s +=
sizeof( QAtomicInt ) +
sizeof(
void * );
388 s += d->geometry.wkbSize();
391 s +=
sizeof( QgsFieldsPrivate );
393 s += d->fields.size() * (
sizeof(
QgsField ) +
sizeof( QgsFieldPrivate ) );
395 return static_cast<int>( s );
428 in >>
id >> attr >> geometry >> valid;
439 const auto constAttributes = key.
attributes();
440 for (
const QVariant &attr : constAttributes )
442 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)
QVariantMap attributeMap() const
Returns the feature's attributes as a map of field name to value.
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.
Abstract base class for all rendered symbols.
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.
const QgsSymbol * embeddedSymbol() const
Returns the feature's embedded symbology, or nullptr if the feature has no embedded symbol.
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)
Assigns a field map with the feature to allow attribute access by attribute name.
int attributeCount() const
Returns the number of attributes attached to the feature.
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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
QDataStream & operator<<(QDataStream &out, const QgsFeature &feature)
Writes the feature to stream out. QGIS version compatibility is not guaranteed.
void resizeAttributes(int fieldCount)
Resizes the attributes attached to this feature to the given number of fields.
bool setAttribute(int field, const QVariant &attr)
Sets 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.
bool operator!=(const QgsFeature &other) const
Compares two features.
A vector of attributes. Mostly equal to QVector<QVariant>.
void setEmbeddedSymbol(QgsSymbol *symbol)
Sets the feature's embedded symbol.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void deleteAttribute(int field)
Clear's an attribute's value by its index.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsFeature(QgsFeatureId id=FID_NULL)
Constructor for QgsFeature.
void padAttributes(int count)
Resizes the attributes attached to this feature by appending the specified count of NULL values to th...
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.