|
QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
|
The feature class encapsulates a single feature including its unique ID, geometry and a list of field/values attributes. More...
#include <qgsfeature.h>
Public Member Functions | |
| QgsFeature (const QgsFeature &rhs) | |
| QgsFeature (const QgsFields &fields, QgsFeatureId id=FID_NULL) | |
| Constructor for QgsFeature. | |
| QgsFeature (QgsFeatureId id=FID_NULL) | |
| Constructor for QgsFeature. | |
| virtual | ~QgsFeature () |
| int | approximateMemoryUsage () const |
| Returns the approximate RAM usage of the feature, in bytes. | |
| Q_INVOKABLE QVariant | attribute (const QString &name) const |
| Lookup attribute value by attribute name. | |
| QVariant | attribute (int fieldIdx) const |
| Lookup attribute value from its index. | |
| int | attributeCount () const |
| Returns the number of attributes attached to the feature. | |
| QVariantMap | attributeMap () const |
| Returns the feature's attributes as a map of field name to value. | |
| QgsAttributes | attributes () const |
| Returns the feature's attributes. | |
| void | clearGeometry () |
| Removes any geometry associated with the feature. | |
| bool | deleteAttribute (const QString &name) |
| Clear's an attribute's value by its field name. | |
| void | deleteAttribute (int field) |
| Clear's an attribute's value by its index. | |
| const QgsSymbol * | embeddedSymbol () const |
Returns the feature's embedded symbology, or nullptr if the feature has no embedded symbol. | |
| int | fieldNameIndex (const QString &fieldName) const |
| Utility method to get attribute index from name. | |
| QgsFields | fields () const |
| Returns the field map associated with the feature. | |
| QgsGeometry | geometry () const |
| Returns the geometry associated with this feature. | |
| bool | hasGeometry () const |
Returns true if the feature has an associated geometry. | |
| QgsFeatureId | id () const |
| Returns the feature ID for this feature. | |
| void | initAttributes (int fieldCount) |
| Initialize this feature with the given number of fields. | |
| bool | isUnsetValue (int fieldIdx) const |
Returns true if the attribute at the specified index is an unset value. | |
| bool | isValid () const |
| Returns the validity of this feature. | |
| operator QVariant () const | |
| Allows direct construction of QVariants from features. | |
| bool | operator!= (const QgsFeature &other) const |
| QgsFeature & | operator= (const QgsFeature &rhs) |
| bool | operator== (const QgsFeature &other) const |
| void | padAttributes (int count) |
| Resizes the attributes attached to this feature by appending the specified count of NULL values to the end of the existing attributes. | |
| void | resizeAttributes (int fieldCount) |
| Resizes the attributes attached to this feature to the given number of fields. | |
| Q_INVOKABLE bool | setAttribute (const QString &name, const QVariant &value) |
| Insert a value into attribute, by field name. | |
| Q_INVOKABLE bool | setAttribute (int field, const QVariant &attr) |
| Sets an attribute's value by field index. | |
| void | setAttributes (const QgsAttributes &attrs) |
| Sets the feature's attributes. | |
| void | setEmbeddedSymbol (QgsSymbol *symbol) |
| Sets the feature's embedded symbol. | |
| void | setFields (const QgsFields &fields, bool initAttributes=false) |
| Assigns a field map with the feature to allow attribute access by attribute name. | |
| void | setGeometry (const QgsGeometry &geometry) |
| Set the feature's geometry. | |
| void | setGeometry (std::unique_ptr< QgsAbstractGeometry > geometry) |
| Set the feature's geometry. | |
| void | setId (QgsFeatureId id) |
| Sets the feature id for this feature. | |
| void | setValid (bool validity) |
| Sets the validity of the feature. | |
Properties | |
| QgsAttributes | attributes |
| QgsFields | fields |
| QgsGeometry | geometry |
| QgsFeatureId | id |
The feature class encapsulates a single feature including its unique ID, geometry and a list of field/values attributes.
Definition at line 59 of file qgsfeature.h.
| QgsFeature::QgsFeature | ( | QgsFeatureId | id = FID_NULL | ) |
Constructor for QgsFeature.
| id | unique feature ID |
Definition at line 45 of file qgsfeature.cpp.
| QgsFeature::QgsFeature | ( | const QgsFields & | fields, |
| QgsFeatureId | id = FID_NULL ) |
Constructor for QgsFeature.
| fields | feature's fields |
| id | unique feature ID |
Definition at line 50 of file qgsfeature.cpp.
| QgsFeature::QgsFeature | ( | const QgsFeature & | rhs | ) |
Definition at line 57 of file qgsfeature.cpp.
|
virtual |
Definition at line 94 of file qgsfeature.cpp.
| int QgsFeature::approximateMemoryUsage | ( | ) | const |
Returns the approximate RAM usage of the feature, in bytes.
This method takes into account the size of variable elements (strings, geometry, ...), but the value returned should be considered as a lower bound estimation.
Definition at line 385 of file qgsfeature.cpp.
| QVariant QgsFeature::attribute | ( | const QString & | name | ) | const |
Lookup attribute value by attribute name.
Field map must be associated using setFields() before this method can be used.
| name | The name of the attribute to get |
Definition at line 338 of file qgsfeature.cpp.
| QVariant QgsFeature::attribute | ( | int | fieldIdx | ) | const |
Lookup attribute value from its index.
| fieldIdx | The index of the attribute to get |
Definition at line 308 of file qgsfeature.cpp.
| int QgsFeature::attributeCount | ( | ) | const |
Returns the number of attributes attached to the feature.
Definition at line 158 of file qgsfeature.cpp.
| QVariantMap QgsFeature::attributeMap | ( | ) | const |
Returns the feature's attributes as a map of field name to value.
Definition at line 140 of file qgsfeature.cpp.
| QgsAttributes QgsFeature::attributes | ( | ) | const |
Returns the feature's attributes.
Alternatively, in Python it is possible to directly iterate over a feature in order to retrieve its attributes:
Definition at line 135 of file qgsfeature.cpp.
| void QgsFeature::clearGeometry | ( | ) |
Removes any geometry associated with the feature.
Definition at line 184 of file qgsfeature.cpp.
| bool QgsFeature::deleteAttribute | ( | const QString & | name | ) |
Clear's an attribute's value by its field name.
Field map must be associated using setFields() before this method can be used.
| name | The name of the field to clear |
false if attribute name could not be converted to index Definition at line 297 of file qgsfeature.cpp.
| void QgsFeature::deleteAttribute | ( | int | field | ) |
Clear's an attribute's value by its index.
| field | the index of the field |
Definition at line 108 of file qgsfeature.cpp.
| const QgsSymbol * QgsFeature::embeddedSymbol | ( | ) | const |
Returns the feature's embedded symbology, or nullptr if the feature has no embedded symbol.
Definition at line 324 of file qgsfeature.cpp.
| int QgsFeature::fieldNameIndex | ( | const QString & | fieldName | ) | const |
Utility method to get attribute index from name.
Field map must be associated using setFields() before this method can be used.
| fieldName | name of field to get attribute index of |
Definition at line 353 of file qgsfeature.cpp.
| QgsFields QgsFeature::fields | ( | ) | const |
Returns the field map associated with the feature.
Definition at line 208 of file qgsfeature.cpp.
| QgsGeometry QgsFeature::geometry | ( | ) | const |
Returns the geometry associated with this feature.
If the feature has no geometry, an empty QgsGeometry object will be returned.
Definition at line 114 of file qgsfeature.cpp.
| bool QgsFeature::hasGeometry | ( | ) | const |
Returns true if the feature has an associated geometry.
Definition at line 233 of file qgsfeature.cpp.
| QgsFeatureId QgsFeature::id | ( | ) | const |
Returns the feature ID for this feature.
Definition at line 103 of file qgsfeature.cpp.
| void QgsFeature::initAttributes | ( | int | fieldCount | ) |
Initialize this feature with the given number of fields.
Discards any previously set attribute data.
| fieldCount | Number of fields to initialize |
Definition at line 238 of file qgsfeature.cpp.
| bool QgsFeature::isUnsetValue | ( | int | fieldIdx | ) | const |
Returns true if the attribute at the specified index is an unset value.
Definition at line 316 of file qgsfeature.cpp.
| bool QgsFeature::isValid | ( | ) | const |
Returns the validity of this feature.
This is normally set by the provider to indicate some problem that makes the feature invalid or to indicate a null feature.
Definition at line 219 of file qgsfeature.cpp.
|
inline |
Allows direct construction of QVariants from features.
Definition at line 1262 of file qgsfeature.h.
| bool QgsFeature::operator!= | ( | const QgsFeature & | other | ) | const |
Definition at line 89 of file qgsfeature.cpp.
| QgsFeature & QgsFeature::operator= | ( | const QgsFeature & | rhs | ) |
Definition at line 61 of file qgsfeature.cpp.
| bool QgsFeature::operator== | ( | const QgsFeature & | other | ) | const |
Definition at line 70 of file qgsfeature.cpp.
| void QgsFeature::padAttributes | ( | int | count | ) |
Resizes the attributes attached to this feature by appending the specified count of NULL values to the end of the existing attributes.
Definition at line 256 of file qgsfeature.cpp.
| void QgsFeature::resizeAttributes | ( | int | fieldCount | ) |
Resizes the attributes attached to this feature to the given number of fields.
If the new fieldCount is greater than the original number of fields then the additional attributes will be filled with NULL values. All existing attributes will remain unchanged.
If the new fieldCount is less than the original number of fields then the unwanted values will be discarded from the end of the existing attributes.
Definition at line 247 of file qgsfeature.cpp.
| bool QgsFeature::setAttribute | ( | const QString & | name, |
| const QVariant & | value ) |
Insert a value into attribute, by field name.
Returns false if field name could not be matched.
Field map must be associated using setFields() before this method can be used.
Calling this method will automatically set the feature as valid (see isValid()).
| name | The name of the field to set |
| value | The value to set |
false if attribute name could not be converted to index Definition at line 285 of file qgsfeature.cpp.
| bool QgsFeature::setAttribute | ( | int | field, |
| const QVariant & | attr ) |
Sets an attribute's value by field index.
If the attribute was successfully set then the feature will be automatically marked as valid (see isValid()).
| field | the index of the field to set |
| attr | the value of the attribute |
false, if the field index does not exist Definition at line 265 of file qgsfeature.cpp.
| void QgsFeature::setAttributes | ( | const QgsAttributes & | attrs | ) |
Sets the feature's attributes.
Calling this method will automatically set the feature as valid (see isValid()).
The number of provided attributes need to exactly match the number of the feature's fields.
| attrs | List of attribute values |
Definition at line 163 of file qgsfeature.cpp.
| void QgsFeature::setEmbeddedSymbol | ( | QgsSymbol * | symbol | ) |
Sets the feature's embedded symbol.
Ownership of symbol is transferred to the feature.
Definition at line 329 of file qgsfeature.cpp.
| void QgsFeature::setFields | ( | const QgsFields & | fields, |
| bool | initAttributes = false ) |
Assigns a field map with the feature to allow attribute access by attribute name.
| fields | The attribute fields which this feature holds |
| initAttributes | If true, attributes are initialized. Clears any data previously assigned. |
Definition at line 198 of file qgsfeature.cpp.
| void QgsFeature::setGeometry | ( | const QgsGeometry & | geometry | ) |
Set the feature's geometry.
Calling this method will automatically set the feature as valid (see isValid()).
| geometry | new feature geometry |
Definition at line 170 of file qgsfeature.cpp.
| void QgsFeature::setGeometry | ( | std::unique_ptr< QgsAbstractGeometry > | geometry | ) |
Set the feature's geometry.
Ownership of the geometry is transferred to the feature.
Calling this method will automatically set the feature as valid (see isValid()).
This method is a shortcut for calling:
Definition at line 177 of file qgsfeature.cpp.
| void QgsFeature::setId | ( | QgsFeatureId | id | ) |
Sets the feature id for this feature.
| id | feature id |
Definition at line 125 of file qgsfeature.cpp.
| void QgsFeature::setValid | ( | bool | validity | ) |
Sets the validity of the feature.
| validity | set to true if feature is valid |
Definition at line 224 of file qgsfeature.cpp.
|
readwrite |
Definition at line 69 of file qgsfeature.h.
|
readwrite |
Definition at line 70 of file qgsfeature.h.
|
readwrite |
Definition at line 71 of file qgsfeature.h.
|
readwrite |
Definition at line 68 of file qgsfeature.h.