Skip to content
Permalink
Browse files

Use a feature source instead of vector layer for QgsGeometrySnapper

  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent 8a84e13 commit 3601138d2a1ba9b1a00b8f5c736cf28212442869
@@ -33,11 +33,11 @@ class QgsGeometrySnapper : QObject
EndPointToEndPoint,
};

QgsGeometrySnapper( QgsVectorLayer *referenceLayer );
QgsGeometrySnapper( QgsFeatureSource *referenceSource );
%Docstring
Constructor for QgsGeometrySnapper. A reference layer which contains geometries to snap to must be
Constructor for QgsGeometrySnapper. A reference feature source which contains geometries to snap to must be
set. It is assumed that all geometries snapped using this object will have the
same CRS as the reference layer (ie, no reprojection is performed).
same CRS as the reference source (ie, no reprojection is performed).
%End

QgsGeometry snapGeometry( const QgsGeometry &geometry, double snapTolerance, SnapMode mode = PreferNodes ) const;
@@ -459,13 +459,11 @@ QgsSnapIndex::SnapItem *QgsSnapIndex::getSnapItem( const QgsPoint &pos, double t
// QgsGeometrySnapper
//

QgsGeometrySnapper::QgsGeometrySnapper( QgsVectorLayer *referenceLayer )
: mReferenceLayer( referenceLayer )
QgsGeometrySnapper::QgsGeometrySnapper( QgsFeatureSource *referenceSource )
: mReferenceSource( referenceSource )
{
// Build spatial index
QgsFeatureRequest req;
req.setSubsetOfAttributes( QgsAttributeList() );
mIndex = QgsSpatialIndex( mReferenceLayer->getFeatures( req ) );
mIndex = QgsSpatialIndex( *mReferenceSource );
}

QgsFeatureList QgsGeometrySnapper::snapFeatures( const QgsFeatureList &features, double snapTolerance, SnapMode mode )
@@ -496,7 +494,7 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
QgsFeatureRequest refFeatureRequest = QgsFeatureRequest().setFilterFids( refFeatureIds ).setSubsetOfAttributes( QgsAttributeList() );
mReferenceLayerMutex.lock();
QgsFeature refFeature;
QgsFeatureIterator refFeatureIt = mReferenceLayer->getFeatures( refFeatureRequest );
QgsFeatureIterator refFeatureIt = mReferenceSource->getFeatures( refFeatureRequest );

while ( refFeatureIt.nextFeature( refFeature ) )
{
@@ -53,11 +53,11 @@ class ANALYSIS_EXPORT QgsGeometrySnapper : public QObject
};

/**
* Constructor for QgsGeometrySnapper. A reference layer which contains geometries to snap to must be
* Constructor for QgsGeometrySnapper. A reference feature source which contains geometries to snap to must be
* set. It is assumed that all geometries snapped using this object will have the
* same CRS as the reference layer (ie, no reprojection is performed).
* same CRS as the reference source (ie, no reprojection is performed).
*/
QgsGeometrySnapper( QgsVectorLayer *referenceLayer );
QgsGeometrySnapper( QgsFeatureSource *referenceSource );

/**
* Snaps a geometry to the reference layer and returns the result. The geometry must be in the same
@@ -99,7 +99,7 @@ class ANALYSIS_EXPORT QgsGeometrySnapper : public QObject

enum PointFlag { SnappedToRefNode, SnappedToRefSegment, Unsnapped };

QgsVectorLayer *mReferenceLayer = nullptr;
QgsFeatureSource *mReferenceSource = nullptr;
QgsFeatureList mInputFeatures;

QgsSpatialIndex mIndex;
@@ -231,7 +231,7 @@ QgsSpatialIndex::QgsSpatialIndex( const QgsFeatureIterator &fi )

QgsSpatialIndex::QgsSpatialIndex( const QgsFeatureSource &source )
{
d = new QgsSpatialIndexData( source.getFeatures() );
d = new QgsSpatialIndexData( source.getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) ) );
}

QgsSpatialIndex::QgsSpatialIndex( const QgsSpatialIndex &other ) //NOLINT

0 comments on commit 3601138

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