Skip to content

Commit

Permalink
add QgsVectorLayer::getGeometry(fid) (#8174)
Browse files Browse the repository at this point in the history
* add QgsVectorLayer::getGeometry(fid)

* update docs to say geom is invalid
  • Loading branch information
3nids committed Oct 15, 2018
1 parent d5e57d3 commit 574c672
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Expand Up @@ -1054,6 +1054,12 @@ Query the layer for features matching a given expression.
%Docstring
Query the layer for the feature with the given id.
If there is no such feature, the returned feature will be invalid.
%End

QgsGeometry getGeometry( QgsFeatureId fid ) const;
%Docstring
Query the layer for the geometry at the given id.
If there is no such feature, the returned geometry will be invalid.
%End

QgsFeatureIterator getFeatures( const QgsFeatureIds &fids );
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -941,6 +941,16 @@ QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest &request
return QgsFeatureIterator( new QgsVectorLayerFeatureIterator( new QgsVectorLayerFeatureSource( this ), true, request ) );
}

QgsGeometry QgsVectorLayer::getGeometry( QgsFeatureId fid ) const
{
QgsFeature feature;
getFeatures( QgsFeatureRequest( fid ).setFlags( QgsFeatureRequest::SubsetOfAttributes ) ).nextFeature( feature );
if ( feature.isValid() )
return feature.geometry();
else
return QgsGeometry();
}

bool QgsVectorLayer::addFeature( QgsFeature &feature, Flags )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1038,6 +1038,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
return feature;
}

/**
* Query the layer for the geometry at the given id.
* If there is no such feature, the returned geometry will be invalid.
*/
QgsGeometry getGeometry( QgsFeatureId fid ) const;

/**
* Query the layer for the features with the given ids.
*/
Expand Down

0 comments on commit 574c672

Please sign in to comment.