Skip to content

Commit ae44e55

Browse files
committedJan 22, 2015
Simplify tool: support for on-the-fly reprojection
1 parent 180ede3 commit ae44e55

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed
 

‎src/app/qgsmaptoolsimplify.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,15 @@ void QgsMapToolSimplify::updateSimplificationPreview()
7676
{
7777
// create a copy of selected feature and do the simplification
7878
QgsFeature f = mSelectedFeature;
79-
if ( mTolerance > 0 )
80-
{
81-
if ( mSelectedFeature.geometry()->type() == QGis::Line )
82-
{
83-
QgsSimplifyFeature::simplifyLine( f, mTolerance );
84-
}
85-
else
86-
{
87-
QgsSimplifyFeature::simplifyPolygon( f, mTolerance );
88-
}
89-
}
90-
mRubberBand->setToGeometry( f.geometry(), 0 );
79+
QgsSimplifyFeature::simplify( f, mTolerance );
80+
mRubberBand->setToGeometry( f.geometry(), currentVectorLayer() );
9181
}
9282

9383

9484
void QgsMapToolSimplify::storeSimplified()
9585
{
9686
QgsVectorLayer * vlayer = currentVectorLayer();
97-
if ( mSelectedFeature.geometry()->type() == QGis::Line )
98-
{
99-
QgsSimplifyFeature::simplifyLine( mSelectedFeature, mTolerance );
100-
}
101-
else
102-
{
103-
QgsSimplifyFeature::simplifyPolygon( mSelectedFeature, mTolerance );
104-
}
87+
QgsSimplifyFeature::simplify( mSelectedFeature, mTolerance );
10588

10689
vlayer->beginEditCommand( tr( "Geometry simplified" ) );
10790
vlayer->changeGeometry( mSelectedFeature.id(), mSelectedFeature.geometry() );
@@ -223,7 +206,7 @@ void QgsMapToolSimplify::canvasPressEvent( QMouseEvent * e )
223206
return;
224207
}
225208

226-
QgsPoint layerCoords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
209+
QgsPoint layerCoords = toLayerCoordinates( vlayer, e->pos() );
227210

228211
double r = QgsTolerance::vertexSearchRadius( vlayer, mCanvas->mapSettings() );
229212
QgsRectangle selectRect = QgsRectangle( layerCoords.x() - r, layerCoords.y() - r,
@@ -259,10 +242,10 @@ void QgsMapToolSimplify::canvasPressEvent( QMouseEvent * e )
259242
}
260243

261244
mRubberBand = new QgsRubberBand( mCanvas );
262-
mRubberBand->setToGeometry( mSelectedFeature.geometry(), 0 );
263245
mRubberBand->setColor( QColor( 255, 0, 0, 65 ) );
264246
mRubberBand->setWidth( 2 );
265247
mRubberBand->show();
248+
updateSimplificationPreview();
266249

267250
// show dialog as a non-modal window
268251
mSimplifyDialog->show();
@@ -309,6 +292,21 @@ QVector<QgsPoint> QgsMapToolSimplify::getPointList( QgsFeature& f )
309292
////////////////////////////////////////////////////////////////////////////
310293

311294

295+
bool QgsSimplifyFeature::simplify( QgsFeature& feature, double tolerance )
296+
{
297+
if ( tolerance <= 0 )
298+
return false;
299+
300+
if ( feature.geometry()->type() == QGis::Line )
301+
{
302+
return QgsSimplifyFeature::simplifyLine( feature, tolerance );
303+
}
304+
else
305+
{
306+
return QgsSimplifyFeature::simplifyPolygon( feature, tolerance );
307+
}
308+
}
309+
312310
bool QgsSimplifyFeature::simplifyLine( QgsFeature& lineFeature, double tolerance )
313311
{
314312
QgsGeometry* line = lineFeature.geometry();
@@ -331,7 +329,6 @@ bool QgsSimplifyFeature::simplifyPolygon( QgsFeature& polygonFeature, double tol
331329
}
332330

333331
QVector<QgsPoint> resultPoints = simplifyPoints( polygon->asPolygon()[0], tolerance );
334-
//resultPoints.push_back(resultPoints[0]);
335332
QVector<QgsPolyline> poly;
336333
poly.append( resultPoints );
337334
polygonFeature.setGeometry( QgsGeometry::fromPolygon( poly ) );

‎src/app/qgsmaptoolsimplify.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ class APP_EXPORT QgsSimplifyFeature
103103
};
104104

105105
public:
106+
/** simplify line/polygon feature with specified tolerance. Returns true on success */
107+
static bool simplify( QgsFeature& feature, double tolerance );
108+
109+
protected:
106110
/** simplify line feature with specified tolerance. Returns true on success */
107111
static bool simplifyLine( QgsFeature &lineFeature, double tolerance );
108112
/** simplify polygon feature with specified tolerance. Returns true on success */

0 commit comments

Comments
 (0)
Please sign in to comment.