Skip to content

Commit 2b55858

Browse files
committed
Improvements from review
1 parent c5e431c commit 2b55858

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/analysis/vector/qgsgeometrysnappersinglesource.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "qgsspatialindex.h"
2727

2828
//! record about vertex coordinates and index of anchor to which it is snapped
29-
typedef struct
29+
struct AnchorPoint
3030
{
3131
//! coordinates of the point
3232
double x, y;
@@ -38,15 +38,15 @@ typedef struct
3838
* -2 - this point is an anchor, i.e. do not snap this point (snap others to this point)
3939
*/
4040
int anchor;
41-
} AnchorPoint;
41+
};
4242

4343

4444
//! record about anchor being along a segment
45-
typedef struct
45+
struct AnchorAlongSegment
4646
{
4747
int anchor; //!< Index of the anchor point
4848
double along; //!< Distance of the anchor point along the segment
49-
} AnchorAlongSegment;
49+
};
5050

5151

5252
static void buildSnapIndex( QgsFeatureIterator &fi, QgsSpatialIndex &index, QVector<AnchorPoint> &pnts, QgsFeedback *feedback, int &count, int totalCount )
@@ -56,6 +56,9 @@ static void buildSnapIndex( QgsFeatureIterator &fi, QgsSpatialIndex &index, QVec
5656

5757
while ( fi.nextFeature( f ) )
5858
{
59+
if ( feedback->isCanceled() )
60+
break;
61+
5962
QgsGeometry g = f.geometry();
6063

6164
for ( auto it = g.vertices_begin(); it != g.vertices_end(); ++it )
@@ -310,9 +313,14 @@ int QgsGeometrySnapperSingleSource::run( const QgsFeatureSource &source, QgsFeat
310313

311314
QgsSpatialIndex index;
312315
QVector<AnchorPoint> pnts;
313-
QgsFeatureIterator fi = source.getFeatures();
316+
QgsFeatureRequest request;
317+
request.setSubsetOfAttributes( QgsAttributeList() );
318+
QgsFeatureIterator fi = source.getFeatures( request );
314319
buildSnapIndex( fi, index, pnts, feedback, count, totalCount );
315320

321+
if ( feedback->isCanceled() )
322+
return 0;
323+
316324
// step 2: go through all registered points and if not yet marked mark it as anchor and
317325
// assign this anchor to all not yet marked points in threshold
318326

@@ -328,6 +336,9 @@ int QgsGeometrySnapperSingleSource::run( const QgsFeatureSource &source, QgsFeat
328336
fi = source.getFeatures();
329337
while ( fi.nextFeature( f ) )
330338
{
339+
if ( feedback->isCanceled() )
340+
break;
341+
331342
QgsGeometry geom = f.geometry();
332343
if ( snapGeometry( geom.get(), index, pnts, thresh ) )
333344
{

0 commit comments

Comments
 (0)