Class: QgsGraph¶
- class qgis.analysis.QgsGraph¶
Bases:
sip.wrapper
Mathematical graph representation
New in version 3.0.
QgsGraph() Constructor for QgsGraph.
QgsGraph(
QgsGraph
)Methods
Add an edge to the graph, going from the
fromVertexIdx
totoVertexIdx
.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
- addEdge(self, fromVertexIdx: int, toVertexIdx: int, strategies: Iterable[Any]) int ¶
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 ¶
Add a vertex to the graph
- Parameters
pt (QgsPointXY) –
- Return type
int
- edge(self, idx: int) QgsGraphEdge ¶
Returns the edge at the given index.
- Raises
IndexError – if the edge is not found.
- Parameters
idx (int) –
- Return type
- edgeCount(self) int ¶
Returns number of graph edges
- Return type
int
- findOppositeEdge(self, index: int) int ¶
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.
New in version 3.24.
- Parameters
index (int) –
- Return type
int
- findVertex(self, pt: QgsPointXY) int ¶
Find vertex by associated point
- Return type
int
- Returns
vertex index
- Parameters
pt (QgsPointXY) –
- hasEdge(self, index: int) bool ¶
Returns whether the edge of the given index exists.
New in version 3.24.
- Parameters
index (int) –
- Return type
bool
- hasVertex(self, index: int) bool ¶
Returns whether the vertex of the given index exists.
New in version 3.24.
- Parameters
index (int) –
- Return type
bool
- removeEdge(self, index: int)¶
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.
New in version 3.24.
- Parameters
index (int) –
- removeVertex(self, index: int)¶
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.
New in version 3.24.
- Parameters
index (int) –
- vertex(self, idx: int) QgsGraphVertex ¶
Returns the vertex at the given index.
- Raises
IndexError – if the vertex is not found.
- Parameters
idx (int) –
- Return type
- vertexCount(self) int ¶
Returns number of graph vertices
- Return type
int