QGIS API Documentation  master-6227475
QgsFeature Class Reference

The feature class encapsulates a single feature including its id, geometry and a list of field/values attributes. More...

#include <qgsfeature.h>

+ Collaboration diagram for QgsFeature:

List of all members.

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 QgsAttributesattributes () const
QgsAttributesattributes ()
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 QgsFieldsfields () const
 Get associated field map.
QgsGeometrygeometry () const
 Get the geometry object associated with this feature.
QgsGeometrygeometryAndOwnership ()
 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)
bool isValid () const
 Return the validity of this feature.
QgsFeatureoperator= (QgsFeature const &rhs)
 assignment operator needed due to internal pointer
bool setAttribute (int field, const QVariant &attr)
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)
 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.

Private Attributes

QgsAttributes mAttributes
 attributes accessed by field index
QgsFeatureId mFid
 feature id
const QgsFieldsmFields
 Optional field map for name-based attribute lookups.
QgsGeometrymGeometry
 pointer to geometry in binary WKB format
bool mOwnsGeometry
 Indicator if the mGeometry is owned by this QgsFeature.
bool mValid
 Flag to indicate if this feature is valid.

Detailed Description

The feature class encapsulates a single feature including its id, geometry and a list of field/values attributes.

Encapsulates a spatial feature with attributes.

Author:
Gary E.Sherman

Definition at line 114 of file qgsfeature.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 27 of file qgsfeature.cpp.

QgsFeature::QgsFeature ( const QgsFields fields,
QgsFeatureId  id = QgsFeatureId() 
)

Definition at line 37 of file qgsfeature.cpp.

References QgsFields::count(), and initAttributes().

copy ctor needed due to internal pointer

Definition at line 47 of file qgsfeature.cpp.

References mGeometry, and setGeometry().

Destructor.

Definition at line 90 of file qgsfeature.cpp.

References mGeometry, and mOwnsGeometry.


Member Function Documentation

QVariant QgsFeature::attribute ( const QString &  name) const
QVariant QgsFeature::attribute ( int  fieldIdx) const

Lookup attribute value from its index.

Returns invalid variant if the index does not exist.

Note:
added in 2.0

Definition at line 214 of file qgsfeature.cpp.

References mAttributes.

Definition at line 144 of file qgsfeature.h.

void QgsFeature::deleteAttribute ( int  field)

Deletes an attribute and its value.

Definition at line 107 of file qgsfeature.cpp.

References mAttributes.

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.

Note:
added in 2.0

Definition at line 204 of file qgsfeature.cpp.

References fieldNameIndex(), and mAttributes.

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.

Note:
added in 2.0

Definition at line 231 of file qgsfeature.cpp.

References QgsFields::at(), QgsFields::count(), mFields, and QgsField::name().

Referenced by attribute(), deleteAttribute(), and setAttribute().

const QgsFields* QgsFeature::fields ( ) const [inline]

Get associated field map.

may be NULL

Note:
added in 2.0

Definition at line 199 of file qgsfeature.h.

Get the geometry object associated with this feature.

Definition at line 113 of file qgsfeature.cpp.

References mGeometry.

