QGIS API Documentation
3.8.0-Zanzibar (11aff65)
|
The feature class encapsulates a single feature including its id, geometry and a list of field/values attributes. More...
#include <qgsfeature.h>
Public Member Functions | |
QgsFeature (QgsFeatureId id=QgsFeatureId()) | |
Constructor for QgsFeature. More... | |
QgsFeature (const QgsFields &fields, QgsFeatureId id=QgsFeatureId()) | |
Constructor for QgsFeature. More... | |
QgsFeature (const QgsFeature &rhs) | |
Copy constructor. More... | |
virtual | ~QgsFeature () |
QVariant | attribute (const QString &name) const |
Lookup attribute value from attribute name. More... | |
QVariant | attribute (int fieldIdx) const |
Lookup attribute value from its index. More... | |
QgsAttributes | attributes () const |
Returns the feature's attributes. More... | |
void | clearGeometry () |
Removes any geometry associated with the feature. More... | |
void | deleteAttribute (int field) |
Deletes an attribute and its value. More... | |
bool | deleteAttribute (const QString &name) |
Removes an attribute value by field name. More... | |
int | fieldNameIndex (const QString &fieldName) const |
Utility method to get attribute index from name. More... | |
QgsFields | fields () const |
Returns the field map associated with the feature. More... | |
QgsGeometry | geometry () const |
Returns the geometry associated with this feature. More... | |
bool | hasGeometry () const |
Returns true if the feature has an associated geometry. More... | |
QgsFeatureId | id () const |
Gets the feature ID for this feature. More... | |
void | initAttributes (int fieldCount) |
Initialize this feature with the given number of fields. More... | |
bool | isValid () const |
Returns the validity of this feature. More... | |
operator QVariant () const | |
Allows direct construction of QVariants from features. More... | |
bool | operator!= (const QgsFeature &other) const |
Compares two features. More... | |
QgsFeature & | operator= (const QgsFeature &rhs) |
Assignment operator. More... | |
bool | operator== (const QgsFeature &other) const |
Compares two features. More... | |
bool | setAttribute (int field, const QVariant &attr) |
Set an attribute's value by field index. More... | |
bool | setAttribute (const QString &name, const QVariant &value) |
Insert a value into attribute. More... | |
void | setAttributes (const QgsAttributes &attrs) |
Sets the feature's attributes. More... | |
void | setFields (const QgsFields &fields, bool initAttributes=false) |
Assign a field map with the feature to allow attribute access by attribute name. More... | |
void | setGeometry (const QgsGeometry &geometry) |
Set the feature's geometry. More... | |
void | setGeometry (std::unique_ptr< QgsAbstractGeometry > geometry) |
Set the feature's geometry. More... | |
void | setId (QgsFeatureId id) |
Sets the feature ID for this feature. More... | |
void | setValid (bool validity) |
Sets the validity of the feature. More... | |
Properties | |
QgsAttributes | attributes |
QgsFields | fields |
QgsGeometry | geometry |
QgsFeatureId | id |
The feature class encapsulates a single feature including its id, geometry and a list of field/values attributes.
Definition at line 55 of file qgsfeature.h.
QgsFeature::QgsFeature | ( | QgsFeatureId | id = QgsFeatureId() | ) |
QgsFeature::QgsFeature | ( | const QgsFields & | fields, |
QgsFeatureId | id = QgsFeatureId() |
||
) |
Constructor for QgsFeature.
fields | feature's fields |
id | feature id |
Definition at line 42 of file qgsfeature.cpp.
QgsFeature::QgsFeature | ( | const QgsFeature & | rhs | ) |
Copy constructor.
Definition at line 49 of file qgsfeature.cpp.
|
virtual |
Definition at line 80 of file qgsfeature.cpp.
QVariant QgsFeature::attribute | ( | const QString & | name | ) | const |
Lookup attribute value from 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 262 of file qgsfeature.cpp.
QVariant QgsFeature::attribute | ( | int | fieldIdx | ) | const |
Lookup attribute value from its index.
Field map must be associated using setFields() before this method can be used.
fieldIdx | The index of the attribute to get |
Definition at line 254 of file qgsfeature.cpp.
QgsAttributes QgsFeature::attributes | ( | ) | const |
Returns the feature's attributes.
void QgsFeature::clearGeometry | ( | ) |
Removes any geometry associated with the feature.
Definition at line 151 of file qgsfeature.cpp.
void QgsFeature::deleteAttribute | ( | int | field | ) |
Deletes an attribute and its value.
field | the index of the field |
Definition at line 95 of file qgsfeature.cpp.
bool QgsFeature::deleteAttribute | ( | const QString & | name | ) |
Removes an attribute value by field name.
Field map must be associated using setFields() before this method can be used.
name | The name of the field to delete |
false
if attribute name could not be converted to index (C++ only) false
Definition at line 243 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 277 of file qgsfeature.cpp.
QgsFields QgsFeature::fields | ( | ) | const |
Returns the field map associated with the feature.
QgsGeometry QgsFeature::geometry | ( | ) | const |
Returns the geometry associated with this feature.
If the feature has no geometry, an empty QgsGeometry object will be returned.
bool QgsFeature::hasGeometry | ( | ) | const |
Returns true
if the feature has an associated geometry.
Definition at line 197 of file qgsfeature.cpp.
QgsFeatureId QgsFeature::id | ( | ) | const |
void QgsFeature::initAttributes | ( | int | fieldCount | ) |
Initialize this feature with the given number of fields.
Discard any previously set attribute data.
fieldCount | Number of fields to initialize |
Definition at line 202 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 183 of file qgsfeature.cpp.
|
inline |
Allows direct construction of QVariants from features.
Definition at line 539 of file qgsfeature.h.
bool QgsFeature::operator!= | ( | const QgsFeature & | other | ) | const |
Compares two features.
Definition at line 75 of file qgsfeature.cpp.
QgsFeature & QgsFeature::operator= | ( | const QgsFeature & | rhs | ) |
Assignment operator.
Definition at line 54 of file qgsfeature.cpp.
bool QgsFeature::operator== | ( | const QgsFeature & | other | ) | const |
Compares two features.
Definition at line 60 of file qgsfeature.cpp.
bool QgsFeature::setAttribute | ( | int | field, |
const QVariant & | attr | ||
) |
Set an attribute's value by field index.
The feature will be valid if it was successful.
field | the index of the field to set |
attr | the value of the attribute |
false
, if the field index does not exist false
Definition at line 211 of file qgsfeature.cpp.
bool QgsFeature::setAttribute | ( | const QString & | name, |
const QVariant & | value | ||
) |
Insert a value into attribute.
Returns false
if attribute name could not be converted to index. Field map must be associated using setFields() before this method can be used. The feature will be valid if it was successful
name | The name of the field to set |
value | The value to set |
false
if attribute name could not be converted to index (C++ only) false
Definition at line 231 of file qgsfeature.cpp.
void QgsFeature::setAttributes | ( | const QgsAttributes & | attrs | ) |
Sets the feature's attributes.
The feature will be valid after.
attrs | attribute list |
Definition at line 127 of file qgsfeature.cpp.
void QgsFeature::setFields | ( | const QgsFields & | fields, |
bool | initAttributes = false |
||
) |
Assign 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. C++: Defaults to false Python: Defaults to true |
Definition at line 162 of file qgsfeature.cpp.
void QgsFeature::setGeometry | ( | const QgsGeometry & | geometry | ) |
Set the feature's geometry.
The feature will be valid after.
geometry | new feature geometry |
Definition at line 137 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. The feature will be made valid after calling this method.
This method is a shortcut for calling:
Definition at line 144 of file qgsfeature.cpp.
void QgsFeature::setId | ( | QgsFeatureId | id | ) |
Sets the feature ID for this feature.
id | feature id |
Definition at line 112 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 188 of file qgsfeature.cpp.
|
readwrite |
Definition at line 65 of file qgsfeature.h.
|
readwrite |
Definition at line 66 of file qgsfeature.h.
|
readwrite |
Definition at line 67 of file qgsfeature.h.
|
readwrite |
Definition at line 64 of file qgsfeature.h.