Class: QgsMeshSpatialIndex¶
A spatial index for QgsMeshFace
or QgsMeshEdge
objects.
QgsMeshSpatialIndex
objects are implicitly shared and can be
inexpensively copied.
Note
While the underlying libspatialindex is not thread safe on some platforms, the QgsMeshSpatialIndex
class implements its own locks and accordingly, a single QgsMeshSpatialIndex
object can safely
be used across multiple threads
See also
QgsSpatialIndex
which is for vector features
Added in version 3.6.
Methods
Adds a face with faceIndex from the mesh in the spatial index |
|
Returns the type of mesh elements that are indexed |
|
Returns a list of face ids with a bounding box which intersects the specified rectangle. |
|
Returns nearest neighbors to a point. |
|
Removes a face with faceIndex from the mesh in the spatial index |
- class qgis.core.QgsMeshSpatialIndex[source]¶
Bases:
object
- __init__()
Constructor for
QgsSpatialIndex
. Creates an empty R-tree index.
- __init__(mesh: QgsMesh, feedback: QgsFeedback | None = None, elementType: QgsMesh.ElementType = QgsMesh.ElementType.Face)
Constructor - creates R-tree and bulk loads faces or edges from the specified mesh
Not implemented to construct R-tree for vertices Since QGIS 3.14 possibility to create R-tree for edges
The optional
feedback
object can be used to allow cancellation of bulk face loading. Ownership offeedback
is not transferred, and callers must take care that the lifetime of feedback exceeds that of the spatial index construction.- Parameters:
mesh (QgsMesh)
feedback (Optional[QgsFeedback] = None)
elementType (QgsMesh.ElementType = QgsMesh.ElementType.Face)
- __init__(other: QgsMeshSpatialIndex)
- Parameters:
other (QgsMeshSpatialIndex)
- addFace(self, faceIndex: int, mesh: QgsMesh)[source]¶
Adds a face with
faceIndex
from themesh
in the spatial index- Parameters:
faceIndex (int)
mesh (QgsMesh)
- elementType(self) QgsMesh.ElementType [source]¶
Returns the type of mesh elements that are indexed
Added in version 3.14.
- Return type:
- intersects(self, rectangle: QgsRectangle) List[int] ¶
Returns a list of face ids with a bounding box which intersects the specified
rectangle
.Note
The intersection test is performed based on the face bounding boxes only, so it is necessary to manually test the returned faces for exact geometry intersection when required.
- Parameters:
rectangle (QgsRectangle)
- Return type:
List[int]
- nearestNeighbor(self, point: QgsPointXY, neighbors: int) List[int] ¶
Returns nearest neighbors to a
point
. The number of neighbours returned is specified by theneighbours
argument.Note
The nearest neighbour test is performed based on the face bounding boxes only, so this method is not guaranteed to return the actual closest neighbours.
- Parameters:
point (QgsPointXY)
neighbors (int)
- Return type:
List[int]