Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Optimise point lookup in index
  • Loading branch information
nyalldawson committed Jul 7, 2018
1 parent 5ce8240 commit 682671d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/core/qgsspatialindexkdbush_p.h
Expand Up @@ -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
{
Expand All @@ -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
Expand Down

0 comments on commit 682671d

Please sign in to comment.