18#ifndef QGSSPATIALINDEXKDBUSH_PRIVATE_H
19#define QGSSPATIALINDEXKDBUSH_PRIVATE_H
47class PointXYKDBush :
public kdbush::KDBush< std::pair<double, double>, QgsSpatialIndexKDBushData, std::size_t >
51 explicit PointXYKDBush( QgsFeatureIterator &fi, QgsFeedback *feedback =
nullptr,
const std::function<
bool(
const QgsFeature & ) > *callback =
nullptr )
53 fillFromIterator( fi, feedback, callback );
56 explicit PointXYKDBush(
const QgsFeatureSource &source, QgsFeedback *feedback )
59 QgsFeatureIterator it = source.
getFeatures( QgsFeatureRequest().setNoAttributes() );
60 fillFromIterator( it, feedback,
nullptr );
67 void fillFromIterator( QgsFeatureIterator &fi, QgsFeedback *feedback =
nullptr,
const std::function<
bool(
const QgsFeature & ) > *callback =
nullptr )
77 if ( callback && !( *callback )( f ) )
86 points.emplace_back( QgsSpatialIndexKDBushData( f.
id(), point->
x(), point->
y() ) );
100 sortKD( 0, size - 1, 0 );
104 bool addFeature(
QgsFeatureId id,
const QgsPointXY point )
108 points.emplace_back( QgsSpatialIndexKDBushData(
id, point.
x(), point.
y() ) );
114 if ( !finalized && !points.empty() )
116 sortKD( 0, points.size() - 1, 0 );
121 std::size_t size()
const
123 return points.size();
126 bool finalized =
false;
130class QgsSpatialIndexKDBushPrivate
134 explicit QgsSpatialIndexKDBushPrivate( QgsFeatureIterator &fi, QgsFeedback *feedback =
nullptr )
135 : index( std::make_unique < PointXYKDBush >( fi, feedback ) )
138 explicit QgsSpatialIndexKDBushPrivate(
const QgsFeatureSource &source, QgsFeedback *feedback =
nullptr )
139 : index( std::make_unique < PointXYKDBush >( source, feedback ) )
142 explicit QgsSpatialIndexKDBushPrivate( QgsFeatureIterator &fi,
const std::function<
bool(
const QgsFeature & ) > &callback, QgsFeedback *feedback =
nullptr )
143 : index( std::make_unique < PointXYKDBush >( fi, feedback, &callback ) )
146 explicit QgsSpatialIndexKDBushPrivate()
147 : index( std::make_unique < PointXYKDBush >() )
151 std::unique_ptr< PointXYKDBush > index;
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
virtual long long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features