|
| 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