Skip to content

Commit 2a08dc0

Browse files
committedJan 22, 2015
Simplify tool: support multi-part features
1 parent 0f9e1f7 commit 2a08dc0

File tree

1 file changed

+51
-15
lines changed

1 file changed

+51
-15
lines changed
 

‎src/app/qgsmaptoolsimplify.cpp

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,30 @@ int QgsMapToolSimplify::vertexCount( QgsGeometry* g ) const
121121
{
122122
case QGis::Line:
123123
{
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;
125133
}
126134
case QGis::Polygon:
127135
{
128136
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+
}
131148
return count;
132149
}
133150
default:
@@ -371,12 +388,6 @@ void QgsMapToolSimplify::selectOneFeature( const QPoint& canvasPoint )
371388
if ( minDistanceFeature.isValid() )
372389
{
373390
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-
}
380391
}
381392
}
382393

@@ -459,16 +470,41 @@ bool QgsSimplifyFeature::simplify( QgsFeature& feature, double tolerance, QgsMap
459470
QgsGeometry* g = feature.geometry();
460471
if ( g->type() == QGis::Line )
461472
{
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+
}
464485
return true;
465486
}
466487
else if ( g->type() == QGis::Polygon )
467488
{
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+
}
472508
return true;
473509
}
474510
else

0 commit comments

Comments
 (0)
Please sign in to comment.