Method and system for batch and rapid extraction of basin boundary based on GIS and python, device, medium

By using a GIS and Python-based approach, watershed boundaries are generated from DEM data and cross-sectional line extension models. This solves the problem of low efficiency in small watershed boundary extraction in traditional methods and enables rapid batch extraction and efficient generation of watershed boundaries.

CN122152956APending Publication Date: 2026-06-05POWER CHINA KUNMING ENG CORP LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
POWER CHINA KUNMING ENG CORP LTD
Filing Date
2026-03-26
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Traditional methods are inefficient in extracting watershed boundaries in small watersheds, making it difficult to meet the needs of batch processing and rapid deployment. In particular, in flood risk mapping and disaster prevention and mitigation work, existing GIS technology requires manual determination of the watershed outlet location, which is inefficient.

Method used

Using a GIS and Python-based approach, the underlying data of the target watershed area surface layer is extracted from DEM data. The cross-section line is determined to intersect with the simulated river network. A cross-section line extension model is established, the watershed outlet point is generated, and the watershed boundary is generated based on the intersection point data.

Benefits of technology

It enables rapid extraction of small watershed boundaries in batches, significantly improving work efficiency and reducing the error rate of manual operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122152956A_ABST
    Figure CN122152956A_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of hydrological analysis, in particular to a method and system for batch rapid extraction of basin boundaries based on GIS and Python, equipment and medium, the method provided by the present application mainly includes obtaining DEM data of a target basin, extracting underlying data of a target basin area surface layer based on the DEM data, obtaining a plurality of cross-section lines corresponding to the current simulated river network in the database, judging whether the current cross-section line intersects with the closest river in the simulated river network, if intersecting, saving the current intersection point data, generating a basin outlet point based on the plurality of intersection point data, and obtaining the basin boundary through the basin outlet point. Through the above method, based on the generated intersection points with key information as the basin outlet, batch small basin boundary extraction can be realized, the work efficiency is significantly improved, and the error rate of manual operation is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of hydrological analysis technology, and more specifically, to a method, system, device, and medium for rapid batch extraction of watershed boundaries based on GIS and Python. Background Technology

[0002] In hydrological analysis and calculation, the extraction of small watershed boundaries is a fundamental task, affecting the calculation of watershed floods and runoff. Its applications are widespread, especially with the vigorous development of flood risk mapping, flash flood early warning, and disaster prevention and mitigation efforts in recent years, which have placed higher demands on the batch and speed of small watershed hydrological calculations. Traditional methods rely on measurements based on collected topographic contour lines, which is inefficient; even skilled workers struggle to extract 10 small watershed boundaries per day. While GIS technology allows for automatic watershed extraction based on DEM-processed data, it still requires manual determination of watershed outlet locations, resulting in relatively low efficiency. Summary of the Invention

[0003] The purpose of this invention is to provide a method, system, device, and medium for rapid batch extraction of watershed boundaries based on GIS and Python, in order to solve the above-mentioned problems in the prior art.

[0004] This invention is achieved through the following technical solution:

[0005] A method for rapid batch extraction of watershed boundaries based on GIS and Python, comprising: Obtain DEM data of the target watershed, and extract the bottom layer data of the target watershed area surface layer based on the DEM data. The bottom layer data includes simulated river network data and raster data. Obtain several cross-sectional lines corresponding to the current simulated river network in the database, determine whether the current cross-sectional line intersects with the closest river in the simulated river network, and if they intersect, save the current intersection point data; If they do not intersect, then establish a cross-section line extension model, output the data of the cross-section line to be extended based on the cross-section line extension model, and obtain the intersection point; The watershed exit point is generated based on several intersection point data, and the watershed boundary is generated based on the watershed exit point.

[0006] Preferably, the underlying data of the target watershed area surface layer extracted based on DEM data includes: The GIS module is used to fill depressions in the DEM data, calculate the water flow direction grid and the cumulative runoff grid, and obtain various types of grid data in the grid. Set a confluence threshold and extract simulated river network grids based on the confluence threshold.

