QGIS API Documentation  3.4.3-Madeira (2f64a3c)
Classes | Public Types | Public Member Functions | Protected Slots | Protected Member Functions | Friends | List of all members
QgsPointLocator Class Reference

The class defines interface for querying point location: More...

#include <qgspointlocator.h>

Inheritance diagram for QgsPointLocator:
Inheritance graph
[legend]

Classes

struct  Match
 
struct  MatchFilter
 Interface that allows rejection of some matches in intersection queries (e.g. More...
 

Public Types

typedef class QList< QgsPointLocator::MatchMatchList
 
enum  Type {
  Invalid = 0, Vertex = 1, Edge = 2, Area = 4,
  All = Vertex | Edge | Area
}
 The type of a snap result or the filter type for a snap request. More...
 

Public Member Functions

 QgsPointLocator (QgsVectorLayer *layer, const QgsCoordinateReferenceSystem &destinationCrs=QgsCoordinateReferenceSystem(), const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext(), const QgsRectangle *extent=nullptr)
 Construct point locator for a layer. More...
 
 ~QgsPointLocator () override
 
int cachedGeometryCount () const
 Returns how many geometries are cached in the index. More...
 
QgsCoordinateReferenceSystem destinationCrs () const
 Gets destination CRS - may be an invalid QgsCoordinateReferenceSystem if not doing OTF reprojection. More...
 
MatchList edgesInRect (const QgsRectangle &rect, QgsPointLocator::MatchFilter *filter=nullptr)
 Find edges within a specified recangle Optional filter may discard unwanted matches. More...
 
MatchList edgesInRect (const QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr)
 Override of edgesInRect that construct rectangle from a center point and tolerance. More...
 
const QgsRectangleextent () const
 Gets extent of the area point locator covers - if null then it caches the whole layer. More...
 
bool hasIndex () const
 Indicate whether the data have been already indexed. More...
 
bool init (int maxFeaturesToIndex=-1)
 Prepare the index for queries. More...
 
QgsVectorLayerlayer () const
 Gets associated layer. More...
 
Match nearestArea (const QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr)
 Find nearest area to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches. More...
 
Match nearestEdge (const QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr)
 Find nearest edge to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches. More...
 
Match nearestVertex (const QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr)
 Find nearest vertex to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches. More...
 
MatchList pointInPolygon (const QgsPointXY &point)
 find out if the point is in any polygons More...
 
void setExtent (const QgsRectangle *extent)
 Configure extent - if not null, it will index only that area. More...
 
void setRenderContext (const QgsRenderContext *context)
 Configure render context - if not null, it will use to index only visible feature. More...
 

Protected Slots

void destroyIndex ()
 

Protected Member Functions

bool rebuildIndex (int maxFeaturesToIndex=-1)
 

Friends

class QgsPointLocator_VisitorArea
 
class QgsPointLocator_VisitorEdgesInRect
 
class QgsPointLocator_VisitorNearestEdge
 
class QgsPointLocator_VisitorNearestVertex
 

Detailed Description

The class defines interface for querying point location:

Works with one layer.

Since
QGIS 2.8

Definition at line 55 of file qgspointlocator.h.

Member Typedef Documentation

◆ MatchList

Definition at line 212 of file qgspointlocator.h.

Member Enumeration Documentation

◆ Type

The type of a snap result or the filter type for a snap request.

Enumerator
Invalid 

Invalid.

Vertex 

Snapped to a vertex. Can be a vertex of the geometry or an intersection.

Edge 

Snapped to an edge.

Area 

Snapped to an area.

All 

Combination of vertex, edge and area.

Definition at line 109 of file qgspointlocator.h.

Constructor & Destructor Documentation

◆ QgsPointLocator()

QgsPointLocator::QgsPointLocator ( QgsVectorLayer layer,
const QgsCoordinateReferenceSystem destinationCrs = QgsCoordinateReferenceSystem(),
const QgsCoordinateTransformContext transformContext = QgsCoordinateTransformContext(),
const QgsRectangle extent = nullptr 
)
explicit

Construct point locator for a layer.

If a valid QgsCoordinateReferenceSystem is passed for destinationCrs then the locator will do the searches on data reprojected to the given CRS. For accurate reprojection it is important to set the correct transformContext if a destinationCrs is specified. This is usually taken from the current QgsProject::transformContext().

If extent is not null, the locator will index only a subset of the layer which falls within that extent.

Definition at line 623 of file qgspointlocator.cpp.

◆ ~QgsPointLocator()

QgsPointLocator::~QgsPointLocator ( )
override

Definition at line 643 of file qgspointlocator.cpp.

Member Function Documentation

◆ cachedGeometryCount()

int QgsPointLocator::cachedGeometryCount ( ) const
inline

Returns how many geometries are cached in the index.

Since
QGIS 2.14

Definition at line 269 of file qgspointlocator.h.

◆ destinationCrs()

QgsCoordinateReferenceSystem QgsPointLocator::destinationCrs ( ) const

Gets destination CRS - may be an invalid QgsCoordinateReferenceSystem if not doing OTF reprojection.

Since
QGIS 2.14

Definition at line 648 of file qgspointlocator.cpp.

◆ destroyIndex

void QgsPointLocator::destroyIndex ( )
protectedslot

Definition at line 811 of file qgspointlocator.cpp.

◆ edgesInRect() [1/2]

QgsPointLocator::MatchList QgsPointLocator::edgesInRect ( const QgsRectangle rect,
QgsPointLocator::MatchFilter filter = nullptr 
)

Find edges within a specified recangle Optional filter may discard unwanted matches.

Definition at line 997 of file qgspointlocator.cpp.

◆ edgesInRect() [2/2]

QgsPointLocator::MatchList QgsPointLocator::edgesInRect ( const QgsPointXY point,
double  tolerance,
QgsPointLocator::MatchFilter filter = nullptr 
)

Override of edgesInRect that construct rectangle from a center point and tolerance.

Definition at line 1017 of file qgspointlocator.cpp.

◆ extent()

const QgsRectangle* QgsPointLocator::extent ( ) const
inline

Gets extent of the area point locator covers - if null then it caches the whole layer.

Since
QGIS 2.14

Definition at line 92 of file qgspointlocator.h.

◆ hasIndex()

bool QgsPointLocator::hasIndex ( ) const

Indicate whether the data have been already indexed.

Definition at line 681 of file qgspointlocator.cpp.

◆ init()

bool QgsPointLocator::init ( int  maxFeaturesToIndex = -1)

Prepare the index for queries.

Does nothing if the index already exists. If the number of features is greater than the value of maxFeaturesToIndex, creation of index is stopped to make sure we do not run out of memory. If maxFeaturesToIndex is -1, no limits are used. Returns false if the creation of index has been prematurely stopped due to the limit of features, otherwise true

Definition at line 675 of file qgspointlocator.cpp.

◆ layer()

QgsVectorLayer* QgsPointLocator::layer ( ) const
inline

Gets associated layer.

Since
QGIS 2.14

Definition at line 80 of file qgspointlocator.h.

◆ nearestArea()

QgsPointLocator::Match QgsPointLocator::nearestArea ( const QgsPointXY point,
double  tolerance,
QgsPointLocator::MatchFilter filter = nullptr 
)

Find nearest area to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.

This will first perform a pointInPolygon and return first result. If no match is found and tolerance is not 0, it will return nearestEdge.

Since
QGIS 3.0

Definition at line 963 of file qgspointlocator.cpp.

◆ nearestEdge()

QgsPointLocator::Match QgsPointLocator::nearestEdge ( const QgsPointXY point,
double  tolerance,
QgsPointLocator::MatchFilter filter = nullptr 
)

Find nearest edge to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.

Definition at line 941 of file qgspointlocator.cpp.

◆ nearestVertex()

QgsPointLocator::Match QgsPointLocator::nearestVertex ( const QgsPointXY point,
double  tolerance,
QgsPointLocator::MatchFilter filter = nullptr 
)

Find nearest vertex to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.

Definition at line 923 of file qgspointlocator.cpp.

◆ pointInPolygon()

QgsPointLocator::MatchList QgsPointLocator::pointInPolygon ( const QgsPointXY point)

find out if the point is in any polygons

Definition at line 1024 of file qgspointlocator.cpp.

◆ rebuildIndex()

bool QgsPointLocator::rebuildIndex ( int  maxFeaturesToIndex = -1)
protected

Definition at line 687 of file qgspointlocator.cpp.

◆ setExtent()

void QgsPointLocator::setExtent ( const QgsRectangle extent)

Configure extent - if not null, it will index only that area.

Since
QGIS 2.14

Definition at line 653 of file qgspointlocator.cpp.

◆ setRenderContext()

void QgsPointLocator::setRenderContext ( const QgsRenderContext context)

Configure render context - if not null, it will use to index only visible feature.

Since
QGIS 3.2

Definition at line 660 of file qgspointlocator.cpp.

Friends And Related Function Documentation

◆ QgsPointLocator_VisitorArea

friend class QgsPointLocator_VisitorArea
friend

Definition at line 301 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorEdgesInRect

Definition at line 302 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorNearestEdge

Definition at line 300 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorNearestVertex

Definition at line 299 of file qgspointlocator.h.


The documentation for this class was generated from the following files: