QGIS API Documentation
2.6.0-Brighton
|
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 & | operator= (QgsFeature const &rhs) |
assignment operator needed due to internal pointer | |
~QgsFeature () | |
Destructor. | |
QgsFeatureId | id () const |
Get the feature id for this feature. | |
void | setFeatureId (QgsFeatureId id) |
Set the feature id for this feature. | |
const QgsAttributes & | attributes () const |
QgsAttributes & | attributes () |
void | setAttributes (const QgsAttributes &attrs) |
bool | setAttribute (int field, const QVariant &attr) |
Set an attribute by id. | |
void | initAttributes (int fieldCount) |
Initialize this feature with the given number of fields. | |
void | deleteAttribute (int field) |
Deletes an attribute and its value. | |
bool | isValid () const |
Return the validity of this feature. | |
void | setValid (bool validity) |
Set the validity of the feature. | |
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. | |
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 | setFields (const QgsFields *fields, bool initAttributes=false) |
Assign a field map with the feature to allow attribute access by attribute name. | |
const QgsFields * | fields () const |
Get associated field map. | |
bool | setAttribute (const QString &name, QVariant value) |
Insert a value into attribute. | |
bool | deleteAttribute (const QString &name) |
Remove an attribute value. | |
QVariant | attribute (const QString &name) const |
Lookup attribute value from attribute name. | |
QVariant | attribute (int fieldIdx) const |
Lookup attribute value from its index. | |
int | fieldNameIndex (const QString &fieldName) const |
Utility method to get attribute index from name. |
The feature class encapsulates a single feature including its id, geometry and a list of field/values attributes.
Encapsulates a spatial feature with attributes.
QgsFeature::QgsFeature | ( | QgsFeatureId | id = QgsFeatureId() | ) |
Constructor.
QgsFeature::QgsFeature | ( | const QgsFields & | fields, |
QgsFeatureId | id = QgsFeatureId() |
||
) |
QgsFeature::QgsFeature | ( | const QgsFeature & | rhs | ) |
copy ctor needed due to internal pointer
QgsFeature::~QgsFeature | ( | ) |
Destructor.
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 |
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 |
|
inline |
|
inline |
void QgsFeature::deleteAttribute | ( | int | field | ) |
Deletes an attribute and its value.
field | The index of the field |
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 |
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.
|
inline |
Get associated field map.
TODO: QGIS 3 - return reference or value, not pointer
QgsGeometry * QgsFeature::geometry | ( | ) | const |
Get the geometry object associated with this feature.
QgsGeometry * QgsFeature::geometryAndOwnership | ( | ) |
Get the geometry object associated with this feature The caller assumes responsibility for the QgsGeometry*'s destruction.
QgsFeatureId QgsFeature::id | ( | ) | const |
Get the feature id for this feature.
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 |
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.
QgsFeature & QgsFeature::operator= | ( | QgsFeature const & | rhs | ) |
assignment operator needed due to internal pointer
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 |
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 |
|
inline |
void QgsFeature::setFeatureId | ( | QgsFeatureId | id | ) |
Set the feature id for this feature.
Set the feature id.
id | Feature id |
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
void QgsFeature::setGeometry | ( | const QgsGeometry & | geom | ) |
Set this feature's geometry from another QgsGeometry object (deep copy)
void QgsFeature::setGeometry | ( | QgsGeometry * | geom | ) |
Set this feature's geometry (takes geometry ownership)
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.
void QgsFeature::setValid | ( | bool | validity | ) |
Set the validity of the feature.