Computer-based automatic identification, conversion and cleaning method for river section data
The computer-based method automates the conversion and processing of river cross-section data using Python to address inefficiencies in CAD data conversion, enhancing work efficiency and compatibility across software formats, thereby supporting intelligent water management systems.
Patent Information
- Application Number
- CN202111110614.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-23
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2041-09-23
AI Technical Summary
Current CAD data conversion methods for river cross-section data are inefficient, requiring extensive manual labor to extract and process data due to limitations in software compatibility and data format requirements, leading to low work efficiency and high human error in city engineering projects.
A computer-based method using Python programming to automatically identify and convert river cross-section data by linking CAD files, sorting and matching text and coordinate data, and generating output in various software formats, reducing manual intervention and data processing time.
This method automates the data processing and conversion of river cross-section data, significantly reducing human resource consumption and improving efficiency, enabling accurate and convenient data transfer across different software platforms, thus facilitating digitalization in urban water management.
Smart Images

Figure CN113986232B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of computer-aided design, and in particular to a computer-based automatic identification, conversion and cleaning method for river section data. Background Art
[0002] In the prior art, due to various factors, the basic data obtained in the design process is often limited, especially the river section data which usually only has the river section diagram in the CAD file format, and there is no data source that can be read by other types of software.
[0003] At present, the method for converting CAD drawing metadata is mainly to establish an Excel blank table associated with CAD, and then use the built-in VBA platform of AutoCAD. The user manually distinguishes the correspondence between the river pile number line and the river section data grouping. The user selects groups of boxes on the CAD section drawing to output the CAD drawing metadata to the Excel table, and then enters other software format requirements of the river data in Excel as needed for subsequent river section data processing.
[0004] In actual municipal engineering projects, there are usually thousands of river section data for a river, which requires a lot of manpower to select and identify them over and over again, and the work efficiency is low. In addition, for different software, the required input river section data is also different. The existing CAD data conversion method has great limitations, and usually requires manpower for the next step of data processing. For example, the input requirement of a drainage model is an ASCII code file, and there are certain format requirements. In this case, it is necessary to further process it in Excel, and then input the corresponding data into the ASCII code file by manual copying and pasting, resulting in a lot of time wasted on the next step of data cleaning, which is very labor-intensive.
[0005] Therefore, how to reduce manual operations, improve work efficiency, and reduce human errors has become a technical problem that technical personnel in this field urgently need to solve. Summary of the invention
[0006] In view of the above-mentioned defects of the prior art, the present invention provides a computer-based method for automatically identifying, converting and cleaning river section data, the purpose of which is to achieve the following.
[0007] To achieve the above object, the present invention discloses a computer-based river section data automatic identification, conversion and cleaning method; the method is characterized in that a python program is used to link a CAD file, and the method comprises the following steps:
[0008] Step 1: Obtain a river cross-section diagram drawn by CAD software after survey;
[0009] Step 2: Based on the script of Python software, establish an application program interface connection with the CAD software through the win32com.client module of Python software to realize the operation control of the CAD software by the script;
[0010] Step 3, respectively obtain the river section pile number name, that is, the insertion coordinate value of the text string and the corresponding string content, and the starting coordinate value of the river section line and store them in two tables respectively;
[0011] The table is a dataframe into the computer.
[0012] The two tables are sorted in ascending order based on the size of the X coordinate, and the indexes of the two tables are regenerated. The river section pile name data and river section line data of the same index corresponding rows in the two tables are matched into a group (so that the two tables can be traversed in sequence and the baseline can be generated later);
[0013] Step 4, traverse the two tables, and create a baseline according to the river section pile name, that is, the insertion coordinate value of the text string and the end point coordinate value of the corresponding river section line;
[0014] The reference line crosses the river section pile number name, that is, the text string and all the elevation points on the corresponding river section line;
[0015] Step 5: Using the height of the text label of the elevation point as the offset distance, the baseline is offset up and down to obtain a set of rectangular corner point coordinates that include the river section pile name, that is, the text string and the corresponding river section elevation point data;
[0016] Step 6: Create a polygonal selection set, use the coordinates of the rectangular corner points obtained in step 5 as the vertex coordinates of the polygonal selection, and traverse each group of distance corner point coordinates to achieve automatic grouping of the river channel pile number name and the river channel section elevation point data;
[0017] Step 7: Perform further data processing in the Python program according to the requirements of different software for data transmission, and then output it according to the template format.
[0018] Beneficial effects of the present invention:
[0019] The present invention can directly link the CAD file through the python program, match the river section elevation data with the pile number line of its river section metafile, clean the data through python, and output it according to the data source template required by the model software.
[0020] The present invention completes work in batches at one time, improves work efficiency, reduces waste of human resources, promotes the digitization process of CAD drawing metadata, and lays the foundation for smart water construction.
[0021] The present invention automatically matches and groups the pile number lines in the CAD river section diagram and the enhanced attribute blocks of the elevation points on the river section line, automatically completes the river section data transmission and data cleaning work in batches, and automatically outputs the data source format required by different software according to different needs. The data conversion is accurate and the transmission is convenient. There is no need for subsequent manual data processing and format conversion, which is convenient for promotion to others for use, and there is no need for tutorial training and other operations.
[0022] The concept, specific structure and technical effects of the present invention will be further described below in conjunction with the accompanying drawings to fully understand the purpose, characteristics and effects of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 A flow chart showing an embodiment of the present invention is shown.
[0024] Figure 2 A cross-sectional view of a river channel in one embodiment of the present invention is shown.
[0025] Figure 3 A table diagram showing a sorted table in one embodiment of the present invention.
[0026] Figure 4 A data output format template diagram in one embodiment of the present invention is shown. DETAILED DESCRIPTION
[0027] Example
[0028] As Figure 2 The river cross-section shown is used as an example for explanation.
[0029] Use Figure 1 The computer-based automatic identification, conversion and cleaning method for river section data shown includes the following steps:
[0030] Step 1: Obtain the river cross-section diagram in CAD format provided by the survey, such as Figure 2 As shown;
[0031] Step 2: Use the win32com.client module of Python to establish an application program interface connection with the CAD software, access the CAD metafile, and implement operations on the CAD console. The specific implementation code is as follows:
[0032] "acad=win32com.client.Dispatch("AutoCAD.Application.22")
[0033] #AutoCAD.Application.22 is ProgID
[0034] doc=acad.ActiveDocument”;
[0035] Step 3: River Cross Section Figure 1 Generally, it contains text strings: pile line name; enhanced attribute block: river section elevation point; straight line: river section line, river center line. Because the river center line data is irrelevant to the river section diagram, it is deleted first, so that it is easier to identify the river section line later.
[0036] Then, by creating a screen frame selection set "slt" (a variable name), all the graphic elements of the CAD model space are obtained, and then all the objects in the selection set are traversed, and the graphic elements of the river section are classified into three categories: "text", "enhanced attribute block" and "straight line" through the judgment statements ObjectName=="AcDbText"; ObjectName=="AcDbBlockReference"; ObjectName=="AcDbLine".
[0037] Step 4. Traverse all the "text" class graphics elements grouped in step 3 to obtain the pile number names (text strings) and pile number name insertion point coordinates of all river sections, and store them row by row in a table data frame named text_data, with "Section Pile Number Line Name", "X0", "Y0", "Z0", "X1", "Y1", "Z1" as column names.
[0038] Step 5: Slice the section pile name column of the data frame obtained in step 4 to obtain the pile line mileage data and store it in a new column. The specific implementation code is text_data['sort'] = text_data['Section pile line'].map(lambda x:int(x[-3:])). Then sort the text_data in ascending order according to the pile line mileage from small to large. The specific implementation code is text_data = text_data.sort_values(by = 'sort', ascending = True), and regenerate the index. The specific implementation code is text_data.reset_index(inplace = True, drop = True). The sorted list is as follows: Figure 3 shown.
[0039] Step 6. Traverse all the "straight line"-type graphics elements grouped in step 3, obtain the straight line object, the coordinate value of the starting point of the straight line, and the coordinate value of the end point of the straight line, and store them row by row in a table data frame named line_data, with "line object", "X0", "Y0", "Z0", "X1", "Y1", and "Z1" as column names. Sort line_data in ascending order according to the X coordinate size of the starting point of the straight line. The specific implementation code is:
[0040] line_data = line_data.sort_values(by = 'X0', ascending = True) and take out the sorted line object column. The specific implementation code is line_objsort = line_data['line object'].
[0041] Step 7: Traverse the sorted line objects taken out in step 6 to generate all the river section map baselines xline. The section baseline runs through the pile line name and the corresponding enhanced attribute blocks of all river section elevation points, that is, the starting point of the baseline is the insertion point coordinate value of the pile line name (text string), and the end point is the end point of the river section line ("straight line"). The specific implementation code is:
[0042] xline=mp.AddLine(vtFloat(startpoint),vtFloat(value.EndPoint));
[0043] Step 8: Using the text height of the enhanced attribute block as the offset distance, the river section baseline generated in step 7 is offset up and down, and the offset straight line starting point coordinates and straight line end point coordinates are stored line by line in the empty lists xline_spoint1, xline_spoint2, xline_epoint1, and xline_epoint2 respectively. The specific implementation code is:
[0044]
[0045] Step 9, create a selection set "slt2" (a variable name) selected by polygon, traverse and read the starting endpoint of the offset baseline obtained in step 8, use it as the four endpoints of the polygon selection set, loop polygon selection, and realize the matching and grouping of the river section elevation point data and the corresponding river pile number line name. The specific implementation code is:
[0046]
[0047]
[0048] Step 10: For data cleaning, this paper takes the ASCII code file as an example of the format data required for river modeling in a drainage software. Open the template ASCII code file as follows: Figure 4 , copy the fixed lines to the python script and store them in the variable str_ in a string format. For the places that need to be changed according to the surveyed river section diagram, such as the river name, river pile number line, and SECTION ID, the river section elements are traversed and passed through %s and %d in python. The specific form is as follows:
[0049]
[0050]
[0051] For the river cross-section elevation data, the number of lines input into the ASCII code file varies depending on the number of survey points. The model in this paper requires the cleaning of each set of river cross-section elevation data to input the relative coordinates of x, z value (river elevation), and the left bank, right bank, and lowest point of the river cross section, and three columns of fixed values. According to the above format requirements, each set of river cross-section images obtained in step 9) is cleaned and stored in an empty table data frame named df_result.
[0052] Use nodepad++ to view the format requirements for river cross-section data input in the template ASCII code file, then read the cleaned data line by line according to the format, and finally use Python's write function to write the river section data in batches as ASCII code files.
[0053] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.
Claims
1. A computer-based method for automatically identifying, converting and cleaning river section data; characterized in that: Use Python program to link CAD files, including the following steps: Step 1: Obtain a river cross-section diagram drawn by CAD software after survey; Step 2: Based on the script of Python software, establish a connection with the CAD software application program interface through the win32com.client module of Python software to realize the operation control of the CAD software by the script; Step 3, respectively obtain the river section pile number name, that is, the insertion coordinate value of the text string and the corresponding string content, and the starting coordinate value of the river section line and store them in two tables respectively; The two tables are sorted in ascending order based on the size of the X coordinate, and the indexes of the two tables are regenerated. The river section pile number name data and the river section line data of the rows corresponding to the same index in the two tables are matched with each other as a group; Step 4, traverse the two tables, and create a baseline according to the river section pile name, that is, the insertion coordinate value of the text string and the end point coordinate value of the corresponding river section line; The reference line crosses the river section pile number name, that is, the text string and all the elevation points on the corresponding river section line; Step 5: Using the height of the text label of the elevation point as the offset distance, the baseline is offset up and down to obtain a set of rectangular corner point coordinates that include the river section pile name, that is, the text string and the corresponding river section elevation point data; Step 6: Create a polygonal selection set, use the coordinates of the rectangular corner points obtained in step 5 as the vertex coordinates of the polygonal selection, and traverse each group of distance corner point coordinates to achieve automatic grouping of the river channel pile number name and the river channel section elevation point data; Step 7: Perform further data processing in the Python program according to the requirements of different software for data transmission, and then output it according to the template format.
Citation Information
Patent Citations
River channel section generalization method and device based on Douglas-Peucker
CN112231993A
SWMM and EFDC coupling model-based regulation and storage project environmental effect assessment method and device
WO2021180100A1