Skip to content
Permalink
Browse files

Avoid extra vertices added when digitizing due to roundtrip reproject…

…ion variance
  • Loading branch information
nirvn committed Oct 15, 2020
1 parent e951aea commit 52416ddca916327f94a77e4917b1ac4a23bf5a1b
Showing with 22 additions and 7 deletions.
  1. +19 −7 src/gui/qgsmaptoolcapture.cpp
  2. +3 −0 src/gui/qgsmaptoolcapture.h
@@ -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;
}

@@ -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()
@@ -395,7 +398,7 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
if ( mCaptureCurve.numPoints() > 0 )
{
QgsPoint mapPt = lastCapturedMapPoint();
const QgsPoint mapPt = lastCapturedMapPoint();

if ( mTempRubberBand )
{
@@ -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 ) );

@@ -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 )
@@ -601,7 +608,7 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
}

mTempRubberBand->addPoint( mapPoint );

mCaptureLastPoint = mapPoint;
}
else
{
@@ -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 );
}
@@ -763,6 +772,9 @@ void QgsMapToolCapture::stopCapturing()
mGeomErrorMarkers.clear();
mGeomErrors.clear();

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

mTracingStartPoint = QgsPointXY();

mCapturing = false;
@@ -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;

0 comments on commit 52416dd

Please sign in to comment.
You can’t perform that action at this time.