Road survey data processing method based on Python and Mayavi
Through Python and Mayavi combined with a variety of third-party libraries, a constraint triangle network model was built, which solved the problems of low modeling efficiency and insufficient accuracy in highway surveys, and achieved efficient and accurate vertical and cross-section data extraction and three-dimensional model reusability, significantly shortening the survey period.
Patent Information
- Application Number
- CN202510432949.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-08
- Publication Date
- 2025-08-29
AI Technical Summary
The prior art has problems in highway surveys with low modeling efficiency, insufficient accuracy, long surveying period and poor model reusability. Especially when vegetation occlusion or point cloud density is insufficient, it is difficult to accurately extract the three-dimensional position information of road features.
Python and Mayavi are combined with a variety of third-party open source libraries, and through feature points and LiDAR point cloud data processing, a constraint triangle network model is built, and data blocking and three-dimensional display is used for data chunking and three-dimensional display, and a Mayavi library is used for model display and data extraction, achieving efficient and accurate vertical and cross-sectional data extraction.
It improves modeling efficiency and accuracy, shortens the surveying period, and the built three-dimensional model has strong reusability, can display and analyze data on multiple platforms, and supports multi-scenario needs for road design and construction.
Smart Images

Figure CN120562001A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of highway survey and design, and in particular relates to a highway survey data processing method based on Python and Mayavi. Background Art
[0002] With the rapid development of the highway survey and design industry, highway construction is placing higher demands on the stability of design solutions and the design cycle. The design industry needs continuous technological innovation to better serve the market in this new era. As an essential early stage task in highway survey and design projects, surveying plays a key role in providing the basic mapping data required for the project's surrounding geographical environment and design. However, traditional surveying methods, due to their time-consuming nature and low efficiency, have become unable to meet the increasingly urgent demands of design projects. In recent years, with the rapid development of digital and intelligent surveying and mapping equipment, particularly the widespread adoption of LiDAR technology, the highway survey field has begun to widely apply LiDAR point clouds to build three-dimensional models and extract road cross-sectional data from these models. However, due to factors such as vegetation obstruction and insufficient point cloud density, relying solely on LiDAR point clouds to build three-dimensional models and extract cross-sectional data often fails to accurately reflect the three-dimensional position information of features such as road edges, ditches, and ridges.
[0003] At present, in highway reconstruction and expansion projects, the technologies for highway survey include:
[0004] (1) Chinese patent application CN201210068333.9 discloses a highway survey method based on a refined digital terrain model. This method constructs a grid model from collected point and line sets and extracts longitudinal and transverse sections from the grid model. While this method simplifies the survey process and ensures the quality of the output data, it still has limitations in terms of model accuracy and applicability.
[0005] (2) Chinese patent application CN201410230292.8 discloses a highway survey and design method based on airborne LiDAR data. This method segments the LiDAR data and constructs an index, calculating the highway's longitudinal and transverse sections using the LiDAR data's terrain factors. Although this method directly generates longitudinal and transverse sections from LiDAR data, shortening highway survey and design time and offering high practicality and ease of implementation, it still suffers from accuracy loss when extracting cross-section data.
[0006] ⑶ The Chinese patent application titled "A method for automatically generating ground line data" discloses a method for modeling ground points in a point cloud and performing elevation interpolation to obtain ground line data. The ground line data is superimposed on the LiDAR point cloud and DOM data for visual inspection and editing to obtain the final ground line data.
[0007] In summary, existing patented technologies are mainly divided into two categories: one is to use LiDAR point cloud modeling and extract longitudinal and cross-sections from the model; the other is to use measured data and LiDAR joint modeling to construct a grid model to extract longitudinal and cross-sections. The first method may cause the cross-section data to not accurately reflect the current topography due to reasons such as vegetation obstruction or insufficient point cloud density; the second method has problems with model accuracy and applicability due to the construction of a digital grid model, and there is a loss of accuracy when extracting cross-section data. In addition, although the traditional method of directly measuring longitudinal and cross-sections is highly accurate, it is inefficient, and when the line needs to be rerouted, the cross-section of the rerouted section must be remeasured, which seriously affects the design schedule. Summary of the Invention
[0008] The purpose of the present invention is to provide a highway survey data processing method based on Python and Mayavi, which has high modeling efficiency, high model accuracy, can shorten the survey period, and has strong results reusability.
[0009] The object of the present invention is achieved by the following technical solution: a highway survey data processing method based on Python and Mayavi, characterized in that it specifically includes the following steps:
[0010] S1. Draw the measured feature points in CAD software, draw 3D feature lines based on the feature points, and then export and save the feature point and 3D feature line data;
[0011] S2. If the highway survey project has LiDAR point cloud data, the LiDAR point cloud data is processed to generate a framing range frame. If the highway survey project does not have LiDAR point cloud data, the entire line data is processed to generate a framing range frame. Then, through buffer analysis, an expanded framing range frame is generated to obtain a final framing range frame.
[0012] S3. Use the LiDAR point cloud data and feature points as feature point data, extract the final framing range frame, use the Python Shapely library to block the feature point data, name the blocked feature point data according to the framing map name, and then use the Python Shapely library to intercept the feature lines in the framing to obtain the feature point data and feature line data after framing;
[0013] S4. Based on the feature point data and feature line data after segmentation, a constrained triangulated network model is constructed using the Python CGAL library, and the constrained triangulated network model is saved in VTK format;
[0014] S5. Calculate the line position stake coordinates with a stake interval of 0.1 m based on the road design plane line position CAD drawing provided by the designer, and save the stake numbers and coordinates as line position text data;
[0015] S6. Setting section extraction parameters, and extracting the center pile and cross section line coordinates based on the line position text data and the section extraction parameters, and extracting longitudinal and cross section data in the constrained triangulated network model;
[0016] S7. Based on the longitudinal and cross-sectional data, generate the final longitudinal and cross-sectional results in CAD, convert the longitudinal and cross-sectional results into latitudinal results, and use Mayavi to convert the constrained triangulated network model into an OBJ format three-dimensional model for use by designers.
[0017] The present invention utilizes a variety of third-party open source libraries of Python and the Mayavi 3D display platform to efficiently process highway survey data to obtain accurate longitudinal and cross-sectional data and 3D ground model results, and realizes functions such as data processing, 3D modeling, model display, and results output. The present invention has high modeling efficiency and high model accuracy; the present invention extracts longitudinal and cross-sectional data through the established 3D model, which can greatly save the survey period, and the 3D model constructed by the present invention is displayed in 3D through the Mayavi library, which has strong reusability.
[0018] In the step S1 of the present invention, three-dimensional feature line data is formed by connecting special features with three-dimensional polylines via feature points.
[0019] In step S2 of the present invention, for projects without LiDAR point cloud data, the entire line data is divided into one frame, that is, a frame range frame is drawn in CAD, and a closed range line is manually drawn; for projects with LiDAR point cloud data, the LiDAR point cloud data of the survey area is first obtained, the LiDAR point cloud is classified, and the ground points in the LiDAR point cloud are obtained. Then, a frame range frame of 2km to 5km is generated according to the road centerline.
[0020] In the step S3 of the present invention, when framing the three-dimensional feature line, the elevation of the plane intersection between the three-dimensional feature line and the framing frame is directly obtained by linear interpolation to obtain the feature line data after framing.
[0021] In step S4 of the present invention, an empty CDT object is constructed using the Python CGAL library, an empty list list for storing feature point coordinates is constructed, the node coordinates on the feature line are written into the empty list list, the node coordinates of the framing range box are appended to the list, and the point coordinates of the feature point data are appended to the list; the list, the constraint information of the feature line, and the constraint information of the framing range box are respectively inserted into the empty CDT object, and after the constrained triangulation network is constructed, the triangles in the constrained triangulation network that are collinear with the framing range box are deleted to obtain the final constrained triangulation network model.
[0022] In the step S4 of the present invention, the constrained triangulated mesh model in VTK format is opened with the Mayavi library for display, and the Mayavi UI is designed to be linked with the CAD. In the constrained triangulated mesh model displayed by Mayavi, an abnormal position is clicked, and the abnormal position is synchronously marked in the CAD. Then, the measured data in the CAD is edited and modified, and steps S1 to S4 are repeated until the surface composed of all triangular faces of the constrained triangulated mesh model is continuous and smooth.
[0023] In step S5 of the present invention, the disconnected curves, straight lines, and multi-segment lines in the line position are manually connected in sequence into a polyline, the node position coordinates of the polyline with an interval of 0.1m are calculated according to the convexity of each node in the polyline, and the cumulative length from each node to the starting point is recorded as the pile number.
[0024] In the step S6 of the present invention, the section extraction parameters include the centerline offset distance, the pile number interval of the longitudinal section extraction point and the cross-section width.
[0025] In step S6 of the present invention, extracting the center pile and cross-section line coordinates includes: first calculating the offset 0.1m interval line center pile data, then calculating the center pile point coordinates of the specified pile number interval, and finally calculating the start and end point coordinates of the cross-section line based on the cross-section width, and taking the left side of the line direction as the starting point of the cross-section line.
[0026] In step S6 of the present invention, extracting longitudinal and cross-sectional data from the constrained triangulated network model includes: calculating the coordinates of the centroid of each triangle in the constrained triangulated network model, converting the centroid coordinates into a kdTree type data structure, performing a proximity search on the centroid coordinates of the kdTree type data structure at the midpoint, finding the corresponding triangle coordinates based on the searched centroid coordinates, traversing these triangle coordinate data to find the triangle containing the midpoint, and interpolating the elevations of all midpoints in sequence according to the triangle vertex coordinates to obtain longitudinal section data; calculating the plane intersection of each cross section and the constrained triangulated network based on the cross-sectional line data, performing a proximity search at the intersection, obtaining the triangle where each intersection is located, calculating the elevation of each intersection, that is, obtaining the coordinates of each intersection of the cross-sectional line and the constrained triangulated network, sorting the coordinates of each intersection on each cross-sectional line according to the distance from the starting point of the cross section, arranging the sorted coordinate points into a cross-sectional result in the form of absolute elevation, and forming the final longitudinal and cross-sectional result with the longitudinal section data.
[0027] Compared with the prior art, the present invention has the following significant effects:
[0028] (1) High modeling efficiency. This method combines both pure field-measured data modeling and field-measured data and LiDAR point cloud fusion modeling. When using pure field-measured data modeling, the amount of feature point and feature line data is typically less than 100,000, resulting in a fast network construction speed. Furthermore, when LiDAR point clouds are involved in modeling, modeling efficiency can be greatly improved through framing. Therefore, this method has a significant advantage in modeling efficiency over other methods.
[0029] (2) High model accuracy. Since the CGAL library used in the present invention to construct the constrained triangulation network provides completely accurate geometric calculations, there is basically no network failure when constructing the constrained triangulation network. Therefore, the model accuracy is high and the constructed model has basically no accuracy loss.
[0030] (3) Shorten the survey period. This method extracts longitudinal and cross-sectional data from a built three-dimensional model, which can significantly reduce the survey period compared to traditional methods. This is especially true when adjusting or rerouting highway projects. As long as the measurement range after the rerouting meets the requirements, longitudinal and cross-sectional data can be quickly extracted from the model, avoiding the need for additional field surveys. Therefore, it can generate significant economic benefits for the entire design period.
[0031] (4) The results are highly reusable. The three-dimensional model constructed by the present invention is displayed in three dimensions through the Mayavi library. Mayavi is a powerful 3D scientific data visualization library designed for Python. It is built on VTK and inherits VTK's powerful graphics and data processing capabilities. It supports VTK, STL, PLY, OBJ and other data formats. Therefore, the three-dimensional model constructed by the present invention is highly reusable and can be converted into input formats supported by mainstream software, providing important data support for terrain analysis, hydrological analysis, landscape modeling, earthwork calculation, disaster assessment, route and road design, etc.
[0032] ⑸The present invention demonstrates significant advantages in surveying and mapping accuracy, automated processing, and multi-platform collaboration, and can efficiently support multi-scenario requirements in road design and construction. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0034] Figure 1 is a flow chart of the present invention;
[0035] Figure 2 This is a graph of the measured data results of the present invention;
[0036] Figure 3 This is a Mayavi 3D model display diagram based on pure measured data of the present invention;
[0037] Figure 4This is a Mayavi 3D model display based on the fusion of measured data and point cloud;
[0038] Figure 5 It is a cross-sectional schematic diagram of the present invention;
[0039] Figure 6 It is a longitudinal section result schematic diagram of the present invention. DETAILED DESCRIPTION
[0040] like Figures 1 to 6 As shown, the present invention provides a highway survey data processing method based on Python and Mayavi, which specifically includes the following steps:
[0041] S1. Draw the measured feature points in CAD software, draw 3D feature lines based on the feature points, and then export and save the feature point and 3D feature line data;
[0042] Measure feature points such as roadsides, water (ditch) edges, ridges, slope edges, and elevation points in the survey area. After the measurement is completed, collect the measured feature points and import them into CAD. Use 3D polylines to connect special features through the feature points to form 3D feature line data. Export and save the feature points and 3D feature line data.
[0043] S2. If the highway survey project has LiDAR point cloud data, the LiDAR point cloud data is processed to generate a framing range frame. If the highway survey project does not have LiDAR point cloud data, the entire line data is processed to generate a framing range frame. Then, through buffer analysis, an expanded framing range frame is generated to obtain a final framing range frame.
[0044] For projects without LiDAR point cloud data, the entire line data is divided into one frame, that is, the frame range is drawn in CAD, and a closed range line is drawn manually;
[0045] For projects with LiDAR point cloud data, first obtain the LiDAR point cloud data of the survey area, classify the LiDAR point cloud data, obtain the ground points in the LiDAR point cloud, and then generate a 2km to 5km frame range based on the road centerline.
[0046] After the scope frames of the above two types of projects are generated, the buffer analysis is performed to generate the expanded sub-framing scope frames. The expanded sub-framing scope frames are the final sub-framing scope frames.
[0047] S3. Both LiDAR point cloud data and feature points are used as feature point data. Therefore, the input data only contains feature point data and feature line data. The final framing range frame is extracted, and the feature point data is divided into blocks using the Shapely library of Python. The feature points after division are named according to the framing map name. The feature lines are then intercepted by the Shapely library of Python. Due to the characteristics of the Shapely library, when framing the 3D feature lines, the plane intersection elevation of the 3D feature lines and the framing frame can be directly obtained by linear interpolation, and the feature point data and feature line data after framing are obtained.
[0048] S4. Based on the feature point data and feature line data after segmentation, a constrained triangulated network model is constructed using the Python CGAL library. The constrained triangulated network model is saved in VTK format and displayed in 3D visualization on the Mayavi platform.
[0049] Construct a constrained triangulation network: Use Python's CGAL library to construct an empty CDT object, construct an empty list list to store the coordinates of feature points, write the node coordinates on the feature line into the empty list list, then append the node coordinates of the tiling range box to the list, and then append the point coordinates of the feature point data to the list; insert the list, the constraint information of the feature line and the constraint information of the tiling range box into the empty CDT object respectively. After the constrained triangulation network is constructed, delete the triangles in the constrained triangulation network that are collinear with the tiling range box to obtain the final constrained triangulation network model.
[0050] Display of constrained triangulated network model: organize the constrained triangulated network into VTK structure data, open it with Mayavi library for display, and design Mayavi UI to link with CAD. In the constrained triangulated network model displayed by Mayavi, click on the abnormal position, mark the abnormal position in CAD synchronously, and then edit and modify the measured data in CAD. Repeat steps S1 to S4 until the surface composed of all triangular faces of the constrained triangulated network three-dimensional model is continuous and smooth, eliminating significant concave or convex defects.
[0051] S5. Calculate the pile line position: Based on the road design plane line position CAD drawing provided by the designer, manually connect the disconnected curves, straight lines, and multi-segment line positions in the line position into a polyline in sequence. Calculate the node position coordinates of the polyline at intervals of 0.1m based on the convexity of each node in the polyline. Record the cumulative length from each node to the starting point as the pile number. Save the pile number and coordinates of the nodes at intervals of 0.1m together as line position text data.
[0052] S6. Setting section extraction parameters, including centerline offset distance, pile number interval of longitudinal section extraction points, and cross-section width; extracting center pile and cross-section line coordinates based on line position text data and section extraction parameters, and extracting longitudinal and cross-section data in the constrained triangulated network model;
[0053] Extract the center pile and cross-section line coordinates: According to the line position text data and section extraction parameters, first calculate the offset 0.1m interval line position center pile data, then calculate the center pile point coordinates of the specified pile number interval, and finally calculate the starting and ending point coordinates of the cross-section line based on the cross-section width, and take the left side of the line position direction as the starting point of the cross-section line.
[0054] Extract longitudinal and cross-sectional data: In the constrained triangulated network model, calculate the coordinates of the centroid of each triangle, convert the coordinates of the centroid into a kdTree type data structure, perform a 50m proximity search on the kdTree type centroid coordinates at the midpoint, find the corresponding triangle coordinates based on the searched centroid coordinates, traverse these triangle data, find the triangle containing the midpoint, interpolate the elevations of all midpoints in sequence based on the triangle vertex coordinates, and obtain the longitudinal section data; according to the cross-sectional line data, calculate the plane intersection of each cross section and the constrained triangulated network, perform a proximity search at the intersection, obtain the triangle where each intersection is located, calculate the elevation of each intersection, that is, obtain the coordinates of each intersection of the cross-sectional line and the constrained triangulated network, sort the coordinates of each intersection on each cross-sectional line according to the distance from the starting point of the cross section, organize the sorted coordinate points into cross-sectional results in the form of absolute elevations, and combine them with the longitudinal section data to form the final longitudinal and cross-sectional results.
[0055] S7. Generate the final longitudinal and cross-sectional results in CAD based on the longitudinal and cross-sectional data, manually check the cross-sectional drawings for gross errors, and convert the longitudinal and cross-sectional results into latitudinal results after the cross-sectional results are correct. Open the constrained triangulated network model in Mayavi, save the OBJ format 3D model, and provide it to designers for use.
[0056] Specific examples:
[0057] According to the requirements of "Highway Survey Specifications" JTG C10-2007, the mean error of DTM interpolation based on measured data should be less than 0.2m in plain areas and less than 0.4m in hilly areas. The following two items were verified for accuracy based on the requirements of the "Highway Survey Specifications".
[0058] In a local road survey project in Huizhou, the design route length is 826m, and there is no LiDAR point cloud data. Figure 2 As shown in the figure, first measure the feature point data in the field, and then build a 3D model as shown in the figure. Figure 3 As shown, the extracted cross-sectional data is drawn into a cross-sectional diagram as shown in Figure 4 、 Figure 5As shown, the longitudinal and cross-sectional data are compared. The following is a comparison table of cross-sectional data sampling:
[0059] Number of sampling points for cross-section data Elevation error / m cross section 172 0.120
[0060] (Table 1)
Claims
1. A highway survey data processing method based on Python and Mayavi, characterized in that The specific steps include: S1. Draw the measured feature points in CAD software, draw 3D feature lines based on the feature points, and then export and save the feature point and 3D feature line data; S2. If the highway survey project has LiDAR point cloud data, the LiDAR point cloud data is processed to generate a frame range. If the highway survey project does not have LiDAR point cloud data, the full-line data is processed to generate a frame range. Then, through buffer zone analysis, the expanded frame range is generated to obtain the final frame range; S3. Use the LiDAR point cloud data and feature points as feature point data, extract the final framing range frame, use the Python Shapely library to block the feature point data, name the blocked feature point data according to the framing map name, and then use the Python Shapely library to intercept the feature lines in the framing to obtain the feature point data and feature line data after framing; S4. Based on the feature point data and feature line data after segmentation, a constrained triangulated network model is constructed using the Python CGAL library. The constrained triangulated network model is saved in VTK format and displayed in 3D visualization on the Mayavi platform. S5. Calculate the line position stake coordinates with a stake interval of 0.1 m based on the road design plane line position CAD drawing provided by the designer, and save the stake numbers and coordinates as line position text data; S6. Setting section extraction parameters, and extracting the center pile and cross section line coordinates based on the line position text data and the section extraction parameters, and extracting longitudinal and cross section data in the constrained triangulated network model; S7. Based on the longitudinal and cross-sectional data, generate the final longitudinal and cross-sectional results in CAD, convert the longitudinal and cross-sectional results into latitudinal results, and use Mayavi to convert the constrained triangulated network model into an OBJ format three-dimensional model for use by designers.
2. The highway survey data processing method according to claim 1, characterized in that: In step S1, three-dimensional feature line data is formed by connecting special features with three-dimensional polylines through feature points.
3. The highway survey data processing method according to claim 2, characterized in that: In step S2, for projects without LiDAR point cloud data, the entire line data is divided into one frame, that is, a frame range frame is drawn in CAD and a closed range line is manually drawn; for projects with LiDAR point cloud data, the LiDAR point cloud data of the survey area is first obtained, the LiDAR point cloud is classified, and the ground points in the LiDAR point cloud are obtained. Then, a frame range frame of 2 km to 5 km is generated according to the centerline of the road.
4. The highway survey data processing method according to claim 3, characterized in that: In step S3, when the three-dimensional feature line is framed, the elevation of the plane intersection between the three-dimensional feature line and the frame frame is directly obtained by linear interpolation to obtain the feature line data after framing.
5. The highway survey data processing method according to claim 4, characterized in that: In step S4, an empty CDT object is constructed using the Python CGAL library, an empty list list is constructed to store the coordinates of the feature points, the coordinates of the nodes on the feature lines are written into the empty list list, the node coordinates of the tiling range frame are appended to the list, and the point coordinates of the feature point data are appended to the list; the list, the constraint information of the feature lines, and the constraint information of the tiling range frame are respectively inserted into the empty CDT object. After the constrained triangulation network is constructed, the triangles in the constrained triangulation network that are collinear with the tiling range frame are deleted to obtain the final constrained triangulation network model.
6. The highway survey data processing method according to claim 5, characterized in that: In step S4, the constrained triangulated mesh model in VTK format is opened with the Mayavi library for display, and the Mayavi UI is designed to be linked with CAD. In the constrained triangulated mesh model displayed by Mayavi, the abnormal position is clicked, and the abnormal position is synchronously marked in CAD. Then, the measured data in CAD is edited and modified, and steps S1 to S4 are repeated until the surface composed of all triangular faces of the constrained triangulated mesh model is continuous and smooth.
7. The highway survey data processing method according to claim 6, characterized in that: In step S5, the disconnected curves, straight lines, and multi-segment lines in the line position are manually connected in sequence to form a polyline, the node position coordinates of the polyline with an interval of 0.1m are calculated according to the convexity of each node in the polyline, and the cumulative length from each node to the starting point is recorded as the pile number.
8. The highway survey data processing method according to claim 7, characterized in that: In step S6, the section extraction parameters include the centerline offset distance, the pile number interval of the longitudinal section extraction points, and the cross-section width.
9. The highway survey data processing method according to claim 8, characterized in that: In step S6, extracting the center pile and cross-section line coordinates includes: first calculating the offset 0.1m interval line center pile data, then calculating the center pile point coordinates of the specified pile number interval, and finally calculating the start and end point coordinates of the cross-section line based on the cross-section width, and taking the left side of the line direction as the starting point of the cross-section line.
10. The highway survey data processing method according to claim 9, characterized in that: In the step S6, extracting the longitudinal and cross-sectional data from the constrained triangulated network model includes: calculating the coordinates of the centroid of each triangle in the constrained triangulated network model, converting the centroid coordinates into a kdTree type data structure, performing a proximity search on the centroid coordinates of the kdTree type data structure at the midpoint, finding the corresponding triangle coordinates based on the searched centroid coordinates, traversing these triangle coordinate data to find the triangle containing the midpoint, and sequentially interpolating the elevations of all midpoints based on the triangle vertex coordinates to obtain longitudinal section data; calculating the plane intersection of each cross section and the constrained triangulated network based on the cross-sectional line data, performing a proximity search at the intersection to obtain the triangle where each intersection is located, calculating the elevation of each intersection, that is, obtaining the coordinates of each intersection of the cross-sectional line and the constrained triangulated network, sorting the coordinates of each intersection on each cross-sectional line according to the distance from the starting point of the cross section, arranging the sorted coordinate points into a cross-sectional result in the form of absolute elevation, and forming the final longitudinal and cross-sectional result with the longitudinal section data.
Citation Information
Patent Citations
Fine digital terrain model based road surveying method
CN102620721B
Road survey and design method based on airborne LiDAR data
CN104007436A