[0007] Preferably, the grid for calculating water flow direction includes: Select the target center pixel as the grid for calculating the water flow direction, and obtain the slope of the 8 adjacent grids of the target pixel;

[0008] In the formula, For slope, The elevation of the current raster. For the first The elevation of one of the neighbors, For distance; Select the grid with the steepest slope as the target flow direction grid, and set the direction encoding value of the current grid to point to the target flow direction grid to obtain the current water flow direction of the grid.

[0009] Preferably, the bus cumulative amount grid includes: Initialize the flow accumulation grid, obtain the flow direction of each grid, and add the flow of each grid into the grid in the indicated direction according to the flow direction; Traverse all grids from highest to lowest elevation to obtain the cumulative flow of each grid.

[0010] Preferably, the establishment of the cross-sectional line extension model includes: Obtain the original line segments of the cross section and extract the terrain profile elevation along the vertical direction; Construct an extension length calculation model, and obtain the required extension length based on the extension length calculation model; The construction of the extended length calculation model includes:

[0011] In the formula, To extend the length, For safety reasons, The height of the highest point in the cross-sectional direction. The height of the lowest point in the cross-sectional direction. This represents the average slope in the cross-sectional direction.

[0012] Preferably, generating the watershed outlet point based on several intersection point data includes: Extract the coordinates of the intersection point and extract the sampled value of the current intersection point from the cumulant raster; The intersection point with the largest sample value is selected as the initial exit point. Based on the current initial exit point, geometric extension is performed to correct the current initial exit point and obtain the final exit point.

[0013] Preferably, the geometric extension based on the current initial point includes:

[0014] In the formula, For the final exit point, As the initial export point, To extend the distance, It is a unit vector representing the direction of water flow.

[0015] Secondly, this invention also provides a system for rapid batch extraction of watershed boundaries based on GIS and Python, used to execute the aforementioned method for rapid batch extraction of watershed boundaries based on GIS and Python, including... The data processing module acquires the DEM data of the target watershed, extracts the bottom layer data of the target watershed area surface layer based on the DEM data, the bottom layer data includes simulated river network data and raster data; acquires several cross-sectional lines corresponding to the current simulated river network in the database, determines whether the current cross-sectional line intersects with the closest river in the simulated river network, and saves the current intersection point data if they intersect. If the outlet point generation module does not intersect, it establishes a cross-section line extension model, outputs the data of the cross-section line to be extended based on the cross-section line extension model, and obtains the intersection point; and generates the watershed outlet point based on several intersection point data.

[0016] Thirdly, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described method for rapid batch extraction of watershed boundaries based on GIS and Python.

[0017] Fourthly, the present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for rapid batch extraction of watershed boundaries based on GIS and Python.

[0018] The technical solution of the present invention has at least the following advantages and beneficial effects: The method provided by this invention mainly includes: acquiring DEM data of the target watershed; extracting the bottom layer data of the target watershed area surface layer based on the DEM data; acquiring several cross-sectional lines corresponding to the current simulated river network in the database; determining whether the current cross-sectional line intersects with the closest river in the simulated river network; if intersecting, saving the current intersection point data; generating watershed exit points based on the several intersection point data; and obtaining the watershed boundary through the watershed exit points. By using the generated intersection points with key information as watershed exits, this method enables the extraction of small watershed boundaries in batches, significantly improving work efficiency and reducing the error rate of manual operations. Attached Figure Description

[0019] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a schematic diagram of the process of the present invention; Figure 2 This is a schematic diagram of the system structure of the present invention. Detailed Implementation

[0021] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0022] The module division in this application is a logical division. In actual application, there may be other division methods. For example, multiple modules may be combined into or integrated into another system, or some features may be ignored or not executed.

