Documentation¶
Classes¶
-
class
Edge
(self)¶ Class of an Edge of the river network. Instantiated with attributes of the features of the layer of the network.
-
__init__
(self, geom, id_edge, node_start, node_end)¶ Constructor of the class
Parameters: - geom – Geometry of the feature (line)
- id_edge – ID of the edge (same as the ID of the feature; integer)
- node_start – Start node of the edge
- node_end – End node of the edge
-
copy_edge
(self)¶ Copy an
Edge
object. Create anEdge
object that has the same attributes.Returns: Copy of the edge Return type: Edge object
-
-
class
Node
(self)¶ Class of a
Node
of the river network. Instantiated with attributes of the features of the layer of the network.
-
__init__
(self, geom, id_node)¶ Constructor of the class
Parameters: - geom – Geometry of the feature (point)
- id_node – ID of the node (ID of one of its connected edges and number 1 or 2 concatenated)
-
copy_node
(self)¶ Copy a
Node
object. Create a Node object that has the same attributes.Returns: Copy of the node Return type: Node object
-
class
Island
(self)¶ Class of an
Island
of the river network.Instantiated with the edges of the island.
-
__init__
(self, island_edges)¶ Constructor of the class
Parameters: island_edges – Edges that make up the island (Edge objects) Island_edges type:
-
copy_island
(self)¶ Copy an
Island
object.Create an
Island
object that has the same attributes.Returns: Copy of the island Return type: Island object
-
compute_edges_in_out
(self)¶ Compute the incoming and outgoing edges of the island.
Set attributes edges_in and edges_out from the edges of the island and their connections to the network.
-
compute_edges_in
(self)¶ Compute the incoming edges of the island.
Set attribute edges_in from the edges of the island and their connections to the network.
-
compute_edges_out
(self)¶ Compute the outgoing edges of the island.
Set attribute edges_out from the edges of the island and their connections to the network.
-
Instanciations of the classes¶
-
create_edges_nodes
(features, name_column, alt_init_column, alt_final_column)¶ Instantiate all the
Edge
andNode
objects that make up the river network.The name of the river and the altitudes are attributes of the objects if the names of the columns are given in arguments.
Parameters: - features (list of QgsFeatures objects) – list of all the features of the river network layer
- name_column (string) – name of the column of the name of the river (selected by the user, empty string if not selected)
- alt_init_column (string) – name of the column of the initial altitude (selected by the user, empty string if not selected)
- alt_final_column (string) – name of the column of the final altitude (selected by the user, empty string if not selected)
Returns: list of all the edges, list of all the nodes making up the river network
Return type: list of Edge objects, list of Node objects
-
set_edges_connected_nodes
(nodes, edges)¶ Fill the lists of incoming and outgoing edges of the input nodes (lists are attributes of Node objects).
The connection between nodes and edges is given by the start node and end node of each edge.
Parameters: - nodes (list of Node objects) – list of all the nodes making up the river network
- edges (list of Edge objects) – list of all the edges making up the river network
-
create_islands
(streams_in_islands)¶ Instanciation of
Island
objects from the list of the edges that make up the island.The instantiated objects are stored as attributes of the edges that belong to the island.
Parameters: streams_in_islands (list of lists of Edge objects) – edges that belong to the island
Correct edges directions¶
-
test_direction
(edges, nodes)¶ Test the direction of edges and return the list of abnormal edges (probable wrong direction).
Uses altitudes if known or studies links in graph if altitude is unknown.
Parameters: - edges (list of Edge objects) – list of all the edges making up the river network
- nodes (list of Node objects) – list of all the nodes making up the river network
Returns: list of abnormal edges
Return type: list of Edge objects
-
is_node_abnormal
(node)¶ Test if a node is abnormal, ie if all its connected edges are in the same direction (all incoming or all outgoing edges) and the node is not a source nor a sink (it has more than one incoming or outgoing edge). A node that is not a source nor a sink should indeed have at least one incoming edge and one outgoing edge (unless it is a multiple source or sink).
Returns True if the node is regarded as abnormal.
Parameters: node (Node object) – node to test
-
next_node_of_edge
(node, edge)¶ Return the node of the edge that is not the input node.
Parameters: - node (Node object) – current node
- edge (Edge object) – current edge
Returns: next node of the edge
Return type: Node object
-
reverse
(edge)¶ Reverse an Edge object. The method swaps the nodes of the edge, updates the incoming and outgoing edges lists of the nodes, reverses the geometry of the edge and updates the attribute edge.reverse to True. Only the object is altered, the input layer remains unchanged.
Parameters: edge (Edge object) – edge to reverse
-
reverse_all_edges
(edges_to_reverse)¶ Reverse edges of the input list (call reverse(edge) method).
Parameters: edges_to_reverse (list of Edge objects) – list of edges to reverse
-
edges_to_features
(list_edges, input_layer)¶ Transform a list of Edges objects into a list of the corresponding features of the layer.
Parameters: - list_edges (list of Edge objects) – list of the edges corresponding to the desired features
- input_layer (QgsVectorLayer object) – layer of the features (and the corresponding edges)
Returns: list of features
Return type: list of QgsFeatures objects
-
features_to_edges
(list_features, edges)¶ Transform a list of QgsFeatures objects into a list of the corresponding Edge objects of the layer.
Parameters: - list_features (list of QgsFeatures objects) – list of the features corresponding to the desired edges
- input_layer (QgsVectorLayer object) – layer of the features (and the corresponding edges)
Returns: list of edges
Return type: list of Edge objects
Sources and sinks¶
-
find_sources_sinks
(edges)¶ Find source edges and sink edges of the network.
A source edge is an edge exiting a node that is only connected to this edge. A sink edge is an edge entering a node that is only connected to this edge.
Parameters: edges (list of Edge objects) – list of all the edges making up the river network Returns: list of source edges, list of sink edges Return type: list of Edge objects, list of Edge objects
Island detection¶
-
detect_islands
(stream_layer, edges)¶ Detect islands in the network. Return a list of lists of the edges that make up each island.
Parameters: - stream_layer (QgsVectorLayer object) – layer of the river network
- edges (list of Edge objects) – list of all the edges that make up the river network
Returns: list of lists of edges of the islands
Return type: list of lists of Edge objects
-
polygonize
(input_layer, name="temp")¶ Island detection algorithm. If there is no island, return None.
Parameters: - input_layer (QgsVectorLayer object) – layer of the river network
- name (string) – name of the layer if displayed
Returns: layer of faces of the network (islands, polygons)
Return type: QgsVectorLayer object
-
create_layer_geom
(list_geom, crs, name="temp")¶ Create a Polygon layer with the input list of geometries (must be polygons).
Parameters: - list_geom (list of QgsGeometry) – list of polygons
- crs (string (format Wkt)) – the crs of the output layer
- name (string) – (optional) Name of the layer to display. Default = “temp”
Returns: layer of polygons
Return type: QgsVectorLayer object
-
iterator_to_list(iterator):
Transform the input iterator into a list.
Parameters: iterator (iterator) – the iterator to convert Returns: the list of the values of the iterator Return type: list
-
aggregate
(listFeatures)¶ Aggregate the geometries of the input list of features into one geometry.
Parameters: listFeatures (list of QgsFeatures objects) – features to aggregate Returns: the aggregated geometry Return type: QgsGeometry object
-
multi_to_single
(geom)¶ Transform the input multi-polygon into a list of single-polygons.
Parameters: geom (QgsGeometry object) – multi-polygon Returns: list of the single geometries Return type: list of QgsGeometry objects
-
relate_stream_island
(stream_layer, island_layer)¶ Return the streams inside or delimiting islands. The topology is defined by DE-9IM matrices.
Parameters: - stream_layer (QgisVectorLayer object (lines)) – the layer of the river network
- island_layer (QgisVectorLayer object (polygons)) – the layer of the islands
Returns: list of lists of all the streams that make up the islands
Return type: list of lists of QgisFeatures objects
-
merge_successive_islands_streams
(streams_in_island_list)¶ Compute successive islands.
Successive islands are islands that are not adjacent, and there is no edge between them (that does not belong to an island). The topology is defined by a DE-9IM matrix. Successive islands are merged into one complex island: lists of edges of successives islands are concatenated into one list. Return the list of lists of features (edges) of the islands.
Parameters: streams_in_island_list (list of lists of QgisFeatures objects) – list of lists of all the streams that make up the islands Returns: list of lists of all the streams that make up the islands, successive islands merged Return type: list of lists of QgisFeatures objects
-
merge_duplicate
(merged_streams_in_island_list)¶ Merge lists that have at least one common element into one list.
Parameters: merged_streams_in_island_list (list of lists) – list of lists to test and merge Returns: list of merged lists Return type: list of lists
Orders¶
-
compute_stroke
(dict_strokes, edge, list_incoming_edges)¶ Compute the stroke of the input edge. Return the ID of the stroke.
Parameters: - dict_strokes (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built {key= stroke ID: values= list of the edges of the stroke}
- edge (Edge object) – edge of which the stroke is computed
- list_incoming_edges (list of Edge objects) – list of the incoming edges of the input edge
Returns: ID of the stroke of the input edge
Return type: integer
-
compute_length
(stroke)¶ Return the total length of a stroke (sum of the lengths of the geometries of the edges that make up the stroke).
Parameters: stroke (list of Edge objects) – list of edges
-
compute_angle(edge_in, edge_out):
Compute the angle formed by edge_in and edge_out, edge_in entering the node edge_out exits.
Parameters: - edge_in (Edge object) – one side of the angle
- edge_out (Edge object) – one side of the angle
-
azimuth_angle(node_start, node_end):
Compute the azimuth of a line defined by its start node and its end node.
Parameters: - node_start (QgsPointXY object) – origin of the line
- node_end (QgsPointXY object) – end of the line
-
compute_stroke_of_island
(dict_strokes, island, incoming_edges_island)¶ Compute the stroke of the island. Return the ID of the stroke.
Parameters: - dict_strokes (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built {key= stroke ID: values= list of the edges of the stroke}
- island (Island object) – island of which the stroke is computed
- incoming_edges_island (list of Edge objects) – list of the incoming edges of the island
Returns: ID of the stroke of the input edge
Return type: integer
-
compute_stroke_outgoing_island
(dict_strokes, dict_forks, island_id_stroke, outgoing_edges_island)¶ Compute the stroke of the outgoing edges of the island. Set the attribute id_stroke of the edges.
Parameters: - dict_strokes (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built {key= stroke ID: values= list of the edges of the stroke}
- dict_forks (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built that split {key= upstream stroke ID: values= list of stroke IDs after the stroke}
- island_id_stroke (integer) – stroke ID of the island
- outgoing_edges_island (list of Edge objects) – list of the outgoing edges of the island
-
is_upstream_processed
(incoming_edges, edges_to_process)¶ Check if all incoming edges have been processed.
Return True if processed.
Parameters: - incoming_edges (list of Edge objects) – list of edges to check (incoming edges of a current edge)
- edges_to_process (list of Edge objects) – list of edges left to process
-
process_network
(edges, sources_edges, orders_to_compute, edges_to_process, dict_strokes, dict_strokes_in_island, dict_forks)¶ Compute stream orders: Strahler, Shreve and / or Horton, according to the selection of the user.
The computed orders are attributes of the Edge objects.
Parameters: - edges (list of Edge objects) – list of all the edges making up the river network
- sources_edges (list of Edge objects) – list of all source edges of the river network
- orders_to_compute (list of strings) – list of the orders to compute (selected by the user)
- edges_to_process (list of Edge objects) – list of the edges left to process
- dict_strokes (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built (except edges of islands) {key= stroke ID: values= list of the edges of the stroke}
- dict_strokes_in_island (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built of edges in islands ; {key= stroke ID: values= list of the edges of the stroke}
- dict_forks (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built that split {key= upstream stroke ID: values= list of stroke IDs after the stroke}
-
is_in_loop
(left_edge, edges_to_process)¶ Test if an edge is connected to a loop in the network. Return the edges of the loop in a list (return an empty list if no loop was detected).
Parameters: - left_edge (Edge object) – edge to test (could not be processed by process_network)
- edges_to_process (list of Edge objects) – list of edges left to process
Returns: list of the edges of the loop (or empty list if no loop)
Return type: list of Edge objects
-
process_loop
(edges_in_loop, orders_to_compute, edges_to_process, dict_strokes_in_island)¶ Process edges of a loop.
Their order and their stroke take the same value. The orders are computed with orders of the incoming edges of the edges of the loop that are known (regular Strahler or Shreve, only on already processed incoming edges). The stroke is the stroke of the island (any loop is an island).
Parameters: - edges_in_loop (list of Edge objects) – list of the edges of the loop
- orders_to_compute (list of strings) – list of the orders to compute (selected by the user)
- edges_to_process (list of Edge objects) – list of edges left to process
- dict_strokes_in_island (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built of edges in islands ; {key= stroke ID: values= list of the edges of the stroke}
Returns: indicate if the loop was successfully processed (can be processed only if incoming edges were already processed)
Return type: boolean
-
merge_strokes
(dict_strokes, dict_strokes_in_island, dict_forks)¶ Merge the strokes of the islands and of the forks with the main stroke.
Parameters: - dict_strokes (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built (except edges of islands) ; {key= stroke ID: values= list of the edges of the stroke}
- dict_strokes_in_island (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built of edges in islands ; {key= stroke ID: values= list of the edges of the stroke}
- dict_forks (dictionary {integer:list of Edge objects}) – dictionary of the strokes already built that split ; {key= upstream stroke ID: values= list of stroke IDs after the stroke}
-
compute_horton
(dict_strokes)¶ Compute the Horton order using the input strokes.
The computed orders are attributes of the Edge objects.
Parameters: dict_strokes (dictionary {integer:list of Edge objects}) – dictionary of all the strokes built, except edges in islands ; {key= stroke ID: values= list of the edges of the stroke}
Write in table¶
-
update_table
(input_layer, orders_to_compute, field_reverse, edges)¶ Updates the table of the layer by adding a column named like the name of the order and filling it with the orders calculated before.
Updates the table with a field “reversed” if the user selected the option (True if the edge has been reversed for the computation of the orders).
Parameters: - input_layer (QgsVectorLayer object) – layer of the river network
- orders_to_compute (list of strings) – list of the orders to compute (selected by the user)
- field_reverse (boolean) – field reversed is added to the table (selected by the user))
- edges (list of Edge objects) – list of all the edges making up the river network
Dialog messages¶
-
show_field_created_successfully
()¶ Display a message box that indicates when the input layer has been updated.
-
show_message_no_stream_order_selected
()¶ Display a message box that indicates when no stream order was checked for computation by the user.