QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
|
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 () |
Destructor. More... | |
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... | |
const QgsGeometry * | constGeometry () const |
Gets a const pointer to the geometry object associated with this 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... | |
const QgsFields * | fields () const |
Returns the field map associated with the feature. More... | |
QgsGeometry * | geometry () |
Get the geometry object associated with this feature. More... | |
Q_DECL_DEPRECATED QgsGeometry * | geometryAndOwnership () |
Get the geometry object associated with this feature, and transfer ownership of the geometry to the caller. More... | |
QgsFeatureId | id () const |
Get 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... | |
QgsFeature & | operator= (QgsFeature const &rhs) |
Assignment operator. 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 | setFeatureId (QgsFeatureId id) |
Sets the feature ID for this feature. More... | |
Q_DECL_DEPRECATED void | setFields (const QgsFields *fields, bool initAttributes=false) |
Assign a field map with the feature to allow attribute access by attribute name. 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 &geom) |
Set this feature's geometry from another QgsGeometry object. More... | |
void | setGeometry (QgsGeometry *geom) |
Set this feature's geometry from a QgsGeometry pointer. More... | |
Q_DECL_DEPRECATED void | setGeometryAndOwnership (unsigned char *geom, int length) |
Set this feature's geometry from WKB. More... | |
void | setValid (bool validity) |
Sets the validity of the feature. More... | |
The feature class encapsulates a single feature including its id, geometry and a list of field/values attributes.
Definition at line 187 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 37 of file qgsfeature.cpp.
QgsFeature::QgsFeature | ( | const QgsFeature & | rhs | ) |
Copy constructor.
Definition at line 44 of file qgsfeature.cpp.
|
virtual |
Destructor.
Definition at line 55 of file qgsfeature.cpp.
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 271 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 263 of file qgsfeature.cpp.
QgsAttributes QgsFeature::attributes | ( | ) | const |
Returns the feature's attributes.
attributes method.
Definition at line 110 of file qgsfeature.cpp.
const QgsGeometry * QgsFeature::constGeometry | ( | ) | const |
Gets a const pointer to the geometry object associated with this feature.
If the geometry is not going to be modified than this method is preferable to the non-const geometry method.
Definition at line 82 of file qgsfeature.cpp.
void QgsFeature::deleteAttribute | ( | int | field | ) |
Deletes an attribute and its value.
field | the index of the field |
Definition at line 70 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 |
Definition at line 252 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 286 of file qgsfeature.cpp.
const QgsFields * QgsFeature::fields | ( | ) | const |
Returns the field map associated with the feature.
Definition at line 188 of file qgsfeature.cpp.
QgsGeometry * QgsFeature::geometry | ( | ) |
Get the geometry object associated with this feature.
If the geometry is not going to be modified than calling the const constGeometry method is preferable as it avoids a potentially expensive detach operation.
It is possible to modify the geometry in place but this will be removed in 3.0 and therefore setGeometry should be called explicitly.
QgsGeometry geometry() const;
Definition at line 76 of file qgsfeature.cpp.
QgsGeometry * QgsFeature::geometryAndOwnership | ( | ) |
Get the geometry object associated with this feature, and transfer ownership of the geometry to the caller.
The caller assumes responsibility for the QgsGeometry*'s destruction.
Definition at line 87 of file qgsfeature.cpp.
QgsFeatureId QgsFeature::id | ( | ) | const |
Get the feature ID for this feature.
Definition at line 65 of file qgsfeature.cpp.
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 213 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 199 of file qgsfeature.cpp.
|
inline |
Allows direct construction of QVariants from features.
Definition at line 417 of file qgsfeature.h.
QgsFeature & QgsFeature::operator= | ( | QgsFeature const & | rhs | ) |
Assignment operator.
Definition at line 49 of file qgsfeature.cpp.
bool QgsFeature::setAttribute | ( | int | field, |
const QVariant & | attr | ||
) |
Set an attribute's value by field index.
field | the index of the field to set |
attr | the value of the attribute |
Definition at line 222 of file qgsfeature.cpp.
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.
name | The name of the field to set |
value | The value to set |
Definition at line 241 of file qgsfeature.cpp.
void QgsFeature::setAttributes | ( | const QgsAttributes & | attrs | ) |
Sets the feature's attributes.
attrs | attribute list |
Definition at line 115 of file qgsfeature.cpp.
void QgsFeature::setFeatureId | ( | QgsFeatureId | id | ) |
Sets the feature ID for this feature.
id | feature id |
Definition at line 101 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 173 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 178 of file qgsfeature.cpp.
void QgsFeature::setGeometry | ( | const QgsGeometry & | geom | ) |
Set this feature's geometry from another QgsGeometry object.
This method performs a deep copy of the geometry.
geom | new feature geometry |
Definition at line 124 of file qgsfeature.cpp.
void QgsFeature::setGeometry | ( | QgsGeometry * | geom | ) |
Set this feature's geometry from a QgsGeometry pointer.
Ownership of the geometry is transferred to the feature.
geom | new feature geometry |
Definition at line 129 of file qgsfeature.cpp.
void QgsFeature::setGeometryAndOwnership | ( | unsigned char * | geom, |
int | length | ||
) |
Set this feature's geometry from WKB.
Set the pointer to the feature geometry.
This feature assumes responsibility for destroying the created geometry.
geom | geometry as WKB |
length | size of WKB |
Definition at line 166 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 204 of file qgsfeature.cpp.