@@ -121,13 +121,30 @@ int QgsMapToolSimplify::vertexCount( QgsGeometry* g ) const
121
121
{
122
122
case QGis::Line:
123
123
{
124
- return g->asPolyline ().count ();
124
+ int count = 0 ;
125
+ if ( g->isMultipart () )
126
+ {
127
+ foreach ( const QgsPolyline& polyline, g->asMultiPolyline () )
128
+ count += polyline.count ();
129
+ }
130
+ else
131
+ count = g->asPolyline ().count ();
132
+ return count;
125
133
}
126
134
case QGis::Polygon:
127
135
{
128
136
int count = 0 ;
129
- foreach ( const QgsPolyline& ring, g->asPolygon () )
130
- count += ring.count ();
137
+ if ( g->isMultipart () )
138
+ {
139
+ foreach ( const QgsPolygon& polygon, g->asMultiPolygon () )
140
+ foreach ( const QgsPolyline& ring, polygon )
141
+ count += ring.count ();
142
+ }
143
+ else
144
+ {
145
+ foreach ( const QgsPolyline& ring, g->asPolygon () )
146
+ count += ring.count ();
147
+ }
131
148
return count;
132
149
}
133
150
default :
@@ -371,12 +388,6 @@ void QgsMapToolSimplify::selectOneFeature( const QPoint& canvasPoint )
371
388
if ( minDistanceFeature.isValid () )
372
389
{
373
390
mSelectedFeatures << minDistanceFeature;
374
-
375
- if ( minDistanceFeature.geometry ()->isMultipart () )
376
- {
377
- emit messageEmitted ( tr ( " Multipart features are not supported for simplification." ), QgsMessageBar::CRITICAL );
378
- return ;
379
- }
380
391
}
381
392
}
382
393
@@ -459,16 +470,41 @@ bool QgsSimplifyFeature::simplify( QgsFeature& feature, double tolerance, QgsMap
459
470
QgsGeometry* g = feature.geometry ();
460
471
if ( g->type () == QGis::Line )
461
472
{
462
- QVector<QgsPoint> resultPoints = simplifyPoints ( g->asPolyline (), tolerance, units, ctLayerToMap );
463
- feature.setGeometry ( QgsGeometry::fromPolyline ( resultPoints ) );
473
+ if ( g->isMultipart () )
474
+ {
475
+ QgsMultiPolyline poly;
476
+ foreach ( const QgsPolyline& ring, g->asMultiPolyline () )
477
+ poly << simplifyPoints ( ring, tolerance, units, ctLayerToMap );
478
+ feature.setGeometry ( QgsGeometry::fromMultiPolyline ( poly ) );
479
+ }
480
+ else
481
+ {
482
+ QgsPolyline resultPoints = simplifyPoints ( g->asPolyline (), tolerance, units, ctLayerToMap );
483
+ feature.setGeometry ( QgsGeometry::fromPolyline ( resultPoints ) );
484
+ }
464
485
return true ;
465
486
}
466
487
else if ( g->type () == QGis::Polygon )
467
488
{
468
- QVector<QgsPolyline> poly;
469
- foreach ( const QgsPolyline& ring, g->asPolygon () )
470
- poly << simplifyPoints ( ring, tolerance, units, ctLayerToMap );
471
- feature.setGeometry ( QgsGeometry::fromPolygon ( poly ) );
489
+ if ( g->isMultipart () )
490
+ {
491
+ QgsMultiPolygon mpoly;
492
+ foreach ( const QgsPolygon& polygon, g->asMultiPolygon () )
493
+ {
494
+ QgsPolygon poly;
495
+ foreach ( const QgsPolyline& ring, polygon )
496
+ poly << simplifyPoints ( ring, tolerance, units, ctLayerToMap );
497
+ mpoly << poly;
498
+ }
499
+ feature.setGeometry ( QgsGeometry::fromMultiPolygon ( mpoly ) );
500
+ }
501
+ else
502
+ {
503
+ QgsPolygon poly;
504
+ foreach ( const QgsPolyline& ring, g->asPolygon () )
505
+ poly << simplifyPoints ( ring, tolerance, units, ctLayerToMap );
506
+ feature.setGeometry ( QgsGeometry::fromPolygon ( poly ) );
507
+ }
472
508
return true ;
473
509
}
474
510
else
0 commit comments