Use a feature source instead of vector layer for QgsGeometrySnapper

This commit is contained in:
Nyall Dawson 2017-07-01 13:56:34 +10:00
parent 8a84e134cc
commit 3601138d2a
4 changed files with 12 additions and 14 deletions

View File

@ -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;

View File

@ -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 ) )
{

View File

@ -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;

View File

@ -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