Skip to content

Commit

Permalink
Improvements from review
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 14, 2018
1 parent c5e431c commit 2b55858
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/analysis/vector/qgsgeometrysnappersinglesource.cpp
Expand Up @@ -26,7 +26,7 @@
#include "qgsspatialindex.h"

//! record about vertex coordinates and index of anchor to which it is snapped
typedef struct
struct AnchorPoint
{
//! coordinates of the point
double x, y;
Expand All @@ -38,15 +38,15 @@ typedef struct
* -2 - this point is an anchor, i.e. do not snap this point (snap others to this point)
*/
int anchor;
} AnchorPoint;
};


//! record about anchor being along a segment
typedef struct
struct AnchorAlongSegment
{
int anchor; //!< Index of the anchor point
double along; //!< Distance of the anchor point along the segment
} AnchorAlongSegment;
};


static void buildSnapIndex( QgsFeatureIterator &fi, QgsSpatialIndex &index, QVector<AnchorPoint> &pnts, QgsFeedback *feedback, int &count, int totalCount )
Expand All @@ -56,6 +56,9 @@ static void buildSnapIndex( QgsFeatureIterator &fi, QgsSpatialIndex &index, QVec

while ( fi.nextFeature( f ) )
{
if ( feedback->isCanceled() )
break;

QgsGeometry g = f.geometry();

for ( auto it = g.vertices_begin(); it != g.vertices_end(); ++it )
Expand Down Expand Up @@ -310,9 +313,14 @@ int QgsGeometrySnapperSingleSource::run( const QgsFeatureSource &source, QgsFeat

QgsSpatialIndex index;
QVector<AnchorPoint> pnts;
QgsFeatureIterator fi = source.getFeatures();
QgsFeatureRequest request;
request.setSubsetOfAttributes( QgsAttributeList() );
QgsFeatureIterator fi = source.getFeatures( request );
buildSnapIndex( fi, index, pnts, feedback, count, totalCount );

if ( feedback->isCanceled() )
return 0;

// step 2: go through all registered points and if not yet marked mark it as anchor and
// assign this anchor to all not yet marked points in threshold

Expand All @@ -328,6 +336,9 @@ int QgsGeometrySnapperSingleSource::run( const QgsFeatureSource &source, QgsFeat
fi = source.getFeatures();
while ( fi.nextFeature( f ) )
{
if ( feedback->isCanceled() )
break;

QgsGeometry geom = f.geometry();
if ( snapGeometry( geom.get(), index, pnts, thresh ) )
{
Expand Down

0 comments on commit 2b55858

Please sign in to comment.