[0023] Furthermore, the connection, coupling, or communication in this application can be a direct connection, coupling, or communication between related objects, or an indirect connection, coupling, or communication through other devices. Moreover, the connection, coupling, or communication between objects can be electrical or other similar forms, and this application does not impose any limitations on these. Independently described modules or sub-modules may or may not be physically separated; they may be implemented in software or hardware, and some modules or sub-modules may be implemented in software, with the processor calling the software to implement the function of these modules or sub-modules, while other modules or sub-modules may be implemented in hardware, such as through hardware circuits. Furthermore, some or all of the modules can be selected to achieve the purpose of this application's solution according to actual needs.

[0024] Please refer to Figures 1-2 This invention provides a method for rapid batch extraction of watershed boundaries based on GIS and Python, comprising: S1: DEM Data Processing Obtain DEM data of the target watershed, and extract layer data of the target watershed area surface layer based on the DEM data. The bottom layer data includes simulated river network data and raster data. Among them, DEM is a digital discrete representation of the elevation of bare ground after removing vegetation, buildings, and other cover. It is a core subset of Digital Terrain Models (DTMs) and includes regular grids (Grid / GRID DEM, the most commonly used): stored using equally spaced rectangular grids, with each cell corresponding to an elevation value; the format is often GeoTIFF, ENVI Grid, or ASCII Grid; its advantages are fast calculation and easy storage, but its disadvantage is limited accuracy in steep areas; examples include SRTM 30m and ASTER GDEM 30m. Irregular triangular meshes (TINs): construct triangular patches based on discrete elevation points; suitable for complex terrain areas, high accuracy, and flexible editing, but with large data volume and computational cost; mostly used for engineering surveys and high-precision mapping. Contour lines / point clouds: auxiliary representations, often used as the raw data for generating Grid / TINs.

[0025] You can download DEM data covering the target watershed with the highest possible accuracy from the official website. Using the Arc Hydro Tools tool in ArcGIS software, you can obtain the underlying data that allows you to extract the watershed area surface layer through a series of steps.

[0026] S2: Cross-sectional line treatment: The database contains several cross-sectional lines corresponding to the current simulated river network. It determines whether the current cross-sectional line intersects with the closest river in the simulated river network. If they intersect, the data of the current intersection point is saved. When searching for intersection points, the GIS module provides a large number of raw cross-sectional lines. However, these cross-sectional lines may not necessarily intersect with the rivers in the simulated river network. Therefore, it is necessary to extend the current cross-sectional lines according to the actual usage. S3: Intersection point processing: If they do not intersect, then establish a cross-section line extension model, output the data of the cross-section line to be extended based on the cross-section line extension model, and obtain the intersection point; S4: Batch extraction of watershed boundaries: The watershed exit point is generated based on several intersection point data, and the watershed boundary is generated based on the watershed exit point.

[0027] By inputting the flow direction grid and the intersection point, the tool starts from this point and traverses the flow direction grid in reverse. All grids that "will eventually flow to this point" are marked as the watershed range, and this point is the outlet point of the watershed.

[0028] Based on the watershed outlet point, upstream tracing is performed using D8 flow direction data to identify all raster regions that ultimately flow towards that point, generating a watershed raster. Subsequently, this region is vectorized using a raster-to-polygon tool to generate the watershed boundary, allowing for batch processing.

[0029] The method provided by this invention mainly includes: acquiring DEM data of the target watershed; extracting the bottom layer data of the target watershed area surface layer based on the DEM data; acquiring several cross-sectional lines corresponding to the current simulated river network in the database; determining whether the current cross-sectional line intersects with the closest river in the simulated river network; if intersecting, saving the current intersection point data; generating watershed exit points based on the several intersection point data; and obtaining the watershed boundary through the watershed exit points. By using the generated intersection points with key information as watershed exits, this method enables the extraction of small watershed boundaries in batches, significantly improving work efficiency and reducing the error rate of manual operations.

