26
26
#include " qgsspatialindex.h"
27
27
28
28
// ! record about vertex coordinates and index of anchor to which it is snapped
29
- typedef struct
29
+ struct AnchorPoint
30
30
{
31
31
// ! coordinates of the point
32
32
double x, y;
@@ -38,15 +38,15 @@ typedef struct
38
38
* -2 - this point is an anchor, i.e. do not snap this point (snap others to this point)
39
39
*/
40
40
int anchor;
41
- } AnchorPoint ;
41
+ };
42
42
43
43
44
44
// ! record about anchor being along a segment
45
- typedef struct
45
+ struct AnchorAlongSegment
46
46
{
47
47
int anchor; // !< Index of the anchor point
48
48
double along; // !< Distance of the anchor point along the segment
49
- } AnchorAlongSegment ;
49
+ };
50
50
51
51
52
52
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
56
56
57
57
while ( fi.nextFeature ( f ) )
58
58
{
59
+ if ( feedback->isCanceled () )
60
+ break ;
61
+
59
62
QgsGeometry g = f.geometry ();
60
63
61
64
for ( auto it = g.vertices_begin (); it != g.vertices_end (); ++it )
@@ -310,9 +313,14 @@ int QgsGeometrySnapperSingleSource::run( const QgsFeatureSource &source, QgsFeat
310
313
311
314
QgsSpatialIndex index;
312
315
QVector<AnchorPoint> pnts;
313
- QgsFeatureIterator fi = source.getFeatures ();
316
+ QgsFeatureRequest request;
317
+ request.setSubsetOfAttributes ( QgsAttributeList () );
318
+ QgsFeatureIterator fi = source.getFeatures ( request );
314
319
buildSnapIndex ( fi, index, pnts, feedback, count, totalCount );
315
320
321
+ if ( feedback->isCanceled () )
322
+ return 0 ;
323
+
316
324
// step 2: go through all registered points and if not yet marked mark it as anchor and
317
325
// assign this anchor to all not yet marked points in threshold
318
326
@@ -328,6 +336,9 @@ int QgsGeometrySnapperSingleSource::run( const QgsFeatureSource &source, QgsFeat
328
336
fi = source.getFeatures ();
329
337
while ( fi.nextFeature ( f ) )
330
338
{
339
+ if ( feedback->isCanceled () )
340
+ break ;
341
+
331
342
QgsGeometry geom = f.geometry ();
332
343
if ( snapGeometry ( geom.get (), index, pnts, thresh ) )
333
344
{
0 commit comments