Class: QgsPointLocator¶
- class qgis.core.QgsPointLocator¶
Bases:
PyQt5.QtCore.QObject
The class defines interface for querying point location:
query nearest vertices / edges to a point
query vertices / edges in rectangle
query areas covering a point
Works with one layer.
New in version 2.8.
QgsPointLocator(layer:
QgsVectorLayer
, destinationCrs:QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem(), transformContext:QgsCoordinateTransformContext
= QgsCoordinateTransformContext(), extent:QgsRectangle
= None) Construct point locator for alayer
.If a valid
QgsCoordinateReferenceSystem
is passed fordestinationCrs
then the locator will do the searches on data reprojected to the given CRS. For accurate reprojection it is important to set the correcttransformContext
if adestinationCrs
is specified. This is usually taken from the currentQgsProject.transformContext()
.If
extent
is notNone
, the locator will index only a subset of the layer which falls within that extent.Methods
Returns how many geometries are cached in the index
Gets destination CRS - may be an invalid
QgsCoordinateReferenceSystem
if not doing OTF reprojectionFind edges within a specified rectangle Optional filter may discard unwanted matches.
Gets extent of the area point locator covers - if
None
then it caches the whole layerIndicate whether the data have been already indexed
Prepare the index for queries.
Returns
True
if the point locator is currently indexing the data.Gets associated layer
Find nearest area to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.
Find nearest centroid to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.
Find nearest edge to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.
Find nearest line endpoint (start or end vertex) to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.
Find nearest middle of segment to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.
Find nearest vertex to the specified point - up to distance specified by tolerance Optional filter may discard unwanted matches.
Find out if the
point
is in any polygons- param maxFeaturesToIndex:
Configure extent - if not
None
, it will index only that areaConfigure render context - if not
None
, it will use to index only visible featureFind vertices within a specified rectangle This method is either blocking or non blocking according to
relaxed
parameter passed Optional filter may discard unwanted matches.If the point locator has been initialized relaxedly and is currently indexing, this methods waits for the indexing to be finished
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
Attributes
- All = 31¶
- Area = 4¶
- Centroid = 8¶
- Edge = 2¶
- Invalid = 0¶
- LineEndpoint = 32¶
- class Match¶
Bases:
sip.wrapper
construct invalid match
QgsPointLocator.Match(t: QgsPointLocator.Type, vl:
QgsVectorLayer
, fid: int, dist: float, pt:QgsPointXY
, vertexIndex: int = 0, edgePoints:QgsPointXY
= None)QgsPointLocator.Match(QgsPointLocator.Match)
- distance(self) float ¶
for vertex / edge match units depending on what class returns it (geom.cache: layer units, map canvas snapper: dest crs units)
- Return type:
float
- edgePoints(self) Tuple[QgsPointXY, QgsPointXY] ¶
Only for a valid edge match - obtain endpoints of the edge
- Return type:
Tuple[
QgsPointXY
, QgsPointXY]
- featureId(self) int ¶
The id of the feature to which the snapped geometry belongs.
- Return type:
int
- hasArea(self) bool ¶
Returns
True
if the Match is an area- Return type:
bool
- hasCentroid(self) bool ¶
Returns
True
if the Match is a centroid- Return type:
bool
- hasEdge(self) bool ¶
Returns
True
if the Match is an edge- Return type:
bool
- hasLineEndpoint(self) bool ¶
Returns
True
if the Match is a line endpoint (start or end vertex).New in version 3.20.
- Return type:
bool
- hasMiddleSegment(self) bool ¶
Returns
True
if the Match is the middle of a segment- Return type:
bool
- hasVertex(self) bool ¶
Returns
True
if the Match is a vertex- Return type:
bool
- interpolatedPoint(self, destinationCrs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem()) QgsPoint ¶
Convenient method to return a point on an edge with linear interpolation of the Z value. The parameter
destinationCrs
depends of where the instance of this Match is created (geom.cache: layer CRS, map canvas snapper: dest CRS)New in version 3.10.
- Parameters:
destinationCrs (
QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem()) –- Return type:
- isValid(self) bool ¶
- Return type:
bool
- layer(self) QgsVectorLayer ¶
The vector layer where the snap occurred. Will be
None
if the snap happened on an intersection.- Return type:
- point(self) QgsPointXY ¶
for vertex / edge match coords depending on what class returns it (geom.cache: layer coords, map canvas snapper: dest coords)
- Return type:
- type(self) QgsPointLocator.Type ¶
- Return type:
- vertexIndex(self) int ¶
for vertex / edge match (first vertex of the edge)
- Return type:
int
- class MatchFilter¶
- class MatchFilter(QgsPointLocator.MatchFilter)
Bases:
sip.wrapper
- acceptMatch(self, match: QgsPointLocator.Match) bool ¶
- Parameters:
match (QgsPointLocator.Match) –
- Return type:
bool
- MiddleOfSegment = 16¶
- class Type¶
Bases:
int
- class Types¶
- class Types(Union[QgsPointLocator.Types, QgsPointLocator.Type])
- class Types(QgsPointLocator.Types)
Bases:
sip.wrapper
- Vertex = 1¶
- cachedGeometryCount(self) int ¶
Returns how many geometries are cached in the index
New in version 2.14.
- Return type:
int
- childEvent(self, QChildEvent)¶
- connectNotify(self, QMetaMethod)¶
- customEvent(self, QEvent)¶
- destinationCrs(self) QgsCoordinateReferenceSystem ¶
Gets destination CRS - may be an invalid
QgsCoordinateReferenceSystem
if not doing OTF reprojectionNew in version 2.14.
- Return type:
- destroyIndex(self)¶
- disconnectNotify(self, QMetaMethod)¶
- edgesInRect(self, rect: QgsRectangle, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) List[QgsPointLocator.Match] ¶
Find edges within a specified rectangle Optional filter may discard unwanted matches. This method is either blocking or non blocking according to
relaxed
parameter passededgesInRect(self, point:
QgsPointXY
, tolerance: float, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) -> List[QgsPointLocator.Match] Override of edgesInRect that construct rectangle from a center point and tolerance This method is either blocking or non blocking according torelaxed
parameter passed- Parameters:
rect (QgsRectangle) –
filter (QgsPointLocator.MatchFilter = None) –
relaxed (bool = False) –
- Return type:
List[QgsPointLocator.Match]
- extent(self) QgsRectangle ¶
Gets extent of the area point locator covers - if
None
then it caches the whole layerNew in version 2.14.
- Return type:
- hasIndex(self) bool ¶
Indicate whether the data have been already indexed
- Return type:
bool
- init(self, maxFeaturesToIndex: int = -1, relaxed: bool = False) bool ¶
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. ifTrue
, index building will be done in another thread andinit()
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, otherwiseTrue
See also
- Parameters:
maxFeaturesToIndex (int = -1) –
relaxed (bool = False) –
- Return type:
bool
- initFinished¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- isIndexing(self) bool ¶
Returns
True
if the point locator is currently indexing the data. This method is useful if constructor parameterrelaxed
isTrue
See also
- Return type:
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- layer(self) QgsVectorLayer ¶
Gets associated layer
New in version 2.14.
- Return type:
- nearestArea(self, point: QgsPointXY, tolerance: float, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) QgsPointLocator.Match ¶
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 passedNew in version 3.0.
- Parameters:
point (QgsPointXY) –
tolerance (float) –
filter (QgsPointLocator.MatchFilter = None) –
relaxed (bool = False) –
- Return type:
- nearestCentroid(self, point: QgsPointXY, tolerance: float, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) QgsPointLocator.Match ¶
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 passedNew in version 3.12.
- Parameters:
point (QgsPointXY) –
tolerance (float) –
filter (QgsPointLocator.MatchFilter = None) –
relaxed (bool = False) –
- Return type:
- nearestEdge(self, point: QgsPointXY, tolerance: float, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) QgsPointLocator.Match ¶
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- Parameters:
point (QgsPointXY) –
tolerance (float) –
filter (QgsPointLocator.MatchFilter = None) –
relaxed (bool = False) –
- Return type:
- nearestLineEndpoints(self, point: QgsPointXY, tolerance: float, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) QgsPointLocator.Match ¶
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 passedNew in version 3.20.
- Parameters:
point (QgsPointXY) –
tolerance (float) –
filter (QgsPointLocator.MatchFilter = None) –
relaxed (bool = False) –
- Return type:
- nearestMiddleOfSegment(self, point: QgsPointXY, tolerance: float, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) QgsPointLocator.Match ¶
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 passedNew in version 3.12.
- Parameters:
point (QgsPointXY) –
tolerance (float) –
filter (QgsPointLocator.MatchFilter = None) –
relaxed (bool = False) –
- Return type:
- nearestVertex(self, point: QgsPointXY, tolerance: float, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) QgsPointLocator.Match ¶
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- Parameters:
point (QgsPointXY) –
tolerance (float) –
filter (QgsPointLocator.MatchFilter = None) –
relaxed (bool = False) –
- Return type:
- pointInPolygon(self, point: QgsPointXY, relaxed: bool = False, filter: QgsPointLocator.MatchFilter = None) List[QgsPointLocator.Match] ¶
Find out if the
point
is in any polygons- Parameters:
point (QgsPointXY) – The point to check polygons against, in map coordinates
relaxed (bool = False) –
True
if index build has to be non blockingfilter (QgsPointLocator.MatchFilter = None) – since QGIS 3.36, Optional filter may discard unwanted matches.
Note
Parameters
filter
andrelaxed
are in reversed order compared to the rest of MatchList returning methods.- Return type:
List[QgsPointLocator.Match]
- rebuildIndex(self, maxFeaturesToIndex: int = -1) bool ¶
- Parameters:
maxFeaturesToIndex (int = -1) –
- Return type:
bool
- receivers(self, PYQT_SIGNAL) int ¶
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setExtent(self, extent: QgsRectangle)¶
Configure extent - if not
None
, it will index only that areaNew in version 2.14.
- Parameters:
extent (QgsRectangle) –
- setRenderContext(self, context: QgsRenderContext)¶
Configure render context - if not
None
, it will use to index only visible featureNew in version 3.2.
- Parameters:
context (QgsRenderContext) –
- timerEvent(self, QTimerEvent)¶
- verticesInRect(self, rect: QgsRectangle, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) List[QgsPointLocator.Match] ¶
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.New in version 3.6.
verticesInRect(self, point:
QgsPointXY
, tolerance: float, filter: QgsPointLocator.MatchFilter = None, relaxed: bool = False) -> List[QgsPointLocator.Match] Override of verticesInRect that construct rectangle from a center point and tolerance This method is either blocking or non blocking according torelaxed
parameter passedNew in version 3.6.
- Parameters:
rect (QgsRectangle) –
filter (QgsPointLocator.MatchFilter = None) –
relaxed (bool = False) –
- Return type:
List[QgsPointLocator.Match]
- waitForIndexingFinished(self)¶
If the point locator has been initialized relaxedly and is currently indexing, this methods waits for the indexing to be finished