Skip to content

Commit

Permalink
Avoid extra vertices added when digitizing due to roundtrip reproject…
Browse files Browse the repository at this point in the history
…ion variance
  • Loading branch information
nirvn committed Oct 15, 2020
1 parent e951aea commit 52416dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -293,6 +293,11 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
mSnappingMatches.append( QgsPointLocator::Match() );

tracer->reportError( QgsTracer::ErrNone, true ); // clear messagebar if there was any error

// adjust last captured point
const QgsPoint lastPt = mCaptureCurve.endPoint();
mCaptureLastPoint = toMapCoordinates( qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ), lastPt );

return true;
}

Expand All @@ -316,14 +321,12 @@ QgsMapToolCaptureRubberBand *QgsMapToolCapture::createCurveRubberBand() const

QgsPoint QgsMapToolCapture::firstCapturedMapPoint()
{
QgsPoint firstPt = mCaptureCurve.startPoint();
return toMapCoordinates( qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ), firstPt ) ;
return mCaptureFirstPoint;
}

QgsPoint QgsMapToolCapture::lastCapturedMapPoint()
{
QgsPoint firstPt = mCaptureCurve.endPoint();
return toMapCoordinates( qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ), firstPt ) ;
return mCaptureLastPoint;
}

void QgsMapToolCapture::resetRubberBand()
Expand Down Expand Up @@ -395,7 +398,7 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
if ( mCaptureCurve.numPoints() > 0 )
{
QgsPoint mapPt = lastCapturedMapPoint();
const QgsPoint mapPt = lastCapturedMapPoint();

if ( mTempRubberBand )
{
Expand Down Expand Up @@ -540,6 +543,11 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
}
else
{
if ( mCaptureFirstPoint.isEmpty() )
{
mCaptureFirstPoint = mapPoint;
}

if ( !mRubberBand )
mRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry ) );

Expand Down Expand Up @@ -584,7 +592,6 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
mSnappingMatches.append( match );
}
}

mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, mDigitizingType, firstCapturedMapPoint() );
}
else if ( mCaptureCurve.numPoints() == 0 )
Expand All @@ -601,7 +608,7 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
}

mTempRubberBand->addPoint( mapPoint );

mCaptureLastPoint = mapPoint;
}
else
{
Expand Down Expand Up @@ -716,6 +723,8 @@ void QgsMapToolCapture::undo()

if ( mCaptureCurve.numPoints() > 0 )
{
const QgsPoint lastPt = mCaptureCurve.endPoint();
mCaptureLastPoint = toMapCoordinates( qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ), lastPt );
mTempRubberBand->addPoint( lastCapturedMapPoint() );
mTempRubberBand->movePoint( lastPoint );
}
Expand Down Expand Up @@ -763,6 +772,9 @@ void QgsMapToolCapture::stopCapturing()
mGeomErrorMarkers.clear();
mGeomErrors.clear();

mCaptureFirstPoint = QgsPoint();
mCaptureLastPoint = QgsPoint();

mTracingStartPoint = QgsPointXY();

mCapturing = false;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsmaptoolcapture.h
Expand Up @@ -394,6 +394,9 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
//! Flag to indicate a map canvas capture operation is taking place
bool mCapturing = false;

QgsPoint mCaptureFirstPoint;
QgsPoint mCaptureLastPoint;

//! Rubber band for polylines and polygons
QObjectUniquePtr<QgsRubberBand> mRubberBand;

Expand Down

0 comments on commit 52416dd

Please sign in to comment.