@@ -362,7 +362,7 @@ void Layer::joinConnectedFeatures()
362
362
QLinkedList<FeaturePart*>* parts = mConnectedHashtable .value ( labelText );
363
363
364
364
// go one-by-one part, try to merge
365
- while ( !parts->isEmpty () )
365
+ while ( !parts->isEmpty () && parts-> count () > 1 )
366
366
{
367
367
// part we'll be checking against other in this round
368
368
FeaturePart* partCheck = parts->takeFirst ();
@@ -371,24 +371,29 @@ void Layer::joinConnectedFeatures()
371
371
if ( otherPart )
372
372
{
373
373
// remove partCheck from r-tree
374
- double bmin[2 ], bmax[2 ];
375
- partCheck->getBoundingBox ( bmin, bmax );
376
- mFeatureIndex ->Remove ( bmin, bmax, partCheck );
377
- mFeatureParts .removeOne ( partCheck );
374
+ double checkpartBMin[2 ], checkpartBMax[2 ];
375
+ partCheck->getBoundingBox ( checkpartBMin, checkpartBMax );
378
376
379
- mConnectedFeaturesIds . insert ( partCheck-> featureId (), connectedFeaturesId ) ;
380
- otherPart->getBoundingBox ( bmin, bmax );
377
+ double otherPartBMin[ 2 ], otherPartBMax[ 2 ] ;
378
+ otherPart->getBoundingBox ( otherPartBMin, otherPartBMax );
381
379
382
380
// merge points from partCheck to p->item
383
381
if ( otherPart->mergeWithFeaturePart ( partCheck ) )
384
382
{
383
+ // remove the parts we are joining from the index
384
+ mFeatureIndex ->Remove ( checkpartBMin, checkpartBMax, partCheck );
385
+ mFeatureIndex ->Remove ( otherPartBMin, otherPartBMax, otherPart );
386
+
387
+ // reinsert merged line to r-tree (probably not needed)
388
+ otherPart->getBoundingBox ( otherPartBMin, otherPartBMax );
389
+ mFeatureIndex ->Insert ( otherPartBMin, otherPartBMax, otherPart );
390
+
391
+ mConnectedFeaturesIds .insert ( partCheck->featureId (), connectedFeaturesId );
385
392
mConnectedFeaturesIds .insert ( otherPart->featureId (), connectedFeaturesId );
386
- // reinsert p->item to r-tree (probably not needed)
387
- mFeatureIndex ->Remove ( bmin, bmax, otherPart );
388
- otherPart->getBoundingBox ( bmin, bmax );
389
- mFeatureIndex ->Insert ( bmin, bmax, otherPart );
393
+
394
+ mFeatureParts .removeOne ( partCheck );
395
+ delete partCheck;
390
396
}
391
- delete partCheck;
392
397
}
393
398
}
394
399
0 commit comments