Class: QgsGraph¶
Mathematical graph representation.
Methods
Add an edge to the graph, going from the fromVertexIdx to toVertexIdx. |
|
Add a vertex to the graph |
|
Returns the edge at the given index. |
|
Returns number of graph edges |
|
Finds the first edge which is the opposite of the edge with the specified index. |
|
Find vertex by associated point |
|
Returns whether the edge of the given index exists. |
|
Returns whether the vertex of the given index exists. |
|
Removes the edge at specified index. |
|
Removes the vertex at specified index. |
|
Returns the vertex at the given index. |
|
Returns number of graph vertices |
- class qgis.analysis.QgsGraph[source]¶
Bases:
object
- addEdge(self, fromVertexIdx: int, toVertexIdx: int, strategies: Iterable[Any]) int [source]¶
Add an edge to the graph, going from the
fromVertexIdx
totoVertexIdx
.- Parameters:
fromVertexIdx (int)
toVertexIdx (int)
strategies (Iterable[Any])
- Return type:
int
- addVertex(self, pt: QgsPointXY) int [source]¶
Add a vertex to the graph
- Parameters:
pt (QgsPointXY)
- Return type:
int
- edge(self, idx: int) QgsGraphEdge [source]¶
Returns the edge at the given index.
- Raises:
IndexError – if the edge is not found.
- Parameters:
idx (int)
- Return type:
- findOppositeEdge(self, index: int) int [source]¶
Finds the first edge which is the opposite of the edge with the specified index.
This represents the edge which has the same vertices as the specified edge, but the opposite direction in the graph.(I.e. the edge which starts at the “from” vertex of the specified edge and ends at the “to” vertex.)
Returns -1 if no opposite edge exists.
- Raises:
IndexError – if the edge with the specified
index
is not found.
Added in version 3.24.
- Parameters:
index (int)
- Return type:
int
- findVertex(self, pt: QgsPointXY) int [source]¶
Find vertex by associated point
- Return type:
int
- Returns:
vertex index
- Parameters:
pt (QgsPointXY)
- hasEdge(self, index: int) bool [source]¶
Returns whether the edge of the given index exists.
Added in version 3.24.
- Parameters:
index (int)
- Return type:
bool
- hasVertex(self, index: int) bool [source]¶
Returns whether the vertex of the given index exists.
Added in version 3.24.
- Parameters:
index (int)
- Return type:
bool
- removeEdge(self, index: int)[source]¶
Removes the edge at specified
index
.The incoming and outgoing edges for all graph vertices will be updated accordingly. Vertices which no longer have any incoming or outgoing edges as a result will be removed from the graph automatically.
- Raises:
IndexError – if the vertex is not found.
Added in version 3.24.
- Parameters:
index (int)
- removeVertex(self, index: int)[source]¶
Removes the vertex at specified
index
.All edges which are incoming or outgoing edges for the vertex will also be removed.
- Raises:
IndexError – if the vertex is not found.
Added in version 3.24.
- Parameters:
index (int)
- vertex(self, idx: int) QgsGraphVertex [source]¶
Returns the vertex at the given index.
- Raises:
IndexError – if the vertex is not found.
- Parameters:
idx (int)
- Return type: