Skip to content
Permalink
Browse files
Merge pull request #1353 from leyan/snapping_intersection
Check snapping tolerance of both layers before validating intersection snapping
  • Loading branch information
3nids committed May 16, 2014
2 parents 0f0a094 + d99dd8e commit f194822b9562e32baee8760c331e0abd11291f94
Showing with 21 additions and 2 deletions.
  1. +21 −2 src/gui/qgsmapcanvassnapper.cpp
@@ -304,8 +304,27 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
QgsGeometry* intersectionPoint = lineA->intersection( lineB );
if ( intersectionPoint->type() == QGis::Point )
{
iSegIt->snappedVertex = intersectionPoint->asPoint();
myResults.append( *iSegIt );
//We have to check the intersection point is inside the tolerance distance for both layers
double toleranceA, toleranceB;
for ( int i = 0 ;i < snapLayers.size();++i )
{
if ( snapLayers[i].mLayer == oSegIt->layer )
{
toleranceA = QgsTolerance::toleranceInMapUnits( snapLayers[i].mTolerance, snapLayers[i].mLayer, mMapCanvas->mapSettings(), snapLayers[i].mUnitType );
}
if ( snapLayers[i].mLayer == iSegIt->layer )
{
toleranceB = QgsTolerance::toleranceInMapUnits( snapLayers[i].mTolerance, snapLayers[i].mLayer, mMapCanvas->mapSettings(), snapLayers[i].mUnitType );
}
}
QgsPoint point = mMapCanvas->getCoordinateTransform()->toMapCoordinates( p );
QgsGeometry* cursorPoint = QgsGeometry::fromPoint( point );
double distance = intersectionPoint->distance( *cursorPoint );
if ( distance < toleranceA && distance < toleranceB )
{
iSegIt->snappedVertex = intersectionPoint->asPoint();
myResults.append( *iSegIt );
}
}
}
}

0 comments on commit f194822

Please sign in to comment.