QGIS API Documentation
2.8.2-Wien
|
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. | |
QgsFeature (const QgsFields &fields, QgsFeatureId id=QgsFeatureId()) | |
QgsFeature (const QgsFeature &rhs) | |
copy ctor needed due to internal pointer | |
~QgsFeature () | |
Destructor. | |
QVariant | attribute (const QString &name) const |
Lookup attribute value from attribute name. | |
QVariant | attribute (int fieldIdx) const |
Lookup attribute value from its index. | |
const QgsAttributes & | attributes () const |
QgsAttributes & | attributes () |
void | deleteAttribute (int field) |
Deletes an attribute and its value. | |
bool | deleteAttribute (const QString &name) |
Remove an attribute value. | |
int | fieldNameIndex (const QString &fieldName) const |
Utility method to get attribute index from name. | |
const QgsFields * | fields () const |
Get associated field map. | |
QgsGeometry * | geometry () const |
Get the geometry object associated with this feature. | |
QgsGeometry * | geometryAndOwnership () |
Get the geometry object associated with this feature The caller assumes responsibility for the QgsGeometry*'s destruction. | |
QgsFeatureId | id () const |
Get the feature id for this feature. | |
void | initAttributes (int fieldCount) |
Initialize this feature with the given number of fields. | |
bool | isValid () const |
Return the validity of this feature. | |
QgsFeature & | operator= (QgsFeature const &rhs) |
assignment operator needed due to internal pointer | |
bool | setAttribute (int field, const QVariant &attr) |
Set an attribute by id. | |
bool | setAttribute (const QString &name, QVariant value) |
Insert a value into attribute. | |
void | setAttributes (const QgsAttributes &attrs) |
void | setFeatureId (QgsFeatureId id) |
Set the feature id for this feature. | |
void | setFields (const QgsFields *fields, bool initAttributes=false) |
Assign a field map with the feature to allow attribute access by attribute name. | |
void | setGeometry (const QgsGeometry &geom) |
Set this feature's geometry from another QgsGeometry object (deep copy) | |
void | setGeometry (QgsGeometry *geom) |
Set this feature's geometry (takes geometry ownership) | |
void | setGeometryAndOwnership (unsigned char *geom, size_t length) |
Set this feature's geometry from WKB. | |
void | setValid (bool validity) |
Set the validity of the feature. |
The feature class encapsulates a single feature including its id, geometry and a list of field/values attributes.
Encapsulates a spatial feature with attributes.
Definition at line 113 of file qgsfeature.h.
QgsFeature::QgsFeature | ( | QgsFeatureId | id = QgsFeatureId() | ) |
Constructor.
Definition at line 27 of file qgsfeature.cpp.
QgsFeature::QgsFeature | ( | const QgsFields & | fields, |
QgsFeatureId | id = QgsFeatureId() |
||
) |
Definition at line 36 of file qgsfeature.cpp.
QgsFeature::QgsFeature | ( | const QgsFeature & | rhs | ) |
copy ctor needed due to internal pointer
Definition at line 46 of file qgsfeature.cpp.
QgsFeature::~QgsFeature | ( | ) |
Destructor.
Definition at line 89 of file qgsfeature.cpp.
QVariant QgsFeature::attribute | ( | const QString & | name | ) | const |
Lookup attribute value from attribute name.
Returns invalid variant if attribute name could not be converted to index (C++ only) Field map must be associated to make this work.
name | The name of the attribute to get |
Definition at line 230 of file qgsfeature.cpp.
QVariant QgsFeature::attribute | ( | int | fieldIdx | ) | const |
Lookup attribute value from its index.
Returns invalid variant if the index does not exist.
fieldIdx | The index of the attribute to get |
Definition at line 222 of file qgsfeature.cpp.
|
inline |
Definition at line 142 of file qgsfeature.h.
|
inline |
Definition at line 143 of file qgsfeature.h.
void QgsFeature::deleteAttribute | ( | int | field | ) |
Deletes an attribute and its value.
field | The index of the field |
Definition at line 106 of file qgsfeature.cpp.
bool QgsFeature::deleteAttribute | ( | const QString & | name | ) |
Remove an attribute value.
Returns false if attribute name could not be converted to index. Field map must be associated to make this work.
name | The name of the field to delete |
Definition at line 212 of file qgsfeature.cpp.
int QgsFeature::fieldNameIndex | ( | const QString & | fieldName | ) | const |
Utility method to get attribute index from name.
Returns -1 if field does not exist or field map is not associated. Field map must be associated to make this work.
Definition at line 239 of file qgsfeature.cpp.
|
inline |
Get associated field map.
TODO: QGIS 3 - return reference or value, not pointer
Definition at line 231 of file qgsfeature.h.
QgsGeometry * QgsFeature::geometry | ( | ) | const |
Get the geometry object associated with this feature.
Definition at line 112 of file qgsfeature.cpp.
QgsGeometry * QgsFeature::geometryAndOwnership | ( | ) |
Get the geometry object associated with this feature The caller assumes responsibility for the QgsGeometry*'s destruction.
Definition at line 117 of file qgsfeature.cpp.
QgsFeatureId QgsFeature::id | ( | ) | const |
Get the feature id for this feature.
Definition at line 100 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 181 of file qgsfeature.cpp.
bool QgsFeature::isValid | ( | ) | const |
Return 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 171 of file qgsfeature.cpp.
QgsFeature & QgsFeature::operator= | ( | QgsFeature const & | rhs | ) |
assignment operator needed due to internal pointer
Definition at line 63 of file qgsfeature.cpp.
bool QgsFeature::setAttribute | ( | int | field, |
const QVariant & | attr | ||
) |
Set an attribute by id.
field | The index of the field to set |
attr | The value of the attribute |
Definition at line 190 of file qgsfeature.cpp.
bool QgsFeature::setAttribute | ( | const QString & | name, |
QVariant | value | ||
) |
Insert a value into attribute.
Returns false if attribute name could not be converted to index. Field map must be associated to make this work.
name | The name of the field to set |
value | The value to set |
Definition at line 202 of file qgsfeature.cpp.
|
inline |
Definition at line 144 of file qgsfeature.h.
void QgsFeature::setFeatureId | ( | QgsFeatureId | id | ) |
Set the feature id for this feature.
Set the feature id.
id | Feature id |
Definition at line 128 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. When used from python, make sure a copy of the fields is held by python, as ownership stays there. I.e. Do not call feature.setFields( myDataProvider.fields() ) but instead call myFields = myDataProvider.fields() feature.setFields( myFields ) |
initAttributes | If true, attributes are initialized. Clears any data previously assigned. C++: Defaults to false Python: Defaults to true |
TODO: QGIS3 - take reference, not pointer
Definition at line 161 of file qgsfeature.cpp.
void QgsFeature::setGeometry | ( | const QgsGeometry & | geom | ) |
Set this feature's geometry from another QgsGeometry object (deep copy)
Definition at line 134 of file qgsfeature.cpp.
void QgsFeature::setGeometry | ( | QgsGeometry * | geom | ) |
Set this feature's geometry (takes geometry ownership)
Definition at line 139 of file qgsfeature.cpp.
void QgsFeature::setGeometryAndOwnership | ( | unsigned char * | geom, |
size_t | length | ||
) |
Set this feature's geometry from WKB.
Set the pointer to the feature geometry.
This feature assumes responsibility for destroying geom.
Definition at line 154 of file qgsfeature.cpp.
void QgsFeature::setValid | ( | bool | validity | ) |
Set the validity of the feature.
Definition at line 176 of file qgsfeature.cpp.