Skip to content
Permalink
Browse files

Improvements to snapping speed: use cached geometries where possible

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9974 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jan 15, 2009
1 parent 1c02154 commit f1590aac3bb4f620b2593e5309e84473b108d95a
Showing with 38 additions and 6 deletions.
  1. +35 −6 src/core/qgsvectorlayer.cpp
  2. +3 −0 src/core/qgsvectorlayer.h
@@ -697,6 +697,8 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
{
// Destroy all cached geometries and clear the references to them
deleteCachedGeometries();

mCachedGeometriesRect = rendererContext.extent();
}

updateFeatureCount();
@@ -783,13 +785,19 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
QgsLogger::warning( "QgsRenderer is null in QgsVectorLayer::draw()" );
}

if ( mEditable )
{
QgsDebugMsg(QString("Cached %1 geometries.").arg(mCachedGeometries.count()));
}

return TRUE; // Assume success always
}

void QgsVectorLayer::deleteCachedGeometries()
{
// Destroy any cached geometries
mCachedGeometries.clear();
mCachedGeometriesRect = QgsRectangle();
}

void QgsVectorLayer::drawVertexMarker( int x, int y, QPainter& p, QgsVectorLayer::VertexMarkerType type )
@@ -3135,15 +3143,36 @@ int QgsVectorLayer::snapWithContext( const QgsPoint& startPoint, double snapping
QgsRectangle searchRect( startPoint.x() - snappingTolerance, startPoint.y() - snappingTolerance,
startPoint.x() + snappingTolerance, startPoint.y() + snappingTolerance );
double sqrSnappingTolerance = snappingTolerance * snappingTolerance;

select( QgsAttributeList(), searchRect, true, true );


int n = 0;
QgsFeature f;
while ( nextFeature( f ) )

if (mCachedGeometriesRect.contains(searchRect))
{
QgsDebugMsg("Using cached geometries for snapping.");

QgsGeometryMap::iterator it = mCachedGeometries.begin();
for ( ; it != mCachedGeometries.end() ; ++it)
{
QgsGeometry* g = &(it.value());
if (g->boundingBox().intersects(searchRect))
{
snapToGeometry( startPoint, it.key(), g, sqrSnappingTolerance, snappingResults, snap_to );
++n;
}
}
}
else
{
snapToGeometry( startPoint, f.id(), f.geometry(), sqrSnappingTolerance, snappingResults, snap_to );
++n;
// snapping outside cached area

select( QgsAttributeList(), searchRect, true, true );

while ( nextFeature( f ) )
{
snapToGeometry( startPoint, f.id(), f.geometry(), sqrSnappingTolerance, snappingResults, snap_to );
++n;
}
}

return n == 0 ? 2 : 0;
@@ -576,6 +576,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

/** cache of the committed geometries retrieved *for the current display* */
QgsGeometryMap mCachedGeometries;

/** extent for which there are cached geometries */
QgsRectangle mCachedGeometriesRect;

/** Set holding the feature IDs that are activated. Note that if a feature
subsequently gets deleted (i.e. by its addition to mDeletedFeatureIds),

0 comments on commit f1590aa

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