A method for identifying upstream and downstream hydrological stations of a river based on existing GIS data
By using open source technologies such as pyshp, shapely and networkx, combined with graph theory algorithms, we automatically identify the topological relationship of hydrological sites upstream and downstream of rivers, solving the problem of manual search in the existing technology, and achieving efficient and accurate river network data processing.
Patent Information
- Application Number
- CN202211232776.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-10
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2042-10-10
AI Technical Summary
The existing technology lacks the means to automatically obtain the topological relationships of upstream and downstream river hydrological sites, resulting in large workload and inefficient human searches.
Using open source technologies such as pyshp, shapely and networkx, combined with graph theory algorithms, the topological relationships of hydrological sites upstream and downstream of rivers are identified through existing GIS data, a virtual topological map is constructed and upstream and downstream hydrological sites are automatically traced.
It realizes efficient and accurate identification of hydrological sites upstream and downstream of rivers, saves manual search work, is especially suitable for large river networks, improves operation speed, and becomes the basis for the digital twin of river networks.
Smart Images

Figure CN115730025B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a method for identifying upstream and downstream hydrological stations of a river channel based on existing GIS data, belonging to the field of digital twins of hydrological information. Background Art
[0002] In natural river networks, it is often necessary to understand the upstream and downstream relationships of river hydrological stations for hydrological situation analysis, flood control forecasting, and hydrological data error judgment. In recent years, the application of deep learning models in various fields and the construction of digital twins by the Ministry of Water Resources have further highlighted the importance of automatically obtaining upstream and downstream relationships and integrating with other programs.
[0003] So far, the academic and industrial circles lack a means to automatically obtain the topological relationship between upstream and downstream stations of a given station based on existing GIS data. Therefore, the inventor proposes a method for identifying upstream and downstream hydrological stations of a river channel based on existing GIS data in the present invention to automatically identify the topological relationship of river stations. Summary of the Invention
[0004] In view of the current situation that the academic and industrial circles lack a means to automatically find the topological relationship of stations along the river flow direction, the present invention proposes a method for identifying upstream and downstream hydrological stations of a river channel based on existing GIS data. By using mature open-source technologies such as pyshp, shapely, and networkx, the river network is analyzed using graph theory algorithms to obtain the upstream and downstream relationships of stations for use as infrastructure.
[0005] In order to achieve the above technical objectives, the technical solution adopted by the present invention is as follows:
[0006] A method for identifying upstream and downstream hydrological stations of a river channel based on existing GIS data, comprising the following steps:
[0007] Step 1: Obtain the longitude and latitude information of hydrological stations from a reliable hydrological station data source (such as the database of the hydrological department or any authoritative data provider), and obtain the river network vector information from a reliable river network information data source (such as HydroRIVERS or the database of any authoritative data provider). Establish a shapefile file in the form of a Point layer to store the location of hydrological stations (including *.shp, *.shx, *.prj, *.dbf files, i.e., the hydrological station layer file) and a shapefile file in the form of a LineString layer to store the river network vector map, i.e., the river network vector layer file.
[0008] Step 2: Traverse the hydrological site layer, and use the built-in functions of pythonpyshp and shapely open source packages to find the nearest river channel (river network line LineString) and the point on the river channel closest to the hydrological site (i.e., projection point) for each hydrological site in the hydrological site layer, and build the mapping relationship between all hydrological sites and their projection points, as well as the mapping relationship between the projection points and the river channels where they are located. This is the projection process. If it is the first run, a cache file will be generated. If others have provided the cache file, it will no longer be generated.
[0009] Step 3: Use the Python networkx open source package to construct a virtual topology map of the river network and projection points. The virtual topology map includes two maps: the virtual river network-hydrological station projection point map and the weighted virtual river network map. The subsequent steps are carried out through the two topology maps and the two mapping relationships obtained in the projection process of step 2.
[0010] Step 4: The user specifies a hydrological station number, chooses whether to trace upstream or downstream, and specifies the number of hydrological stations to trace (N is a positive integer and does not exceed 2). 31 -1, if not specified, it means infinite), then in the topology map obtained in step 3, all river sections will be traced back along the upstream / downstream direction specified by the user, and each river section will be traversed to a maximum of N stations; if it is the first time to run and there is no cache file, the upstream and downstream topology subgraph will be saved as an edge table file, and the upstream and downstream hydrological station topological relationship of all hydrological stations will be calculated once to generate an upstream and downstream relationship set; if others have provided the corresponding edge table file and upstream and downstream relationship set cache file, the edge table file and upstream and downstream relationship set will no longer be generated.
[0011] Step 5: The user can specify the first hydrological station and the second hydrological station by himself, and determine whether the second hydrological station is in the mainstream, tributary, or not in the upstream basin of the first hydrological station according to the upstream and downstream topological subgraph generated in step 4 (the mainstream is determined based on the principle of "the source of the river is far away").
[0012] Step 6: After the above steps are completed, save the upstream and downstream relationship set obtained in step 4 as a cache file for subsequent analysis.
[0013] Furthermore, the steps for obtaining the station location and river network vector map from a reliable data source in step 1 are as follows:
[0014] Step 1.1: Obtain the xls / xlsx / csv data file from the reliable hydrological site data source described in step 1, and manually remove invalid data (such as data that exceeds the survey range, or has null coordinates, or duplicate coordinates);
[0015] Step 1.2: Convert the data generated in Step 1.1 into a shapefile (including *.shp, *.shx, *.prj, and *.dbf files) through the Python geopandas package; if the data source already provides the site location, Steps 1.1 and 1.2 of the shapefile can be omitted, and the shapefile can be directly used.
[0016] Step 1.3: Obtain the river network vector map file from a reliable river network information data source, and use ArcGIS / QGIS to convert it from multi-part (MultiLine-String) to single-part (LineString). If it is already in single-part, this step can be omitted.
[0017] Furthermore, in Step 2, the steps to find the nearest river channel to the site and the nearest point on the river channel are as follows:
[0018] Step 2.1: Use the buffer method of Python shapely to add a limited range to a certain hydrological site in the hydrological site layer file obtained in the first step, and continuously expand the range until at least one river network line appears within the limited range of the hydrological site in the river network vector layer file. Then, for all river network lines within the limited range, calculate their distances from the current hydrological site, and take the vector of the river network line (LineString) with the smallest distance as the river section to be projected, so as to determine the upstream and downstream topological relationships.
[0019] Step 2.2: Use the built-in algorithm of shapely to directly find the projection point of the current hydrological site on the river section to be projected. If there are more than one projection points on the river section, sort them by the Euclidean distance from the projection point to the source point of the river section, and repeat this process for all river sections to be projected obtained in Step 2.1 in the river network vector layer.
[0020] Step 2.3: Build the mapping relationships between all hydrological sites and projection points, and between all projection points and all river sections to be projected. If it is the first time to run, write them into a cache file. If others have provided the cache file, this process will no longer be carried out.
[0021] Furthermore, in Step 3, two topological maps are built, and the steps to find the relationships between source sites through the topological maps and the two mapping relationships obtained in Step 2 are as follows:
[0022] Step 3.1: Connect all the projection points obtained in Step 2 with the starting point and ending point of each river section through the Python networkx open-source package to obtain a virtual river network-site projection point map. At the same time, connect the starting point and ending point of each river section and the river section length to form a weighted virtual river network map.
[0023] Step 3.2: Save the virtual river network-site projection point map and the weighted virtual river network map as cache files for subsequent analysis.
[0024] Further, the steps for finding the topological subgraph by the specified site number in Step 4 are as follows:
[0025] Step 4.1: After the user independently specifies the site number, selects the upstream and downstream directions, and the number of retraces N, use python pyshp to obtain the Point corresponding to the site number, and then determine the target node through the mapping relationship obtained in Step 2;
[0026] Step 4.2: In the virtual river network-site projection point map obtained in Step 3 or the corresponding cache file, obtain the upstream topological subgraph through the ancestor nodes of the target node in the graph, and then correspond the coordinates in the topological subgraph to the site coordinates one by one, and write the results into the site set. The maximum length of the site set is N; or obtain the downstream topological subgraph through the depth-first search tree of the target node, and also correspond the coordinates in the subgraph to the site coordinates one by one, and write the results into the site set, with a maximum length of N;
[0027] Step 4.3: Return the site set, and save the topological subgraph as a cache file for subsequent analysis.
[0028] Further, in Step 5, when specifying the second hydrological site and judging whether it is in the upstream basin of the first hydrological site and in the main stream / tributary of the upstream basin of the first hydrological site, the steps are as follows:
[0029] Step 5.1: Through the first hydrological site, obtain the topological subgraph through Step 4 or the corresponding cache file;
[0030] Step 5.2: Through the weighted virtual river network map obtained in Step 3, splice the lengths of each river section to obtain the longest weighted path and use it as the main stream;
[0031] Step 5.3: Through the two mapping relationships obtained in Step 2 or the corresponding cache file, find the corresponding hydrological site according to the projection points on all river sections of the main stream. If the second hydrological site is found, then determine whether its corresponding river section is in the main stream or the tributary according to Step 5.2. If not found, it is determined that it is not in the upstream basin.
[0032] The beneficial effects of the present invention are as follows:
[0033] The present invention only needs to construct two layer files based on the existing GIS data, and can identify the upstream and downstream hydrological sites of the river. It can greatly save the workload of manually finding the upstream and downstream hydrological stations of specific sites, and is particularly useful for large river networks and site layers, such as all river networks and hydrological stations in the nine major basins in China, such as the Songliao Basin (in actual operation, there are often hundreds of thousands of river sections), and has high accuracy and fast operation speed, and can be used as a favorable basis for the digital twin of the river network. Brief Description of the Drawings
[0034] Figure 1 It is a flowchart of the invention provided by an embodiment of the present invention;
[0035] Figure 2 It is an effect diagram of the combination of the test vector river network layer and the station layer provided by an embodiment of the present invention. Detailed Embodiment
[0036] The present invention will be further described below in conjunction with specific embodiments. The implementation includes the following steps:
[0037] Step 1: Manually specify the longitude and latitude information of the simulated hydrological station location. Use the real vector river network of the HydroRIVERS project as the river network vector information to establish a shapefile file (including *.shp, *.shx, *.prj, *.dbf files, that is, the hydrological station layer file) in the form of a Point layer to save the location of the hydrological station, and a shapefile file in the form of a LineString layer to save the river network vector map, that is, the river network vector layer file. The two layers are superimposed together, and the display effect is as Figure 2 (The lines represent the river network lines, the dots represent the hydrological stations, and the hydrological station names are referred to by digital labels), for the reviewer to check.
[0038] Step 2: Traverse the hydrological station layer. Through the built-in functions of the python pyshp and shapely open source packages, find the nearest river channel (the river network line LineString) and the nearest point on the river channel to the hydrological station (i.e., the projection point) for each hydrological station in the hydrological station layer, and construct the mapping relationship between all hydrological stations and their projection points, as well as the mapping relationship between the projection points and the river channels where they are located, which is the projection process. Specifically:
[0039] Step 2.1: Use the buffer method of pythonshapely to add a limited range to a certain hydrological station in the hydrological station layer file obtained in the first step, and continuously expand the range until at least one river network line appears within the limited range of the hydrological station in the river network vector layer file. Then, calculate the distance between all river network lines within the limited range and the current hydrological station, and take the LineString vector of the river network line with the smallest distance as the river section to be projected to determine the upstream and downstream topological relationship;
[0040] Step 2.2: Use the built-in algorithm of shapely to directly find the projection point of the current hydrological station on the river section to be projected. If there are more than one projection points on this river section, sort them by the Euclidean distance from the projection point to the source point of the river section, and repeat this process for all river sections to be projected obtained in step 2.1 in the river network vector layer;
[0041] Step 2.3: Establish the mapping relationships between all hydrological stations and projection points, and between all projection points and all river reaches to be projected.
[0042] The cache files of the mapping relationships between hydrological stations and projection points, and between projection points and the river network lines where they are located obtained in this embodiment have the following effects:
[0043]
[0044] (source refers to the longitude and latitude coordinates of hydrological stations, and point refers to the longitude and latitude coordinates of the projected points of hydrological stations obtained in Step 2.2)
[0045]
[0046] (nearest_line_wkt refers to the river network line with a projection point, and nearest_point refers to the longitude and latitude coordinates of the projected points of hydrological stations obtained in Step 2.2, which is exactly the same as the point column in the above table)
[0047] Step 3: Use the Python networkx open-source package to construct a virtual topological graph from the river network and projection points. The virtual topological graph includes two graphs: a virtual river network - hydrological station projection point graph and a weighted virtual river network graph. Perform subsequent steps based on the two topological graphs and the two mapping relationships obtained in the projection process of Step 2. Specifically:
[0048] Step 3.1: Connect all the projection points obtained in Step 2 with the starting and ending points of each river reach through the Python networkx open-source package to obtain a virtual river network - station projection point graph. At the same time, connect the starting and ending points of each river reach and the river reach length to form a weighted virtual river network graph;
[0049] Step 3.2: Save the virtual river network - station projection point graph and the weighted virtual river network graph as cache files.
[0050] The cache files corresponding to the virtual river network - station projection point graph and the weighted virtual river network graph obtained in this embodiment have the following effects:
[0051] (124.6171154674783, 44.175448800812)|(124.59791666666567, 44.16458333333265)|{}
[0052] (124.59791666666567, 44.16458333333265)|(124.5119074866849, 44.17142584664665)|{}
[0053] (124.47708333333222,44.160416666665945)|(124.47288309644105,44.16045023689056)|{}
[0054] (124.50775911793546,44.17025911793586)|(124.50239336527217,44.168749999999314)|0
[0055] (124.47877361068909,44.162106944022824)|(124.47708333333222,44.160416666665945)|{}
[0056] (124.60416666666558,44.154166666665965)|(124.59791666666567,44.16458333333265)|{}
[0057] (124.4499999999989444.13749999999933)|(124.44374999999897,44.15225655351622)|{}
[0058] (124.17499999999896.44.12083333333265)|(124.17227536566786,44.12355796766375)|{}
[0059] (124.20833333333226,44.12083333333265)|(124.20478225272018,44.124384413944746)|{}
[0060] (124.56874999999897,44.114583333332625)|(124.52291666666557,44.135416666665954)|{}
[0061] (124.52291666666557,44.135416666665954)|(124.50624999999891,44.13958333333266)|{}
[0062] (124.50624999999891, 44.13958333333266)|(124.47708333333222, 44.160416666665945)|{}
[0063] (124.61249999999896, 44.11041666666596)|(124.56874999999897, 44.114583333332625)|{}
[0064] (124.76458333333224, 44.12291666666598)|(124.80492778258905, 44.114583333332625)|{}
[0065] (The above figure shows the data corresponding to the virtual river network - site projection point map. For each row, the first set of coordinates in parentheses is the longitude and latitude of the starting point of the edge, and the second set of coordinates in parentheses is the longitude and latitude of the ending point of the edge)
[0066] (124.6171154674783, 44.175448800812)|(124.59791666666567, 44.16458333333265)|0.02369942480408072
[0067] (124.59791666666567, 44.16458333333265)|(124.5119074866849, 44.17142584664665)|0.10265056054188054
[0068] (124.47708333333222, 44.160416666665945)|(124.47288309644105, 44.16045023689056)|0.004214142133493249
[0069] (124.50775911793546, 44.17025911793586)|(124.50239336527217, 44.168749999999314)|0.005990849779834087
[0070] (124.47877361068909, 44.162106944022824)|(124.47708333333222, 44.160416666665945)|0.0023904131622650756
[0071] (124.60416666666558,44.154166666665965)|(124.59791666666567,44.16458333333265)|0.013005501431458975
[0072] (124.44999999999894,44.13749999999933)|(124.44374999999897,44.15225655351622)|0.017345388281698817
[0073] (124.17499999999896,44.12083333333265)|(124.17227536566786,44.12355796766375)|0.0038532148235518484
[0074] (124.20833333333226,44.12083333333265)|(124.20478225272018,44.124384413944746)|0.005021986362699364
[0075] (124.56874999999897,44.114583333332625)|(124.47708333333222,44.160416666665945)|0.11309223176556264
[0076] (124.61249999999896,44.11041666666596)|(124.56874999999897,44.114583333332625)|0.04547588984320829
[0077] (124.76458333333224,44.12291666666598)|(124.80492778258905,44.114583333332625)|0.04724800862970576
[0078] (124.74166666666562,44.095833333332614)|(124.76458333333224,44.12291666666598)|0.03901650429448847
[0079] (124.59999999999891, 44.08541666666597)|(124.56874999999897, 44.114583333332625)|0.048212782549389745
[0080] (The above figure shows the data corresponding to the weighted virtual river network diagram. For each row, the first pair of coordinates in parentheses is the longitude and latitude coordinates of the starting point of the edge, the second pair is the longitude and latitude coordinates of the ending point of the edge, and the third data is the length of the edge, which is also the edge weight.)
[0081] Step 4: The user independently specifies a hydrological station number, chooses whether to trace upstream or downstream, and simultaneously independently specifies the number N of hydrological stations to be traced, where N is 6. In the topological graph obtained in Step 3, trace all river sections in the upstream / downstream direction specified by the user, and each river section is traversed up to N stations at most. If it is the first run (this embodiment will take into account both the first and subsequent runs) and there is no cache file, the upstream and downstream topological subgraphs will be saved as an edge table file, and at the same time, the topological relationships between the upstream and downstream hydrological stations of all hydrological stations will be calculated once, generating an upstream and downstream relationship set. If someone else has provided the corresponding edge table file and the upstream and downstream relationship set cache file, the edge table file and the upstream and downstream relationship set will not be generated again. Specifically:
[0082] Step 4.1: After the user independently specifies the station number, selects the upstream / downstream direction, and the number N of stations to be traced, use python pyshp to obtain the Point corresponding to the station number, and then determine the target node through the mapping relationship obtained in Step 2;
[0083] Step 4.2: In the virtual river network - station projection point diagram obtained in Step 3 or the corresponding cache file, obtain the upstream topological subgraph through the ancestor nodes of the target node in the graph, and then map the coordinates in the topological subgraph to the station coordinates one by one, and write the results into the station set, with the maximum length of the station set being N; or obtain the downstream topological subgraph through the depth - first search tree of the target node, and also map the coordinates in the subgraph to the station coordinates one by one, and write the results into the station set, with the maximum length being N;
[0084] Step 4.3: Return the station set, and save the topological subgraph as a cache file for subsequent analysis.
[0085] In this embodiment, the Windows command line is used to test Step 4 to trace hydrological stations upstream or downstream:
[0086] (1) First, without relying on the cache file, trace N hydrological stations for all river channels upstream of the specified hydrological station:
[0087]
[0088] -- The `nodes_path` configuration item: The absolute path where the hydrological station layer file is located;
[0089] -- The `river_path` configuration item: The absolute path where the river network vector layer is located;
[0090] -- The `cur_sta` configuration item: Specify that the hydrological station number is 0;
[0091] -- The `upstream` configuration item: Specify to trace upstream;
[0092] -- The `outdated` configuration item: Identify whether the data is outdated. If it is `True`, it represents the first run or the data has expired and needs to be recalculated. The program will recalculate the topological relationship from the two layer files. If not specified or set to `False`, the program needs to read the topological relationship from the existing cache file (such as distributed by others or generated by a previously run program).
[0093] -- The `cutoff` configuration item: Specify the number of traced stations `N` mentioned in step 4.1. The result in this example is 6, indicating that each upstream tributary outputs at most 6 stations;
[0094] The output result is shown in the following figure:
[0095]
[0096] In each item separated by commas, "sta" refers to the hydrological station name, and the following number represents the hydrological station number. Due to the upstream relationship, the last item in each row is the user-specified hydrological station, and the row content represents the river flow sequence relationship from the first hydrological station to the last hydrological station.
[0097] (2) Next, perform the same analysis using the cache file:
[0098]
[0099] -- The `cache_dir` configuration item: The path where the cache file is placed;
[0100] The output topological relationship is exactly the same as that in (1), but the order of the output rows will be different.
[0101] (3) Next, obtain the list of downstream stations of a specific station:
[0102]
[0103] The output result indicates that the downstream nodes of station 10 are 10 → 8 → 7 → 6 → 5 → 4 → 2 → 1 → 0, which is the same as the output result in step 5 of the embodiment.
[0104] (4) Change "outdated" to True and perform the same analysis. The result is the same as in (3):
[0105]
[0106] Step 5: The user can specify the first hydrological station and the second hydrological station by themselves. According to the upstream and downstream topological subgraph generated in Step 4, determine whether the second hydrological station is on the main stream, tributary, or not in the upstream basin of the first hydrological station (the "source is the farthest" principle is adopted for the main stream determination). Specifically:
[0107] Step 5.1: Through the first hydrological station, obtain the topological subgraph via Step 4 or the corresponding cache file;
[0108] Step 5.2: Through the weighted virtual river network graph obtained in Step 3, splice the lengths of each river section to obtain the longest weighted path and use it as the main stream;
[0109] Step 5.3: Through the two mapping relationships obtained in Step 2 or the corresponding cache file, find the corresponding hydrological stations according to the projection points on all river sections of the main stream. If the second hydrological station is found, then determine whether its corresponding river section is in the main stream or tributary according to Step 5.2. If not found, it is determined that it is not in the upstream basin.
[0110] In this embodiment, the Windows command line is used to test the judgment of the main stream and tributary of the second hydrological station in the upstream basin of the first hydrological station in Step 5:
[0111]
[0112] --up_sta: The second hydrological station specified by the user. The meaning of this command is: Judge whether hydrological station 10 is in the upstream basin of hydrological station 0. If so, display the main stream / tributary where it is located. The output result shows that hydrological station 10 is in the tributary of the upstream basin of hydrological station 0, and the path is 10→8→7→6→5→4→2-→1→0.
[0113] Next, change "outdated" to True and perform the same analysis. The result is the same:
[0114]
[0115] Step 6: Save the upstream and downstream relationship set obtained in Step 4 as a cache file for analysis. In this embodiment, a relationship set file is generated, and the effect is as follows:
[0116] upstream: ′sta52′, ′sta51′, ′sta30′, ′sta11′, ′sta3′
[0117] upstream: 'sta14','sta13','sta11','sta3'
[0118] upstream: 'sta15','sta14','sta13','sta11','sta3'
[0119] upstream: 'sta48','sta31','sta30','sta11','sta3'
[0120] upstream: 'sta51','sta30','sta11','sta3'
[0121] downstream:'sta3','sta1','sta0'
[0122] upstream:'sta6','sta5','sta4'
[0123] upstream:'sta8','sta7','sta6','sta5','sta4'
[0124] upstream:'sta10','sta8','sta7','sta6','sta5','sta4'
[0125] upstream:'sta9','sta8','sta7','sta6','sta5','sta4'
[0126] downstream:'sta4','sta2','sta1','sta0'
[0127] The "upstream" line refers to all hydrological stations upstream of the last hydrological station number in that line, and the "downstream" line refers to all hydrological stations downstream of the first hydrological station number in that line.
[0128] In summary, the present invention allows users to specify requirements relatively freely, obtain information on other required hydrological stations upstream and downstream of a specific hydrological station. The cache file can improve the operation speed and can also be given to others for analysis. Through the present invention, it can help users automatically, efficiently and collaboratively find the downstream relationship of hydrological stations under complex river network conditions and carry out subsequent development, eliminating the difficulty of finding hydrological stations by the naked eye and saving the communication cost of multi-person collaboration, and can become an important basis for the digital twin work of the river network.
[0129] The above-described embodiments merely illustrate the implementation manners of the present invention, but should not be construed as limiting the scope of the present invention. It should be noted that for those skilled in the art, without departing from the concept of the present invention, several modifications and improvements can still be made, and these all fall within the protection scope of the present invention.
Claims
1. A method for identifying upstream and downstream hydrological stations of a river channel based on existing GIS data, characterized in that, The following steps are involved: Step 1: Obtain the latitude and longitude information of the hydrological station from a reliable hydrological station data source, and obtain the river network vector information from a reliable river network information data source, and create a shapefile file that exists in the form of a Point layer to save the location of the hydrological station and a shapefile file that exists in the form of a LineString layer to save the river network vector, that is, the river network vector layer file; Step 2: Traverse the hydrological site layer, and use the built-in functions of Python PySHP and Shapely open source packages to find the nearest river channel and the point on the river channel closest to the hydrological site, i.e., the projection point, for each hydrological site in the hydrological site layer. Build the mapping relationship between all hydrological sites and their projection points, and the mapping relationship between the projection points and the river channels where they are located. This is the projection process. If it is the first run, a cache file will be generated. If others have provided the cache file, it will not be generated. Step 3: Use the Python networkx open source package to construct a virtual topology map of the river network and projection points. The virtual topology map includes two maps: a virtual river network-hydrological station projection point map and a weighted virtual river network map. The subsequent steps are carried out through the two topology maps and the two mapping relationships obtained in the projection process of step 2; Step 4: The user specifies a hydrological station number, chooses to trace upstream or downstream, and specifies the number of hydrological stations to be traced N. In the topological map obtained in step 3, all river sections are traced along the upstream / downstream direction specified by the user, and each river section is traversed to a maximum of N stations; If it is the first time to run and there is no cache file, the upstream and downstream topological subgraphs will be saved as edge table files, and the upstream and downstream topological relationships of all hydrological stations will be calculated to generate an upstream and downstream relationship set; If the corresponding edge list file and the cache file of the upstream and downstream relationship set have already been provided by others, the edge list file and the upstream and downstream relationship set will not be generated again; N is a positive integer and does not exceed 2 31 -1; Step 5: The user can specify the first hydrological station and the second hydrological station by himself. According to the upstream and downstream topological subgraph generated in step 4, determine whether the second hydrological station is in the mainstream, tributary or not in the upstream basin of the first hydrological station. The mainstream is determined by the principle of "the source of the river is far away"; Step 6: Save the upstream and downstream relationship set obtained in step 4 as a cache file for subsequent analysis.
2. The method for identifying upstream and downstream hydrological stations of a river channel based on existing GIS data according to claim 1, wherein The steps for obtaining the station location and river network vector map from a reliable data source in step 1 are as follows: Step 1.1: Obtain the xls / xlsx / csv data file from the reliable hydrological site data source described in step 1, and manually remove invalid data, including data that exceeds the survey range, or has null coordinates, or has duplicate coordinates; Step 1.2: Convert the data generated in step 1.1 into a shapefile using the python geopandas package; If the data source already provides the site location, the shapefile file can skip steps 1.1 and 1.2 and use the shapefile file directly; Step 1.3: Obtain river network vector graphics files from reliable river network information data sources, and use ArcGIS / QGIS to convert them from multi-component MultiLine-String to single-component LineString. If it is already a single component, this step can be omitted.
3. The method for identifying upstream and downstream hydrological stations of a river channel based on existing GIS data according to claim 1, wherein, The steps for finding the river closest to the site and the nearest point on the river in step 2 are as follows: Step 2.1: Use the buffer method of Python Shapely to add a limited range to a hydrological station in the hydrological station layer file obtained in the first step, and continue to expand the range until at least one river network line appears in the limited range of the hydrological station in the river network vector layer file. Then, for all the river network lines in the limited range, calculate their distance from the current hydrological station, take the river network line LineString vector with the smallest distance as the river section to be projected, and determine the upstream and downstream topological relationship; Step 2.2: Use Shapely's built-in algorithm to directly find the projection point of the current hydrological station on the river section to be projected. If there is more than one projection point on the river section, sort them by the Euclidean distance from the projection point to the source point of the river section. Repeat this process for all the river sections to be projected obtained in step 2.1 in the river network vector layer. Step 2.3: Build the mapping relationship between all hydrological stations and projection points, and all projection points and all river sections to be projected. If it is the first time to run, it will be written into the cache file. If others have provided the cache file, this process will not be repeated.
4. A method for identifying upstream and downstream hydrological stations of a river channel based on existing GIS data according to claim 1, characterized in that, In step 3, two topology maps are constructed, and the steps for finding the relationship between source sites through the topology maps and the two mapping relationships obtained in step 2 are as follows: Step 3.1: Connect all the projection points obtained in step 2 with the starting point and end point of each river section through the Python NetworkX open source package to obtain a virtual river network-site projection point diagram. At the same time, connect the starting point and end point of each river section and the length of the river section to form a weighted virtual river network diagram; Step 3.2: Save the virtual river network-site projection point map and weighted virtual river network map as cache files for subsequent analysis.
5. A method for identifying upstream and downstream hydrological stations of a river based on existing GIS data according to claim 1, characterized in that, In step 4, the steps of finding the topology submap by specifying the site number are as follows: Step 4.1: After the user specifies the site number, selects the upstream and downstream directions and the traceability quantity N, use pythonpyshp to get the Point corresponding to the site number, and then determine the target node through the mapping relationship obtained in step 2; Step 4.2: In the virtual river network-site projection point graph obtained in step 3 or the corresponding cache file, obtain the upstream topology subgraph through the ancestor node of the target node in the graph, and then correspond the coordinates in the topology subgraph to the site coordinates one by one, and write the result into the site set, and the maximum length of the site set is N; or obtain the downstream topology subgraph through the depth-first search tree of the target node, and similarly correspond the coordinates in the subgraph to the site coordinates one by one, and write the result into the site set, and the maximum length is N; Step 4.3: Return to the site collection and save the topology submap as a cache file for subsequent analysis.
6. The method for identifying upstream and downstream hydrological stations of a river channel based on existing GIS data according to claim 1, wherein, In step 5, a second hydrological station is specified, and the judgment on whether it is in the upstream basin of the first hydrological station, in the main stream / tributary of the upstream basin of the first hydrological station is as follows: Step 5.1: Through the first hydrological station, obtain the topological subgraph via step 4 or the corresponding cache file; Step 5.2: Through the weighted virtual river network graph obtained in step 3, splice the length of each river section to obtain the longest weighted path and use it as the main stream; Step 5.3: Through the two mapping relationships obtained in step 2 or the corresponding cache file, find the corresponding hydrological station according to the projection points on all river sections of the main stream. If the second hydrological station is found, then determine whether its corresponding river section is in the main stream or the tributary according to step 5.
2. If not found, it is determined that it is not in the upstream basin.
Citation Information
Patent Citations
Complex riverway terrain quick and fine generation method
CN108010103A
Method and system for optimizing obstacle avoidance path of offshore wind farm current collection system
WO2018010471A1
Cited By
Method and system for automatically identifying upstream and downstream relationship of observation station on line
CN117971997A