[0030] An exemplary embodiment of the present invention, extracting the underlying data of a target watershed area surface layer based on DEM data, includes: The GIS module is used to fill depressions in the DEM data, calculate the water flow direction grid and the cumulative runoff grid, and obtain various types of grid data in the grid. Set a confluence threshold and extract simulated river network grids based on the confluence threshold.

[0031] Specifically, the water flow direction calculation grid includes each cell having 8 neighbors, and the water flows only in the direction of the steepest slope: Select the target center pixel as the grid for calculating the water flow direction, and obtain the slope of the 8 adjacent grids of the target pixel;

[0032] In the formula, For slope, The elevation of the current raster. For the first The elevation of one of the neighbors, For distance; Select the grid with the steepest slope as the target flow direction grid, and set the direction encoding value of the current grid to point to the target flow direction grid to obtain the current water flow direction of the grid.

[0033] In practical applications, DEM data is read, a 3×3 window is extracted for each cell, the slope in 8 directions is calculated, the direction with the steepest slope is selected, and a coding value (1, 2, 4...128) is assigned. Depressions are processed (flat areas are processed according to the surrounding direction), and FlowDir raster is output.

[0034] Specifically, the cumulative flow grid includes: Initialize the flow accumulation grid, obtain the flow direction of each grid, and add the flow of each grid into the grid in the indicated direction according to the flow direction; traverse all grids from high to low according to the elevation of each grid to obtain the flow accumulation of each grid.

[0035] Obtain the DEM after filling the depression, the flow direction grid FlowDir, and the sum of the cumulative flow of all upstream grids flowing towards the current grid.

[0036] In one exemplary embodiment of the present invention, establishing a cross-sectional line extension model includes: Set a target for cross-section extension so that the cross-section line can pass through the center line of the river channel in the simulated river network. The cross-section is a straight line perpendicular to the direction of the river. The river channel is generally located at the lowest point of the valley. The resulting valley width is approximately equal to the terrain slope plus the DEM resolution.

[0037] Obtain the original line segment of the cross section and extract the terrain profile elevation along the vertical direction; construct the extension length calculation model and obtain the required extension length based on the extension length calculation model; The construction of the extended length calculation model includes:

[0038] In the formula, To extend the length, For safety reasons, The height of the highest point in the cross-sectional direction. The height of the lowest point in the cross-sectional direction. This represents the average slope in the cross-sectional direction.

[0039] In one exemplary embodiment of the present invention, generating the watershed outlet point based on a plurality of intersection point data includes: Extract the coordinates of the intersection point and extract the sampled value of the current intersection point from the cumulant raster; The intersection point with the largest sample value is selected as the initial exit point. Based on the current initial exit point, geometric extension is performed to correct the current initial exit point and obtain the final exit point.

[0040] To more accurately locate the exit point, which is often located at the very end of the river channel, a further geometric extension is needed for correction. This geometric extension based on the current preliminary exit point includes:

[0041] In the formula, For the final exit point, As the initial export point, To extend the distance, It is a unit vector representing the direction of water flow.

[0042] Secondly, this invention also provides a system for rapid batch extraction of watershed boundaries based on GIS and Python, used to execute the aforementioned method for rapid batch extraction of watershed boundaries based on GIS and Python, including... The data processing module acquires the DEM data of the target watershed, extracts the bottom layer data of the target watershed area surface layer based on the DEM data, the bottom layer data includes simulated river network data and raster data; acquires several cross-sectional lines corresponding to the current simulated river network in the database, determines whether the current cross-sectional line intersects with the closest river in the simulated river network, and saves the current intersection point data if they intersect. If the outlet point generation module does not intersect, it establishes a cross-section line extension model, outputs the data of the cross-section line to be extended based on the cross-section line extension model, and obtains the intersection point; and generates the watershed outlet point based on several intersection point data.

