Skip to content
Permalink
Browse files

add QgsVectorLayer::getGeometry(fid) (#8174)

* add QgsVectorLayer::getGeometry(fid)

* update docs to say geom is invalid
  • Loading branch information
3nids committed Oct 15, 2018
1 parent d5e57d3 commit 574c672a1e6a9b50c4adfbf23d639a7f284f5f33
Showing with 22 additions and 0 deletions.
  1. +6 −0 python/core/auto_generated/qgsvectorlayer.sip.in
  2. +10 −0 src/core/qgsvectorlayer.cpp
  3. +6 −0 src/core/qgsvectorlayer.h
@@ -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 );
@@ -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 )
@@ -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.
*/

0 comments on commit 574c672

Please sign in to comment.
You can’t perform that action at this time.