mirror of
https://github.com/qgis/QGIS.git
synced 2025-06-19 00:02:48 -04:00
Use a feature source instead of vector layer for QgsGeometrySnapper
This commit is contained in:
parent
8a84e134cc
commit
3601138d2a
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user