QGIS API Documentation  3.20.0-Odense (decaadbb31)
Classes | Public Types | Signals | 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 << 0 , Edge = 1 << 1 , Area = 1 << 2 ,
  Centroid = 1 << 3 , MiddleOfSegment = 1 << 4 , LineEndpoint = 1 << 5 , All = Vertex | Edge | Area | Centroid | MiddleOfSegment
}
 The type of a snap result or the filter type for a snap request. More...
 

Signals

void initFinished (bool ok)
 Emitted whenever index has been built and initialization is finished. 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 QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Override of edgesInRect that construct rectangle from a center point and tolerance This method is either blocking or non blocking according to relaxed parameter passed. More...
 
MatchList edgesInRect (const QgsRectangle &rect, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Find edges within a specified rectangle Optional filter may discard unwanted matches. More...
 
const QgsRectangleextent () const
 Gets extent of the area point locator covers - if nullptr then it caches the whole layer. More...
 
bool hasIndex () const
 Indicate whether the data have been already indexed. More...
 
bool init (int maxFeaturesToIndex=-1, bool relaxed=false)
 Prepare the index for queries. More...
 
bool isIndexing () const
 Returns true if the point locator is currently indexing the data. More...
 
QgsVectorLayerlayer () const
 Gets associated layer. More...
 
Match nearestArea (const QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Find nearest area to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches. More...
 
Match nearestCentroid (const QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Find nearest centroid 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, bool relaxed=false)
 Find nearest edge to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches. More...
 
Match nearestLineEndpoints (const QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Find nearest line endpoint (start or end vertex) to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches. More...
 
Match nearestMiddleOfSegment (const QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Find nearest middle of segment 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, bool relaxed=false)
 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, bool relaxed=false)
 find out if the point is in any polygons This method is either blocking or non blocking according to relaxed parameter passed More...
 
void setExtent (const QgsRectangle *extent)
 Configure extent - if not nullptr, it will index only that area. More...
 
void setRenderContext (const QgsRenderContext *context)
 Configure render context - if not nullptr, it will use to index only visible feature. More...
 
MatchList verticesInRect (const QgsPointXY &point, double tolerance, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Override of verticesInRect that construct rectangle from a center point and tolerance This method is either blocking or non blocking according to relaxed parameter passed. More...
 
MatchList verticesInRect (const QgsRectangle &rect, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Find vertices within a specified rectangle This method is either blocking or non blocking according to relaxed parameter passed Optional filter may discard unwanted matches. More...
 
void waitForIndexingFinished ()
 If the point locator has been initialized relaxedly and is currently indexing, this methods waits for the indexing to be finished. More...
 

Protected Slots

void destroyIndex ()
 

Protected Member Functions

bool rebuildIndex (int maxFeaturesToIndex=-1)
 

Friends

class QgsPointLocator_VisitorArea
 
class QgsPointLocator_VisitorCentroidsInRect
 
class QgsPointLocator_VisitorEdgesInRect
 
class QgsPointLocator_VisitorMiddlesInRect
 
class QgsPointLocator_VisitorNearestCentroid
 
class QgsPointLocator_VisitorNearestEdge
 
class QgsPointLocator_VisitorNearestLineEndpoint
 
class QgsPointLocator_VisitorNearestMiddleOfSegment
 
class QgsPointLocator_VisitorNearestVertex
 
class QgsPointLocator_VisitorVerticesInRect
 
class QgsPointLocatorInitTask
 
class TestQgsPointLocator
 

Detailed Description

The class defines interface for querying point location:

Works with one layer.

Since
QGIS 2.8

Definition at line 101 of file qgspointlocator.h.

Member Typedef Documentation

◆ MatchList

Definition at line 185 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.

Centroid 

Snapped to a centroid.

MiddleOfSegment 

Snapped to the middle of a segment.

LineEndpoint 

Start or end points of lines only (since QGIS 3.20)

All 

Combination of all types. Note LineEndpoint is not included as endpoints made redundant by the presence of the Vertex flag.

Definition at line 155 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 nullptr, the locator will index only a subset of the layer which falls within that extent.

Definition at line 843 of file qgspointlocator.cpp.

◆ ~QgsPointLocator()

QgsPointLocator::~QgsPointLocator ( )
override

Definition at line 863 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 414 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 873 of file qgspointlocator.cpp.

◆ destroyIndex

void QgsPointLocator::destroyIndex ( )
protectedslot

Definition at line 1137 of file qgspointlocator.cpp.

◆ edgesInRect() [1/2]

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

Override of edgesInRect that construct rectangle from a center point and tolerance This method is either blocking or non blocking according to relaxed parameter passed.

Definition at line 1397 of file qgspointlocator.cpp.

◆ edgesInRect() [2/2]

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

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

This method is either blocking or non blocking according to relaxed parameter passed

Definition at line 1381 of file qgspointlocator.cpp.

◆ extent()

const QgsRectangle* QgsPointLocator::extent ( ) const
inline

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

Since
QGIS 2.14

Definition at line 138 of file qgspointlocator.h.

◆ hasIndex()

bool QgsPointLocator::hasIndex ( ) const

Indicate whether the data have been already indexed.

Definition at line 981 of file qgspointlocator.cpp.

◆ init()

bool QgsPointLocator::init ( int  maxFeaturesToIndex = -1,
bool  relaxed = false 
)

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.

This method is either blocking or non blocking according to relaxed parameter passed in the constructor. if true, index building will be done in another thread and init() method returns immediately. initFinished() signal will be emitted once the initialization is over.

Returns false if the creation of index is blocking and has been prematurely stopped due to the limit of features, otherwise true

See also
QgsPointLocator()

Definition at line 934 of file qgspointlocator.cpp.

◆ initFinished

void QgsPointLocator::initFinished ( bool  ok)
signal

Emitted whenever index has been built and initialization is finished.

Parameters
okfalse if the creation of index has been prematurely stopped due to the limit of features, otherwise true

◆ isIndexing()

bool QgsPointLocator::isIndexing ( ) const
inline

Returns true if the point locator is currently indexing the data.

This method is useful if constructor parameter relaxed is true

See also
QgsPointLocator()

Definition at line 422 of file qgspointlocator.h.

◆ layer()

QgsVectorLayer* QgsPointLocator::layer ( ) const
inline

Gets associated layer.

Since
QGIS 2.14

Definition at line 126 of file qgspointlocator.h.

◆ nearestArea()

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

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. This method is either blocking or non blocking according to relaxed parameter passed

Since
QGIS 3.0

Definition at line 1351 of file qgspointlocator.cpp.

◆ nearestCentroid()

QgsPointLocator::Match QgsPointLocator::nearestCentroid ( const QgsPointXY point,
double  tolerance,
QgsPointLocator::MatchFilter filter = nullptr,
bool  relaxed = false 
)

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

This method is either blocking or non blocking according to relaxed parameter passed

Since
3.12

Definition at line 1288 of file qgspointlocator.cpp.

◆ nearestEdge()

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

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

This method is either blocking or non blocking according to relaxed parameter passed

Definition at line 1333 of file qgspointlocator.cpp.

◆ nearestLineEndpoints()

QgsPointLocator::Match QgsPointLocator::nearestLineEndpoints ( const QgsPointXY point,
double  tolerance,
QgsPointLocator::MatchFilter filter = nullptr,
bool  relaxed = false 
)

Find nearest line endpoint (start or end vertex) to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.

This method is either blocking or non blocking according to relaxed parameter passed

Since
3.20

Definition at line 1318 of file qgspointlocator.cpp.

◆ nearestMiddleOfSegment()

QgsPointLocator::Match QgsPointLocator::nearestMiddleOfSegment ( const QgsPointXY point,
double  tolerance,
QgsPointLocator::MatchFilter filter = nullptr,
bool  relaxed = false 
)

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

This method is either blocking or non blocking according to relaxed parameter passed

Since
3.12

Definition at line 1303 of file qgspointlocator.cpp.

◆ nearestVertex()

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

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

This method is either blocking or non blocking according to relaxed parameter passed

Definition at line 1274 of file qgspointlocator.cpp.

◆ pointInPolygon()

QgsPointLocator::MatchList QgsPointLocator::pointInPolygon ( const QgsPointXY point,
bool  relaxed = false 
)

find out if the point is in any polygons This method is either blocking or non blocking according to relaxed parameter passed

Definition at line 1421 of file qgspointlocator.cpp.

◆ rebuildIndex()

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

Definition at line 1006 of file qgspointlocator.cpp.

◆ setExtent()

void QgsPointLocator::setExtent ( const QgsRectangle extent)

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

Since
QGIS 2.14

Definition at line 878 of file qgspointlocator.cpp.

◆ setRenderContext()

void QgsPointLocator::setRenderContext ( const QgsRenderContext context)

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

Since
QGIS 3.2

Definition at line 889 of file qgspointlocator.cpp.

◆ verticesInRect() [1/2]

QgsPointLocator::MatchList QgsPointLocator::verticesInRect ( const QgsPointXY point,
double  tolerance,
QgsPointLocator::MatchFilter filter = nullptr,
bool  relaxed = false 
)

Override of verticesInRect that construct rectangle from a center point and tolerance This method is either blocking or non blocking according to relaxed parameter passed.

Since
QGIS 3.6

Definition at line 1415 of file qgspointlocator.cpp.

◆ verticesInRect() [2/2]

QgsPointLocator::MatchList QgsPointLocator::verticesInRect ( const QgsRectangle rect,
QgsPointLocator::MatchFilter filter = nullptr,
bool  relaxed = false 
)

Find vertices within a specified rectangle This method is either blocking or non blocking according to relaxed parameter passed Optional filter may discard unwanted matches.

Since
QGIS 3.6

Definition at line 1403 of file qgspointlocator.cpp.

◆ waitForIndexingFinished()

void QgsPointLocator::waitForIndexingFinished ( )

If the point locator has been initialized relaxedly and is currently indexing, this methods waits for the indexing to be finished.

Definition at line 973 of file qgspointlocator.cpp.

Friends And Related Function Documentation

◆ QgsPointLocator_VisitorArea

friend class QgsPointLocator_VisitorArea
friend

Definition at line 488 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorCentroidsInRect

Definition at line 493 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorEdgesInRect

Definition at line 489 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorMiddlesInRect

Definition at line 494 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorNearestCentroid

Definition at line 485 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorNearestEdge

Definition at line 487 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorNearestLineEndpoint

Definition at line 495 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorNearestMiddleOfSegment

Definition at line 486 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorNearestVertex

Definition at line 484 of file qgspointlocator.h.

◆ QgsPointLocator_VisitorVerticesInRect

Definition at line 490 of file qgspointlocator.h.

◆ QgsPointLocatorInitTask

friend class QgsPointLocatorInitTask
friend

Definition at line 491 of file qgspointlocator.h.

◆ TestQgsPointLocator

friend class TestQgsPointLocator
friend

Definition at line 492 of file qgspointlocator.h.


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