Skip to content
Permalink
Browse files

allow limiting snapping to a given area

  • Loading branch information
jef-n committed Jan 1, 2017
1 parent 4d6a535 commit c6fb25375cd248f09bd6491933bf771529170d95
@@ -47,7 +47,8 @@ class QgsSnappingUtils : QObject
{
IndexAlwaysFull, //!< For all layers build index of full extent. Uses more memory, but queries are faster.
IndexNeverFull, //!< For all layers only create temporary indexes of small extent. Low memory usage, slower queries.
IndexHybrid //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
IndexHybrid, //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
IndexExtent //!< For all layer build index of extent given in map settings
};

/** Set a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be */
@@ -849,7 +849,7 @@ QgsPointLocator::Match QgsPointLocator::nearestVertex( const QgsPoint& point, do
QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
if ( m.isValid() && m.distance() > tolerance )
return Match(); // // make sure that only match strictly within the tolerance is returned
return Match(); // make sure that only match strictly within the tolerance is returned
return m;
}

@@ -871,7 +871,7 @@ QgsPointLocator::Match QgsPointLocator::nearestEdge( const QgsPoint& point, doub
QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
if ( m.isValid() && m.distance() > tolerance )
return Match(); // // make sure that only match strictly within the tolerance is returned
return Match(); // make sure that only match strictly within the tolerance is returned
return m;
}

@@ -91,7 +91,9 @@ bool QgsSnappingUtils::isIndexPrepared( QgsVectorLayer* vl, const QgsRectangle&
if ( mStrategy == IndexAlwaysFull && loc->hasIndex() )
return true;

if ( mStrategy == IndexHybrid && loc->hasIndex() && ( !loc->extent() || loc->extent()->contains( areaOfInterest ) ) )
QgsRectangle aoi( areaOfInterest );
aoi.scale( 0.999 );
if (( mStrategy == IndexHybrid || mStrategy == IndexExtent ) && loc->hasIndex() && ( !loc->extent() || loc->extent()->contains( aoi ) ) )

This comment has been minimized.

Copy link
@mhugo

mhugo Jan 10, 2019

This is a pretty old commit, but I am currently experimenting with IndexExtent and I get a very strange behaviour: indexes get constantly destroyed and recomputed when the mouse moves close to extent's borders (with the vertex tool).
It seems to come from these lines. I can't understand the logic behind : why do we want to recompute indexes on borders ?

This comment has been minimized.

This comment has been minimized.

Copy link
@wonder-sk

wonder-sk Jan 10, 2019

Member

that's probably happening because near the extent's border the area interest (point expanded by tolerance) does not fully fit into the indexed area (so the existing locator may not give correct results). Probably extending the indexed area a bit would solve that...

This comment has been minimized.

Copy link
@mhugo

mhugo Jan 10, 2019

In the case of an "IndexExtent" strategy, is there a need that the area of interest fully fits the indexed area (the current extent) ? A simple intersection test would work, right ? There is no need to try to index stuff that are beyond the current extent I think.
Is still do not understand what the 0.999% scale is supposed to do / circumvent ...

return true;

return false; // the index - even if it exists - is not suitable
@@ -339,7 +341,13 @@ void QgsSnappingUtils::prepareIndex( const QList<LayerAndAreaOfInterest>& layers
QTime tt;
tt.start();
QgsPointLocator* loc = locatorForLayer( vl );
if ( mStrategy == IndexHybrid )
if ( mStrategy == IndexExtent )
{
QgsRectangle rect( mMapSettings.extent() );
loc->setExtent( &rect );
loc->init();
}
else if ( mStrategy == IndexHybrid )
{
// first time the layer is used? - let's set an initial guess about indexing
if ( !mHybridMaxAreaPerLayer.contains( vl->id() ) )
@@ -487,7 +495,7 @@ QString QgsSnappingUtils::dump()
.arg( layer.layer->name() )
.arg( layer.type ).arg( layer.tolerance ).arg( layer.unit );

if ( mStrategy == IndexAlwaysFull || mStrategy == IndexHybrid )
if ( mStrategy == IndexAlwaysFull || mStrategy == IndexHybrid || mStrategy == IndexExtent )
{
if ( QgsPointLocator* loc = locatorForLayer( layer.layer ) )
{
@@ -89,7 +89,8 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
{
IndexAlwaysFull, //!< For all layers build index of full extent. Uses more memory, but queries are faster.
IndexNeverFull, //!< For all layers only create temporary indexes of small extent. Low memory usage, slower queries.
IndexHybrid //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
IndexHybrid, //!< For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.
IndexExtent //!< For all layer build index of extent given in map settings
};

//! Set a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be
@@ -1048,13 +1048,15 @@ QMap< QString, QStringList > QgsCptCityDirectoryItem::rampsMap()
}

}
#if 0
//TODO what to do with other vars? e.g. schemeNames
// // add schemes to archive
// mSchemeMap[ path ] = schemeNames;
// schemeCount += schemeName.count();
// schemeNames.clear();
// listVariant.clear();
// prevName = "";
// add schemes to archive
mSchemeMap[ path ] = schemeNames;
schemeCount += schemeName.count();
schemeNames.clear();
listVariant.clear();
prevName = "";
#endif
return mRampsMap;
}

@@ -40,7 +40,6 @@ struct Block {
size_t size;
};

// ///////////////////////////////////////////////////////

class BlockArray {
public:

0 comments on commit c6fb253

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