Referenced by QgsVectorLayerImport::addFeature(), QgsVectorLayerEditUtils::addPart(), QgsVectorLayerEditUtils::addRing(), QgsVectorLayer::boundingBoxOfSelected(), QgsGeometryAnalyzer::bufferFeature(), QgsInterpolator::cacheBaseData(), QgsGml::calculateExtentFromFeatures(), QgsZonalStatistics::calculateStatistics(), QgsGeometryAnalyzer::centroidFeature(), QgsGeometryAnalyzer::convexFeature(), QgsPointDisplacementRenderer::createDisplacementGroups(), QgsVectorFileWriter::createFeature(), QgsGeometryAnalyzer::dissolveFeature(), QgsVectorLayer::drawRendererV2(), QgsVectorLayer::drawRendererV2Levels(), QgsGeometryAnalyzer::eventLayer(), QgsVectorFileWriter::exportFeaturesSymbolLevels(), QgsVectorLayer::extent(), fcnGeomArea(), fcnGeometry(), fcnGeomLength(), fcnGeomPerimeter(), QgsMapToolIdentify::featureDerivedAttributes(), QgsSpatialIndex::featureInfo(), QgsVectorLayerImport::importLayer(), QgsTINInterpolator::insertData(), QgsOverlayAnalyzer::intersectFeature(), QgsLabel::labelPoint(), QgsLineVectorLayerDirector::makeGraph(), QgsAtlasComposition::prepareForFeature(), QgsAttributeDialog::QgsAttributeDialog(), QgsVectorLayerUndoCommandAddFeature::redo(), QgsPalLabeling::registerDiagramFeature(), QgsPalLayerSettings::registerFeature(), QgsVectorLayer::removePolygonIntersections(), QgsPointDisplacementRenderer::renderFeature(), QgsFeatureRendererV2::renderFeatureWithSymbol(), QgsGeometryAnalyzer::simplifyFeature(), QgsVectorLayer::snapWithContext(), QgsVectorLayerEditUtils::translateFeature(), QgsVectorLayerUndoCommandAddFeature::undo(), QgsVectorLayerUndoCommandChangeGeometry::undo(), QgsVectorLayer::updateFeature(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorFileWriter::writeAsVectorFormat().

Get the geometry object associated with this feature The caller assumes responsibility for the QgsGeometry*'s destruction.

Definition at line 118 of file qgsfeature.cpp.

References mGeometry, and mOwnsGeometry.

Get the feature id for this feature.

Returns:
Feature id

Definition at line 101 of file qgsfeature.cpp.

References mFid.

Referenced by QgsVectorLayerEditUtils::addRing(), QgsAttributeTableModel::attributeValueChanged(), QgsAtlasComposition::beginRender(), QgsVectorLayer::boundingBoxOfSelected(), QgsVectorLayerCache::cacheFeature(), QgsZonalStatistics::calculateStatistics(), QgsOfflineEditing::copyVectorLayer(), QgsPointDisplacementRenderer::createDisplacementGroups(), QgsVectorFileWriter::createFeature(), QgsFeatureListModel::data(), QgsAttributeTableModel::data(), QgsVectorLayer::drawRendererV2(), QgsVectorLayer::drawRendererV2Levels(), QgsGml::endElement(), QgsGeometryAnalyzer::eventLayer(), fcnFeatureId(), QgsSpatialIndex::featureInfo(), QgsAttributeTableFilterModel::generateListOfVisibleFeatures(), QgsVectorLayerImport::importLayer(), QgsVectorLayer::invertSelection(), QgsVectorLayer::invertSelectionInRectangle(), QgsAttributeTableModel::loadLayer(), QgsVectorLayerFeatureIterator::nextFeature(), QgsCachedFeatureWriterIterator::nextFeature(), QgsExpressionSelectionDialog::on_mActionAddToSelection_triggered(), QgsExpressionSelectionDialog::on_mActionRemoveFromSelection_triggered(), QgsExpressionSelectionDialog::on_mActionSelect_triggered(), QgsExpressionSelectionDialog::on_mActionSelectInstersect_triggered(), QgsAttributeTableModel::prefetchColumnData(), QgsAttributeDialog::QgsAttributeDialog(), QgsVectorLayerUndoCommandDeleteAttribute::QgsVectorLayerUndoCommandDeleteAttribute(), QgsVectorLayerUndoCommandAddFeature::redo(), QgsPalLabeling::registerDiagramFeature(), QgsPalLayerSettings::registerFeature(), QgsVectorLayer::removePolygonIntersections(), QgsPointDisplacementRenderer::renderFeature(), QgsFeatureRendererV2::renderFeatureWithSymbol(), QgsDualView::saveEditChanges(), QgsVectorLayer::select(), QgsVectorLayer::selectAll(), QgsFormAnnotationItem::setFeatureForMapPosition(), QgsHtmlAnnotationItem::setFeatureForMapPosition(), setFeatureId(), QgsVectorLayer::snapWithContext(), QgsVectorLayerUndoCommandAddFeature::undo(), QgsVectorLayerUndoCommandDeleteFeature::undo(), QgsVectorLayerUndoCommandDeleteAttribute::undo(), QgsVectorLayerEditBuffer::updateChangedAttributes(), QgsVectorLayer::updateFeature(), QgsVectorLayerEditBuffer::updateFeatureGeometry(), QgsOfflineEditing::updateFidLookup(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorFileWriter::writeAsVectorFormat().

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 163 of file qgsfeature.cpp.

References mValid.

Referenced by QgsAttributeTableModel::data(), QgsDualView::on_mFeatureList_currentEditSelectionChanged(), and QgsExpressionBuilderWidget::on_txtExpressionString_textChanged().

QgsFeature & QgsFeature::operator= ( QgsFeature const &  rhs)

assignment operator needed due to internal pointer

Definition at line 64 of file qgsfeature.cpp.

References mAttributes, mFid, mFields, mGeometry, mOwnsGeometry, mValid, and setGeometry().

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.

Note:
added in 2.0

Definition at line 194 of file qgsfeature.cpp.

References fieldNameIndex(), and mAttributes.

void QgsFeature::setFields ( const QgsFields fields) [inline]

Assign a field map with the feature to allow attribute access by attribute name.

Note:
added in 2.0

Definition at line 194 of file qgsfeature.h.

Referenced by QgsVectorLayerFeatureIterator::nextFeature(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorLayerFeatureIterator::useChangedAttributeFeature().

Set this feature's geometry (takes geometry ownership)

Note:
not available in python bindings

Definition at line 140 of file qgsfeature.cpp.

References mGeometry, and mOwnsGeometry.

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 155 of file qgsfeature.cpp.

References QgsGeometry::fromWkb(), and setGeometry().

Referenced by QgsGml::endElement().


Member Data Documentation

attributes accessed by field index

Definition at line 236 of file qgsfeature.h.

Referenced by attribute(), deleteAttribute(), initAttributes(), operator=(), and setAttribute().

feature id

Definition at line 233 of file qgsfeature.h.

Referenced by id(), operator=(), and setFeatureId().

const QgsFields* QgsFeature::mFields [private]

Optional field map for name-based attribute lookups.

Definition at line 253 of file qgsfeature.h.

Referenced by fieldNameIndex(), and operator=().

pointer to geometry in binary WKB format

This is usually set by a call to OGRGeometry::exportToWkb()

Definition at line 242 of file qgsfeature.h.

Referenced by geometry(), geometryAndOwnership(), operator=(), QgsFeature(), setGeometry(), and ~QgsFeature().

bool QgsFeature::mOwnsGeometry [private]

Indicator if the mGeometry is owned by this QgsFeature.

If so, this QgsFeature takes responsibility for the mGeometry's destruction.

Definition at line 247 of file qgsfeature.h.

Referenced by geometryAndOwnership(), operator=(), setGeometry(), and ~QgsFeature().

bool QgsFeature::mValid [private]

Flag to indicate if this feature is valid.

Definition at line 250 of file qgsfeature.h.

Referenced by isValid(), operator=(), and setValid().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines