QGIS API Documentation
2.2.0-Valmiera
|
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. |
Private Attributes | |
QgsFeatureId | mFid |
feature id | |
QgsAttributes | mAttributes |
attributes accessed by field index | |
QgsGeometry * | mGeometry |
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. | |
const QgsFields * | mFields |
Optional field map for name-based attribute lookups. |
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 114 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 37 of file qgsfeature.cpp.
References QgsFields::count(), and initAttributes().
QgsFeature::QgsFeature | ( | const QgsFeature & | rhs | ) |
copy ctor needed due to internal pointer
Definition at line 47 of file qgsfeature.cpp.
References mGeometry, and setGeometry().
QgsFeature::~QgsFeature | ( | ) |
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 231 of file qgsfeature.cpp.
References fieldNameIndex(), and mAttributes.
Referenced by QgsGeometryAnalyzer::addEventLayerFeature(), QgsVectorLayerFeatureIterator::addJoinedAttributes(), QgsDualView::attributeAdded(), QgsGeometryAnalyzer::bufferFeature(), QgsInterpolator::cacheBaseData(), QgsAttributeEditor::createAttributeEditor(), QgsVectorFileWriter::createFeature(), QgsPointSample::createRandomPoints(), QgsGraduatedSymbolRendererV2::createRenderer(), QgsTransectSample::createSample(), QgsAttributeTableModel::data(), QgsPalLayerSettings::dataDefinedValue(), QgsAttributeAction::doAction(), QgsExpression::NodeColumnRef::eval(), QgsGeometryAnalyzer::eventLayer(), QgsAttributeTableModel::featureAdded(), QgsMapTip::fetchFeature(), QgsLabel::fieldValue(), QgsTransectSample::findBaselineGeometry(), QgsSearchQueryBuilder::getFieldValues(), QgsRelation::getRelatedFeaturesRequest(), QgsAttributeDialog::init(), QgsTINInterpolator::insertData(), QgsAttributeTableModel::loadAttributes(), QgsVectorLayer::maximumValue(), QgsVectorLayer::minimumValue(), QgsRelationEditorWidget::on_mAddFeatureButton_clicked(), QgsRelationEditorWidget::on_mLinkFeatureButton_clicked(), QgsAttributeTableModel::prefetchColumnData(), QgsVectorLayerUndoCommandDeleteAttribute::QgsVectorLayerUndoCommandDeleteAttribute(), QgsPalLabeling::registerDiagramFeature(), QgsPalLayerSettings::registerFeature(), QgsDualView::reloadAttribute(), QgsVectorFieldSymbolLayer::renderPoint(), QgsVectorLayerUndoCommandChangeAttribute::undo(), QgsVectorDataProvider::uniqueValues(), and QgsVectorLayer::uniqueValues().
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 223 of file qgsfeature.cpp.
References mAttributes.
|
inline |
Definition at line 143 of file qgsfeature.h.
Referenced by QgsVectorLayerEditBuffer::addFeature(), QgsVectorLayerImport::addFeature(), QgsVectorLayerFeatureIterator::addJoinedAttributes(), QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect(), QgsOfflineEditing::applyFeaturesAdded(), QgsDualView::attributeAdded(), QgsGeometryAnalyzer::bufferFeature(), QgsVectorLayerJoinBuffer::cacheJoinLayer(), QgsGeometryAnalyzer::centroidFeature(), QgsVectorLayerEditBuffer::commitChanges(), QgsOfflineEditing::copyVectorLayer(), QgsFormAnnotationItem::createDesignerWidget(), QgsAttributeEditor::createWidgetFromDef(), QgsSingleCategoryDiagramRenderer::diagramSize(), QgsVectorDataProvider::fillMinMaxCache(), QgsComposerAttributeTable::getFeatureAttributes(), QgsPointDisplacementRenderer::getLabel(), QgsOverlayAnalyzer::intersectFeature(), QgsPalLabeling::registerDiagramFeature(), QgsDualView::saveEditChanges(), QgsGeometryAnalyzer::simplifyFeature(), QgsGraduatedSymbolRendererV2::symbolForFeature(), QgsCategorizedSymbolRendererV2::symbolForFeature(), QgsVectorLayerFeatureIterator::updateChangedAttributes(), QgsVectorLayerEditBuffer::updateChangedAttributes(), QgsVectorLayer::updateFeature(), QgsAtlasComposition::updateFeatures(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorLayerFeatureIterator::useChangedAttributeFeature().
|
inline |
Definition at line 144 of file qgsfeature.h.
void QgsFeature::deleteAttribute | ( | int | field | ) |
Deletes an attribute and its value.
field | The index of the field |
Definition at line 107 of file qgsfeature.cpp.
References mAttributes.
Referenced by QgsDualView::attributeDeleted().
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 213 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.
Definition at line 240 of file qgsfeature.cpp.
References QgsFields::at(), QgsFields::count(), mFields, and QgsField::name().
Referenced by attribute(), deleteAttribute(), and setAttribute().
|
inline |
Get associated field map.
may be NULL
Definition at line 230 of file qgsfeature.h.
Referenced by QgsPalLabeling::registerDiagramFeature(), and setFields().
QgsGeometry * QgsFeature::geometry | ( | ) | const |
Get the geometry object associated with this feature.
Definition at line 113 of file qgsfeature.cpp.
References mGeometry.
Referenced by QgsFeatureRequest::acceptFeature(), QgsVectorLayerImport::addFeature(), QgsVectorLayerEditUtils::addPart(), QgsVectorLayerEditUtils::addRing(), QgsPointSample::addSamplePoints(), QgsGeometry::avoidIntersections(), QgsVectorLayer::boundingBoxOfSelected(), QgsGeometryAnalyzer::bufferFeature(), QgsInterpolator::cacheBaseData(), QgsGml::calculateExtentFromFeatures(), QgsZonalStatistics::calculateStatistics(), QgsGeometryAnalyzer::centroidFeature(), QgsAtlasComposition::computeExtent(), QgsGeometryAnalyzer::convexFeature(), QgsPointDisplacementRenderer::createDisplacementGroups(), QgsVectorFileWriter::createFeature(), QgsTransectSample::createSample(), QgsGeometryAnalyzer::dissolveFeature(), QgsVectorLayer::drawRendererV2(), QgsVectorLayer::drawRendererV2Levels(), QgsGeometryAnalyzer::eventLayer(), QgsVectorFileWriter::exportFeaturesSymbolLevels(), QgsVectorLayer::extent(), fcnGeomArea(), fcnGeometry(), fcnGeomLength(), fcnGeomPerimeter(), QgsMapToolIdentify::featureDerivedAttributes(), QgsSpatialIndex::featureInfo(), QgsVectorLayerImport::importLayer(), QgsHighlight::init(), QgsAttributeDialog::init(), QgsTINInterpolator::insertData(), QgsOverlayAnalyzer::intersectFeature(), QgsLabel::labelPoint(), QgsAbstractFeatureIterator::nextFeature(), QgsHighlight::paint(), QgsAtlasComposition::prepareForFeature(), QgsVectorLayerUndoCommandAddFeature::redo(), QgsPalLabeling::registerDiagramFeature(), QgsPalLayerSettings::registerFeature(), QgsVectorLayer::removePolygonIntersections(), QgsPointDisplacementRenderer::renderFeature(), QgsFeatureRendererV2::renderFeatureWithSymbol(), QgsAtlasComposition::setCoverageLayer(), QgsAbstractFeatureIterator::simplify(), QgsGeometryAnalyzer::simplifyFeature(), QgsVectorLayer::snapWithContext(), QgsVectorLayerEditUtils::splitParts(), QgsVectorLayerEditUtils::translateFeature(), QgsVectorLayerUndoCommandAddFeature::undo(), QgsVectorLayerUndoCommandChangeGeometry::undo(), QgsVectorLayer::updateFeature(), QgsHighlight::updateRect(), QgsVectorLayerFeatureIterator::useAddedFeature(), QgsVectorLayerFeatureIterator::useChangedAttributeFeature(), and QgsVectorFileWriter::writeAsVectorFormat().
QgsGeometry * QgsFeature::geometryAndOwnership | ( | ) |
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.
Referenced by QgsTransectSample::createSample(), and QgsTransectSample::findBaselineGeometry().
QgsFeatureId QgsFeature::id | ( | ) | const |
Get the feature id for this feature.
Definition at line 101 of file qgsfeature.cpp.
References mFid.
Referenced by QgsFeatureRequest::acceptFeature(), QgsVectorLayerEditUtils::addRing(), QgsPointSample::addSamplePoints(), QgsVectorLayer::allFeatureIds(), QgsDualView::attributeAdded(), QgsGeometry::avoidIntersections(), QgsVectorLayer::boundingBoxOfSelected(), QgsVectorLayerCache::cacheFeature(), QgsZonalStatistics::calculateStatistics(), QgsVectorLayerEditBuffer::commitChanges(), QgsOfflineEditing::copyVectorLayer(), QgsPointDisplacementRenderer::createDisplacementGroups(), QgsVectorFileWriter::createFeature(), QgsFeatureListModel::data(), QgsAttributeTableModel::data(), QgsVectorLayer::drawRendererV2(), QgsVectorLayer::drawRendererV2Levels(), QgsGml::endElement(), QgsGeometryAnalyzer::eventLayer(), fcnFeatureId(), QgsAttributeTableModel::featureAdded(), QgsDualView::featureDeleted(), QgsSpatialIndex::featureInfo(), QgsVectorLayerFeatureIterator::fetchFeature(), QgsCachedFeatureWriterIterator::fetchFeature(), QgsVectorLayerFeatureIterator::fetchNextChangedAttributeFeature(), QgsAttributeTableFilterModel::generateListOfVisibleFeatures(), QgsVectorLayerImport::importLayer(), QgsAttributeDialog::init(), QgsVectorLayer::invertSelectionInRectangle(), QgsAttributeTableModel::loadLayer(), QgsAbstractFeatureIterator::nextFeatureFilterFids(), QgsExpressionSelectionDialog::on_mActionAddToSelection_triggered(), QgsExpressionSelectionDialog::on_mActionRemoveFromSelection_triggered(), QgsExpressionSelectionDialog::on_mActionSelect_triggered(), QgsExpressionSelectionDialog::on_mActionSelectInstersect_triggered(), QgsDualView::on_mFeatureList_currentEditSelectionChanged(), QgsAttributeTableModel::prefetchColumnData(), QgsAtlasComposition::prepareForFeature(), QgsVectorLayerUndoCommandDeleteAttribute::QgsVectorLayerUndoCommandDeleteAttribute(), QgsVectorLayerUndoCommandAddFeature::redo(), QgsPalLabeling::registerDiagramFeature(), QgsPalLayerSettings::registerFeature(), QgsDualView::reloadAttribute(), QgsVectorLayer::removePolygonIntersections(), QgsPointDisplacementRenderer::renderFeature(), QgsFeatureRendererV2::renderFeatureWithSymbol(), QgsDualView::saveEditChanges(), QgsVectorLayer::select(), QgsAtlasComposition::setCoverageLayer(), QgsHtmlAnnotationItem::setFeatureForMapPosition(), QgsFormAnnotationItem::setFeatureForMapPosition(), setFeatureId(), QgsVectorLayer::snapWithContext(), QgsVectorLayerEditUtils::splitParts(), QgsVectorLayerUndoCommandAddFeature::undo(), QgsVectorLayerUndoCommandDeleteFeature::undo(), QgsVectorLayerUndoCommandDeleteAttribute::undo(), QgsVectorLayerFeatureIterator::updateChangedAttributes(), QgsVectorLayerEditBuffer::updateChangedAttributes(), QgsVectorLayer::updateFeature(), QgsVectorLayerFeatureIterator::updateFeatureGeometry(), QgsVectorLayerEditBuffer::updateFeatureGeometry(), QgsAtlasComposition::updateFeatures(), QgsOfflineEditing::updateFidLookup(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorFileWriter::writeAsVectorFormat().
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 182 of file qgsfeature.cpp.
References mAttributes.
Referenced by QgsVectorLayerImport::addFeature(), QgsAttributeTableModel::feature(), QgsVectorLayerImport::importLayer(), QgsFeature(), setFields(), 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 172 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 | ( | 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 191 of file qgsfeature.cpp.
References QgsMessageLog::logMessage(), mAttributes, tr, and QgsMessageLog::WARNING.
Referenced by QgsAttributeDialog::accept(), QgsVectorLayerImport::addFeature(), QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesCached(), QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect(), QgsPointSample::addSamplePoints(), QgsDualView::attributeAdded(), QgsTransectSample::createSample(), QgsGml::endElement(), QgsAttributeTableModel::feature(), QgsVectorLayerCache::onAttributeValueChanged(), QgsDualView::reloadAttribute(), and QgsVectorLayerUndoCommandDeleteAttribute::undo().
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 203 of file qgsfeature.cpp.
References fieldNameIndex(), and mAttributes.
|
inline |
Definition at line 145 of file qgsfeature.h.
Referenced by QgsOfflineEditing::applyFeaturesAdded(), QgsGeometryAnalyzer::bufferFeature(), QgsGeometryAnalyzer::centroidFeature(), QgsGeometryAnalyzer::convexHull(), QgsOfflineEditing::copyVectorLayer(), QgsGeometryAnalyzer::dissolve(), QgsGeometryAnalyzer::extent(), QgsPalGeometry::feature(), QgsOverlayAnalyzer::intersectFeature(), QgsGeometryAnalyzer::simplifyFeature(), QgsVectorLayerEditUtils::splitFeatures(), QgsGml::startElement(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorLayerFeatureIterator::useChangedAttributeFeature().
void QgsFeature::setFeatureId | ( | QgsFeatureId | id | ) |
Set the feature id for this feature.
Set the feature id.
id | Feature id |
Definition at line 129 of file qgsfeature.cpp.
Referenced by QgsPalGeometry::feature(), QgsAttributeTableModel::feature(), QgsAttributeTableModel::QgsAttributeTableModel(), QgsVectorLayerUndoCommandAddFeature::QgsVectorLayerUndoCommandAddFeature(), QgsAttributeTableModel::reload(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorLayerFeatureIterator::useChangedAttributeFeature().
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 |
Definition at line 162 of file qgsfeature.cpp.
References QgsFields::count(), fields(), initAttributes(), and mFields.
Referenced by QgsFeatureStore::addFeature(), QgsPalGeometry::feature(), QgsVectorLayerFeatureIterator::fetchFeature(), QgsFeatureStore::setFields(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorLayerFeatureIterator::useChangedAttributeFeature().
void QgsFeature::setGeometry | ( | const QgsGeometry & | geom | ) |
Set this feature's geometry from another QgsGeometry object (deep copy)
Definition at line 135 of file qgsfeature.cpp.
Referenced by QgsGeometryAnalyzer::addEventLayerFeature(), QgsVectorLayerImport::addFeature(), QgsPointSample::addSamplePoints(), QgsGeometryAnalyzer::buffer(), QgsGeometryAnalyzer::bufferFeature(), QgsGeometryAnalyzer::centroidFeature(), QgsGeometryAnalyzer::convexHull(), QgsTransectSample::createSample(), QgsGeometryAnalyzer::dissolve(), QgsGml::endElement(), QgsGeometryAnalyzer::extent(), QgsVectorLayerCache::geometryChanged(), QgsAttributeDialog::init(), QgsOverlayAnalyzer::intersectFeature(), operator=(), QgsFeature(), setGeometryAndOwnership(), QgsGeometryAnalyzer::simplifyFeature(), QgsVectorLayerEditUtils::splitFeatures(), QgsVectorLayerFeatureIterator::updateFeatureGeometry(), QgsVectorLayerEditBuffer::updateFeatureGeometry(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorLayerFeatureIterator::useChangedAttributeFeature().
void QgsFeature::setGeometry | ( | QgsGeometry * | geom | ) |
Set this feature's geometry (takes geometry ownership)
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().
void QgsFeature::setValid | ( | bool | validity | ) |
Set the validity of the feature.
Definition at line 177 of file qgsfeature.cpp.
References mValid.
Referenced by QgsGml::endElement(), QgsPalGeometry::feature(), QgsVectorLayerFeatureIterator::fetchFeature(), QgsVectorLayerFeatureIterator::useAddedFeature(), and QgsVectorLayerFeatureIterator::useChangedAttributeFeature().
|
private |
attributes accessed by field index
Definition at line 295 of file qgsfeature.h.
Referenced by attribute(), deleteAttribute(), initAttributes(), operator=(), and setAttribute().
|
private |
feature id
Definition at line 292 of file qgsfeature.h.
Referenced by id(), operator=(), and setFeatureId().
|
private |
Optional field map for name-based attribute lookups.
Definition at line 312 of file qgsfeature.h.
Referenced by fieldNameIndex(), operator=(), and setFields().
|
private |
pointer to geometry in binary WKB format
This is usually set by a call to OGRGeometry::exportToWkb()
Definition at line 301 of file qgsfeature.h.
Referenced by geometry(), geometryAndOwnership(), operator=(), QgsFeature(), setGeometry(), and ~QgsFeature().
|
private |
Indicator if the mGeometry is owned by this QgsFeature.
If so, this QgsFeature takes responsibility for the mGeometry's destruction.
Definition at line 306 of file qgsfeature.h.
Referenced by geometryAndOwnership(), operator=(), setGeometry(), and ~QgsFeature().
|
private |
Flag to indicate if this feature is valid.
Definition at line 309 of file qgsfeature.h.
Referenced by isValid(), operator=(), and setValid().