Skip to content

Commit cae4eb3

Browse files
committedJan 20, 2015
[FEATURE] New snapping API with improved indexing (QEP 13)
Merge branch 'snapping-improved'
2 parents b029198 + 8177bbe commit cae4eb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2796
-485
lines changed
 

‎python/core/core.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
%Include qgspluginlayer.sip
7979
%Include qgspluginlayerregistry.sip
8080
%Include qgspoint.sip
81+
%Include qgspointlocator.sip
8182
%Include qgsproject.sip
8283
%Include qgsprojectproperty.sip
8384
%Include qgsprojectversion.sip
@@ -96,6 +97,7 @@
9697
%Include qgsscaleutils.sip
9798
%Include qgssimplifymethod.sip
9899
%Include qgssnapper.sip
100+
%Include qgssnappingutils.sip
99101
%Include qgsspatialindex.sip
100102
%Include qgstolerance.sip
101103
%Include qgsvectordataprovider.sip

‎python/core/qgspointlocator.sip

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
class QgsPointLocator : QObject
3+
{
4+
%TypeHeaderCode
5+
#include <qgspointlocator.h>
6+
%End
7+
8+
public:
9+
/** Construct point locator for a layer.
10+
* @arg destCRS if not null, will do the searches on data reprojected to the given CRS
11+
* @arg extent if not null, will index only a subset of the layer
12+
*/
13+
explicit QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateReferenceSystem* destCRS = 0, const QgsRectangle* extent = 0 );
14+
15+
~QgsPointLocator();
16+
17+
enum Type { Invalid, Vertex, Edge, Area, All };
18+
19+
/** Prepare the index for queries. Does nothing if the index already exists */
20+
void init();
21+
22+
struct Match
23+
{
24+
//! consruct invalid match
25+
Match();
26+
27+
Match( QgsPointLocator::Type t, QgsVectorLayer* vl, QgsFeatureId fid, double dist, const QgsPoint& pt, int vertexIndex = 0 );
28+
29+
QgsPointLocator::Type type() const;
30+
31+
bool isValid() const;
32+
bool hasVertex() const;
33+
bool hasEdge() const;
34+
bool hasArea() const;
35+
36+
//! for vertex / edge match
37+
//! units depending on what class returns it (geom.cache: layer units, map canvas snapper: dest crs units)
38+
double distance() const;
39+
40+
//! for vertex / edge match
41+
//! coords depending on what class returns it (geom.cache: layer coords, map canvas snapper: dest coords)
42+
QgsPoint point() const;
43+
44+
//! for vertex / edge match (first vertex of the edge)
45+
int vertexIndex() const;
46+
47+
//! reference vector layer
48+
QgsVectorLayer* layer() const;
49+
50+
QgsFeatureId featureId() const;
51+
52+
//! Only for a valid edge match - obtain endpoints of the edge
53+
void edgePoints( QgsPoint& pt1 /Out/, QgsPoint& pt2 /Out/ ) const;
54+
};
55+
56+
typedef QList<QgsPointLocator::Match> MatchList;
57+
58+
//! Interface that allows rejection of some matches in intersection queries
59+
//! (e.g. a match can only belong to a particular feature / match must not be a particular point).
60+
//! Implement the interface and pass its instance to QgsPointLocator or QgsSnappingUtils methods.
61+
struct MatchFilter
62+
{
63+
virtual bool acceptMatch( const QgsPointLocator::Match& match ) = 0;
64+
};
65+
66+
// intersection queries
67+
68+
//! Find nearest vertex to the specified point - up to distance specified by tolerance
69+
//! Optional filter may discard unwanted matches.
70+
Match nearestVertex( const QgsPoint& point, double tolerance, QgsPointLocator::MatchFilter* filter = 0 );
71+
//! Find nearest edges to the specified point - up to distance specified by tolerance
72+
//! Optional filter may discard unwanted matches.
73+
Match nearestEdge( const QgsPoint& point, double tolerance, QgsPointLocator::MatchFilter* filter = 0 );
74+
//! Find edges within a specified recangle
75+
//! Optional filter may discard unwanted matches.
76+
MatchList edgesInRect( const QgsRectangle& rect, QgsPointLocator::MatchFilter* filter = 0 );
77+
//! Override of edgesInRect that construct rectangle from a center point and tolerance
78+
MatchList edgesInRect( const QgsPoint& point, double tolerance, QgsPointLocator::MatchFilter* filter = 0 );
79+
80+
// point-in-polygon query
81+
82+
// TODO: function to return just the first match?
83+
//! find out if the point is in any polygons
84+
MatchList pointInPolygon( const QgsPoint& point );
85+
86+
87+
};

0 commit comments

Comments
 (0)
Please sign in to comment.