Skip to content
Permalink
Browse files
[optimization][geometry snapper] Cache source geometries
  • Loading branch information
nirvn authored and github-actions committed Apr 27, 2021
1 parent 3213c68 commit 08dd78bef97e6532c87e903f15a64091d617b33e
Showing with 29 additions and 8 deletions.
  1. +28 −7 src/analysis/vector/qgsgeometrysnapper.cpp
  2. +1 −1 src/analysis/vector/qgsgeometrysnapper.h
@@ -488,16 +488,37 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
QgsFeatureIds refFeatureIds = qgis::listToSet( mIndex.intersects( searchBounds ) );
mIndexMutex.unlock();

QgsFeatureRequest refFeatureRequest = QgsFeatureRequest().setFilterFids( refFeatureIds ).setNoAttributes();
mReferenceLayerMutex.lock();
QgsFeature refFeature;
QgsFeatureIterator refFeatureIt = mReferenceSource->getFeatures( refFeatureRequest );
if ( refFeatureIds.isEmpty() )
return QgsGeometry( geometry );

while ( refFeatureIt.nextFeature( refFeature ) )
refGeometries.reserve( refFeatureIds.size() );
QgsFeatureIds missingFeatureIds;
const QgsFeatureIds cachedIds = qgis::listToSet( mCachedReferenceGeometries.keys() );
for ( QgsFeatureId id : refFeatureIds )
{
refGeometries.append( refFeature.geometry() );
if ( cachedIds.contains( id ) )
{
refGeometries.append( mCachedReferenceGeometries[id] );
}
else
{
missingFeatureIds << id;
}
}

if ( missingFeatureIds.size() > 0 )
{

mReferenceLayerMutex.lock();
QgsFeatureRequest refFeatureRequest = QgsFeatureRequest().setFilterFids( missingFeatureIds ).setNoAttributes();
QgsFeatureIterator refFeatureIt = mReferenceSource->getFeatures( refFeatureRequest );
QgsFeature refFeature;
while ( refFeatureIt.nextFeature( refFeature ) )
{
refGeometries.append( refFeature.geometry() );
}
mReferenceLayerMutex.unlock();
}
mReferenceLayerMutex.unlock();

return snapGeometry( geometry, snapTolerance, refGeometries, mode );
}
@@ -102,7 +102,7 @@ class ANALYSIS_EXPORT QgsGeometrySnapper : public QObject
enum PointFlag { SnappedToRefNode, SnappedToRefSegment, Unsnapped };

QgsFeatureSource *mReferenceSource = nullptr;
QgsFeatureList mInputFeatures;
QHash<QgsFeatureId, QgsGeometry> mCachedReferenceGeometries;

QgsSpatialIndex mIndex;
mutable QMutex mIndexMutex;

0 comments on commit 08dd78b

Please sign in to comment.