18#ifndef QGSSPATIALINDEXKDBUSH_PRIVATE_H
19#define QGSSPATIALINDEXKDBUSH_PRIVATE_H
47class PointXYKDBush :
public kdbush::KDBush< std::pair<double, double>, QgsSpatialIndexKDBushData, std::size_t >
50 explicit PointXYKDBush( QgsFeatureIterator &fi, QgsFeedback *feedback =
nullptr,
const std::function<
bool(
const QgsFeature & ) > *callback =
nullptr )
52 fillFromIterator( fi, feedback, callback );
55 explicit PointXYKDBush(
const QgsFeatureSource &source, QgsFeedback *feedback )
58 QgsFeatureIterator it = source.
getFeatures( QgsFeatureRequest().setNoAttributes() );
59 fillFromIterator( it, feedback,
nullptr );
64 void fillFromIterator( QgsFeatureIterator &fi, QgsFeedback *feedback =
nullptr,
const std::function<
bool(
const QgsFeature & ) > *callback =
nullptr )
74 if ( callback && !( *callback )( f ) )
83 points.emplace_back( QgsSpatialIndexKDBushData( f.
id(), point->
x(), point->
y() ) );
97 sortKD( 0, size - 1, 0 );
101 bool addFeature(
QgsFeatureId id,
const QgsPointXY point )
105 points.emplace_back( QgsSpatialIndexKDBushData(
id, point.
x(), point.
y() ) );
111 if ( !finalized && !points.empty() )
113 sortKD( 0, points.size() - 1, 0 );
118 std::size_t size()
const {
return points.size(); }
120 bool finalized =
false;
123class QgsSpatialIndexKDBushPrivate
126 explicit QgsSpatialIndexKDBushPrivate( QgsFeatureIterator &fi, QgsFeedback *feedback =
nullptr )
127 : index( std::make_unique< PointXYKDBush >( fi, feedback ) )
130 explicit QgsSpatialIndexKDBushPrivate(
const QgsFeatureSource &source, QgsFeedback *feedback =
nullptr )
131 : index( std::make_unique< PointXYKDBush >( source, feedback ) )
134 explicit QgsSpatialIndexKDBushPrivate( QgsFeatureIterator &fi,
const std::function<
bool(
const QgsFeature & ) > &callback, QgsFeedback *feedback =
nullptr )
135 : index( std::make_unique< PointXYKDBush >( fi, feedback, &callback ) )
138 explicit QgsSpatialIndexKDBushPrivate()
139 : index( std::make_unique< PointXYKDBush >() )
143 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