Skip to content
Permalink
Browse files

Optimise point lookup in index

  • Loading branch information
nyalldawson committed Jul 6, 2018
1 parent 5ce8240 commit 682671d18f545747327cc9163ca7f3cf97def95f
Showing with 8 additions and 6 deletions.
  1. +8 −6 src/core/qgsspatialindexkdbush_p.h
@@ -74,6 +74,7 @@ class PointXYKDBush : public kdbush::KDBush< std::pair<double, double>, QgsFeatu
{
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( f.geometry().constGet() );
points.emplace_back( point->x(), point->y() );
mIdToPoint[ f.id() ] = QgsPointXY( point->x(), point->y() );
}
else
{
@@ -90,17 +91,18 @@ class PointXYKDBush : public kdbush::KDBush< std::pair<double, double>, QgsFeatu

bool point( QgsFeatureId id, QgsPointXY &point ) const
{
auto iter = std::find_if( ids.begin(), ids.end(), [id]( QgsFeatureId f ) { return id == f; } );
size_t index = std::distance( ids.begin(), iter );
if ( index == ids.size() )
{
auto it = mIdToPoint.constFind( id );
if ( it == mIdToPoint.constEnd() )
return false;
}

point = QgsPointXY( points[ index ].first, points[index].second );
point = *it;
return true;
}

private:

QHash< QgsFeatureId, QgsPointXY > mIdToPoint;

};

class QgsSpatialIndexKDBushPrivate

0 comments on commit 682671d

Please sign in to comment.
You can’t perform that action at this time.