Skip to content
Permalink
Browse files
Avoid re-preparing geos geometry from QgsVectorLayerFeatureIterator
Does so by exposing a referenceGeometryEngine method to
QgsFeatureRequest and copying the engine rather than creating
a new one on each iteration.
  • Loading branch information
strk committed Oct 18, 2021
1 parent ba7cdde commit 27ae2c9516f4b08fd798263750e8f4772f5c80ac
@@ -405,6 +405,7 @@ will use the same CRS as the source layer/provider.
.. versionadded:: 3.22
%End


double distanceWithin() const;
%Docstring
Returns the maximum distance from the :py:func:`~QgsFeatureRequest.referenceGeometry` of fetched
@@ -407,6 +407,16 @@ class CORE_EXPORT QgsFeatureRequest
*/
QgsGeometry referenceGeometry() const { return mReferenceGeometry; }

/**
* Returns the reference geometry engine used for spatial filtering of features.
*
* This is to avoid re-creating the engine.
*
* \see referenceGeometry()
* \since QGIS 3.22
*/
std::shared_ptr< QgsGeometryEngine > referenceGeometryEngine() const SIP_SKIP { return mReferenceGeometryEngine; }

/**
* Returns the maximum distance from the referenceGeometry() of fetched
* features, if spatialFilterType() is Qgis::SpatialFilterType::DistanceWithin.
@@ -151,7 +151,7 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
if ( !mRequest.referenceGeometry().isEmpty() )
{
mDistanceWithinGeom = mRequest.referenceGeometry();
mDistanceWithinEngine.reset( QgsGeometry::createGeometryEngine( mDistanceWithinGeom.constGet() ) );
mDistanceWithinEngine = mRequest.referenceGeometryEngine();
mDistanceWithinEngine->prepareGeometry();
mDistanceWithin = mRequest.distanceWithin();
}
@@ -272,7 +272,7 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera
QgsCoordinateTransform mTransform;

QgsGeometry mDistanceWithinGeom;
std::unique_ptr< QgsGeometryEngine > mDistanceWithinEngine;
std::shared_ptr< QgsGeometryEngine > mDistanceWithinEngine;
double mDistanceWithin = 0;

// only related to editing

0 comments on commit 27ae2c9

Please sign in to comment.