mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-04 00:06:46 -05:00
Implement distance within search for vector layer iterator
This commit is contained in:
parent
8ee93ef2df
commit
f69ff2706a
@ -158,6 +158,7 @@ Setup the simplification of geometries to fetch using the specified simplify met
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
QgsVectorLayerFeatureIterator( const QgsVectorLayerFeatureIterator &rhs );
|
||||
};
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgsexception.h"
|
||||
#include "qgsexpressioncontextutils.h"
|
||||
#include "qgsgeometryengine.h"
|
||||
|
||||
#include <QThreadStorage>
|
||||
#include <QStack>
|
||||
@ -137,6 +138,26 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// prepare spatial filter geometries for optimal speed
|
||||
switch ( mRequest.spatialFilterType() )
|
||||
{
|
||||
case Qgis::SpatialFilterType::NoFilter:
|
||||
case Qgis::SpatialFilterType::BoundingBox:
|
||||
break;
|
||||
|
||||
case Qgis::SpatialFilterType::DistanceWithin:
|
||||
if ( !mRequest.referenceGeometry().isEmpty() )
|
||||
{
|
||||
mDistanceWithinGeom = mRequest.referenceGeometry();
|
||||
mDistanceWithinEngine.reset( QgsGeometry::createGeometryEngine( mDistanceWithinGeom.constGet() ) );
|
||||
mDistanceWithinEngine->prepareGeometry();
|
||||
mDistanceWithin = mRequest.distanceWithin();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ( !mFilterRect.isNull() )
|
||||
{
|
||||
// update request to be the unprojected filter rect
|
||||
@ -879,6 +900,12 @@ bool QgsVectorLayerFeatureIterator::postProcessFeature( QgsFeature &feature )
|
||||
bool result = checkGeometryValidity( feature );
|
||||
if ( result )
|
||||
geometryToDestinationCrs( feature, mTransform );
|
||||
|
||||
if ( result && mDistanceWithinEngine && feature.hasGeometry() )
|
||||
{
|
||||
result = mDistanceWithinEngine->distance( feature.geometry().constGet() ) <= mDistanceWithin;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -270,6 +270,10 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera
|
||||
QgsRectangle mFilterRect;
|
||||
QgsCoordinateTransform mTransform;
|
||||
|
||||
QgsGeometry mDistanceWithinGeom;
|
||||
std::unique_ptr< QgsGeometryEngine > mDistanceWithinEngine;
|
||||
double mDistanceWithin = 0;
|
||||
|
||||
// only related to editing
|
||||
QSet<QgsFeatureId> mFetchConsidered;
|
||||
QgsGeometryMap::ConstIterator mFetchChangedGeomIt;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user