[0043] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0044] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. This computer software product, stored in a storage medium, includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0045] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for rapid batch extraction of watershed boundaries based on GIS and Python, characterized in that, include: Obtain DEM data of the target watershed, and extract the bottom layer data of the target watershed area surface layer based on the DEM data. The bottom layer data includes simulated river network data and raster data. Obtain several cross-sectional lines corresponding to the current simulated river network in the database, determine whether the current cross-sectional line intersects with the closest river in the simulated river network, and if they intersect, save the current intersection point data; If they do not intersect, then establish a cross-section line extension model, output the data of the cross-section line to be extended based on the cross-section line extension model, and obtain the intersection point; The watershed exit point is generated based on several intersection point data, and the watershed boundary is generated based on the watershed exit point.

2. The method for rapid batch extraction of watershed boundaries based on GIS and Python according to claim 1, characterized in that, The underlying data of the target watershed area surface layer extracted based on DEM data includes: The GIS module is used to fill depressions in the DEM data, calculate the water flow direction grid and the cumulative runoff grid, and obtain various types of grid data in the grid. Set a confluence threshold and extract simulated river network grids based on the confluence threshold.

3. The method for rapid batch extraction of watershed boundaries based on GIS and Python according to claim 2, characterized in that, The grid for calculating the water flow direction includes: Select the target center pixel as the grid for calculating the water flow direction, and obtain the slope of the 8 adjacent grids of the target pixel; In the formula, For slope, The elevation of the current raster. For the first The elevation of one of the neighbors, For distance; Select the grid with the steepest slope as the target flow direction grid, and set the direction encoding value of the current grid to point to the target flow direction grid to obtain the current water flow direction of the grid.

4. The method for rapid batch extraction of watershed boundaries based on GIS and Python according to claim 3, characterized in that, The cumulative flow grid includes: Initialize the flow accumulation grid, obtain the flow direction of each grid, and add the flow of each grid into the grid in the indicated direction according to the flow direction; Traverse all grids from highest to lowest elevation to obtain the cumulative flow of each grid.

5. The method for rapid batch extraction of watershed boundaries based on GIS and Python according to claim 4, characterized in that, The establishment of the cross-sectional line extension model includes: Obtain the original line segments of the cross section and extract the terrain profile elevation along the vertical direction; Construct an extension length calculation model, and obtain the required extension length based on the extension length calculation model; The construction of the extended length calculation model includes: In the formula, To extend the length, For safety reasons, The height of the highest point in the cross-sectional direction. The height of the lowest point in the cross-sectional direction. This represents the average slope in the cross-sectional direction.

6. The method for rapid batch extraction of watershed boundaries based on GIS and Python according to claim 5, characterized in that, The generation of the watershed exit point based on several intersection point data includes: Extract the coordinates of the intersection point and extract the sampled value of the current intersection point from the cumulant raster; The intersection point with the largest sample value is selected as the initial exit point. Based on the current initial exit point, geometric extension is performed to correct the current initial exit point and obtain the final exit point.

7. The method for rapid batch extraction of watershed boundaries based on GIS and Python according to claim 6, characterized in that, The geometric extension based on the current initial point includes: In the formula, For the final exit point, As the initial export point, To extend the distance, It is a unit vector representing the direction of water flow.

8. A system for rapid batch extraction of watershed boundaries based on GIS and Python, characterized in that, The method for batch rapid extraction of watershed boundaries based on GIS and Python, as described in any one of claims 1-7, includes: The data processing module acquires the DEM data of the target watershed, extracts the bottom layer data of the target watershed area surface layer based on the DEM data, the bottom layer data includes simulated river network data and raster data; acquires several cross-sectional lines corresponding to the current simulated river network in the database, determines whether the current cross-sectional line intersects with the closest river in the simulated river network, and saves the current intersection point data if they intersect. If the exit point generation module does not intersect, it establishes a cross-section line extension model, outputs the data of the cross-section line to be extended based on the cross-section line extension model, and obtains the intersection point. The watershed exit point is generated based on several intersection point data.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method for rapid batch extraction of watershed boundaries based on GIS and Python as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method for rapid batch extraction of watershed boundaries based on GIS and Python as described in any one of claims 1-7.