International Journal of Advanced Network, Monitoring and Controls Volume 05, No.02, 2020 DOI: 10.21307/ijanmc-2020-019 71 Design of Electric Power Line Drawing Algorithm Sun Pengzhan School of Computer Science and Engineering Xi'an Technological University Xi’an, 710021, China E-mail: 2994553975@qq.com Lei Juchao School of Computer Science and Engineering Xi'an Technological University Xi’an, 710021, China E-mail: leijuchao@139.com Abstract—At present, the drawing of power lines is still in the state of semi-manual design, mainly completed by AutoCAD, which not only consumes human resources, but also has low efficiency. Therefore, this paper designs an automatic drawing software for power lines. It integrates drawing and data management. Based on the basic information of power lines, this software imports and automatically converts the basic power data (latitude and longitude data) containing GPS/ BeidDou positioning information into the distance, direction, angle and other information of poles and cables. Then, it realizes the function of automatically drawing the power line graph according to the scale by multiple tree traversal algorithm. This software is easy to operate and reliable, and has achieved good results in practice. Keywords-Power Lines; Automatic Drawing; The Database; Multiple Tree; Traversal Algorithm I. INTRODUCTION The power grid is directly facing the end users and is closely related to the production and life of the people. It is an important public infrastructure to serve the people's livelihood. In recent years, with the development of new-type urbanization, China has been committed to the construction and renovation of power grid, so as to realize reliable power supply, high-quality service and improve supply efficiency. Power grid construction and reconstruction has become an urgent task of the current power industry. After the completion of the power grid transformation, the power supply enterprises need to draw and archive the power line diagram, which is usually drawn semi-manually by AutoCAD. However, AutoCAD requires professionals to use different drawing tools to draw on the software when drawing, and if it is necessary to change the position of a pole or change the information of a power line, it needs to be redrawn. Therefore, this kind of design method's shortcoming is obvious, not only the design workload is big, time-consuming, laborious, the efficiency is low, moreover has not been able to adapt to the electronic age development demand[1-2]. In order to realize the convenient drawing function, this paper designs and implements an automatic drawing software for power lines. The system can calculate various parameter information in the line through GPS data (longitude and latitude data) and store it in the database. Then it will automatically generate a standard and beautiful power circuit diagram according to the information stored in the database. If some information needs to be changed after the completion of power grid construction and reconstruction, only the corresponding data need to be changed to automatically draw again. This software provides a strong guarantee for reducing labor intensity, improving work efficiency and plotting quality, and shortening plotting cycle. II. POWER LINE STRUCTURE ANALYSIS Power equipment mainly includes generator set, power distribution device, lighthouse bridge column, fuse, transformer, transformer table, automatic control device, watt-hour meter, high-voltage switch, high-voltage circuit breaker, capacitor, lightning arrester, current transformer, voltage transformer, cable line, power line, etc. Since the generator set is not fixed on the power line, the power line mentioned in this system mainly refers to the line composed of outdoor poles, cables and transformer stations (including box transformers). Due to the wide coverage area of outdoor lines, the complex and changeable environment, and the diversified routing modes of the lines, the factors to be considered in drawing are also relatively complex. However, no matter how complicated and diverse the actual power lines are, all power lines are connected to the user end through transformer outgoing lines and several poles, so the power lines are essentially standard multi-branch tree structures. As shown in fig. 1, the power line in each area is essentially a mailto:yangyh26@qq.com International Journal of Advanced Network, Monitoring and Controls Volume 05, No.02, 2020 72 multi-branch tree with transformer as root node (node 0), and each pole in the line is a node of the multi-branch tree, i.e. T = {0,1,2,3,4,5,6,7} is a tree with root 0. The other nodes except the root node 0 can be divided into n disjoint finite sets, each set is a subtree of the root node[3]. Figure 1. Schematic diagram of power line multi-branch tree structure In the actual drawing process, whether manual drawing or automatic drawing, transformer is generally selected as the starting point. The process is: starting from the starting point to find the next pole connected to it through the relationship between the nodes, get the parameters of the node and the parent node, such as the distance, rotation angle, steering and other parameters, and then calculate the relative coordinates of the node. This drawing process is also very similar to the traversal process of a multi-fork tree, which provides the possibility for the realization of automatic power drawing. In the actual circuit drawing process, the four basic data sources of gear length, angle, steering, and pole number can be obtained during power grid reconstruction or power grid construction, or GPS can be used to obtain the latitude and longitude information of the pole and then converted to span, veer and angle. The automatic drawing of power lines can be realized by processing the four parameters in the database while traversing each node, calculating the relative coordinates of each node and converting them into absolute coordinates. III. POWER LINE AUTOMATIC DRAWING FUNCTION DESIGN A. Traversal of Multi-fork Trees Since the relationship between transformer and pole is tree structure, when drawing circuit diagram, this multi-branch tree can be constructed by traversing power lines and all nodes in the tree can be processed one by one. Therefore, it has the possibility to realize the automatic drawing of power line graphics. Common multi-tree traversal can be divided into two types: level-first traversal and depth-first traversal. Depth first traversal can be divided into: first order traversal, middle order traversal, and second order traversal. Its principle is to traverse the nodes of the tree along its depth and search the branches of the tree as deep as possible. Hierarchy priority traversal is to traverse the nodes of the tree according to hierarchy. Its principle is to first visit the root node and find all its children. These sub-nodes are also the root nodes of the sub-tree, so these nodes are accessed again, and so on and so forth, in order of first, second, third, etc[4]. B. Power Line Traversal Algorithm Although the power line graph has a multi-branch tree structure, there are many problems in the actual traversal operation. In the past multi-tree applications, whether it is depth traversal or hierarchical traversal, the node stores the node's sub-node information when it is stored, so its sub-nodes can be directly found by accessing the node, and traversal can be completed from top to bottom. However, in power lines, because each pole node only knows its parent node but not its child node and has no other relationship information, it is difficult to determine the location of other nodes except the root node, so the traditional traversal algorithm is not applicable. In order to solve this problem, this research has made some improvements on the basis of the hierarchical traversal algorithm. Because the information of each node's parent node is clear, we can easily find all the nodes with the same parent node. This research is based on this point to achieve top-down traversal. First, create an instance class object “Tree”, which represents that each row of data in the database is an instance object in java, and create an attribute “children” in the instance object Tree to save all child nodes of the current node. Second, get the data in the database to the instance object, and save all the International Journal of Advanced Network, Monitoring and Controls Volume 05, No.02, 2020 73 instance objects in the list collection. The specific traversal algorithm is to find the root node and put it into the result, and use the children attribute to find all the child nodes of the current layer from top to bottom through recursion, and save them in the result. Recursive traversal code is as follows. //Store all node data information object collection List result = new ArrayList(); //Query node data information List lists = new TestJDBC().queryAll(); //Traverse to determine whether it is the root node for (Tree tree : lists) { if(null == tree.getPid()) { result.add(tree); } } // Recursive call judgment function for (Tree parent : result) { parent = recursiveTree(parent, lists); } //Judgment function adds an object to the child attribute of the parent node object public static Tree recursiveTree(Tree parent, List list) { for (Tree tree : list) { if(parent.getId().equals(tree.getPid())) { tree = recursiveTree(tree, list); parent.getChildren().add(tree); } } return parent; } C. Calculation of Plane Coordinates The purpose of traversal is not only to construct the multi tree, but also to locate the coordinates of the traversal nodes. It is very important to convert the latitude and longitude data of the pole to the coordinate points in the plane rectangular coordinate system because it is impossible to draw the figure directly by GPS. In order to draw the figure accurately in the plane coordinate, first we must convert the longitude and latitude data into the plane coordinate data, and calculate the angle and the distance between the two points through the longitude and latitude data[5]. With poles A and B, the following calculation methods can be obtained through the derivation of mathematical geometric formula to realize data conversion. (1) The calculation method of the angle formed by two points A and B is as follows:  180 arctan( ) JA JB WA WB         Among them, θ is the angle (degree) between A and B, JA is the longitude of point a, JB is the longitude of point B, WA is the latitude of point A, WB is the latitude of point B. (2) The calculation method of the distance between two points A and B is as follows:  2 2 2 *acrsin sin ( ) 2 ( ) ( ) * cos( ) *sin ( ) 2 L R WA WB JA JB COS WA WB       Among them, L is the distance between points A and B (m), R is the earth radius (6371km), JA is the longitude of point A, JB is the longitude of point B, WA is the latitude of point A, WB is the latitude of point B. According to the calculation results of formulas (1) and (2), the storage in the database is shown in Figure 2. During traversal, the coordinates are located from the starting point, and then each child node of the node is found by traversal algorithm. The relative coordinates of the nodes are calculated by the span, rotation angle and steering parameters between the child node and the parent node. Due to the need to modify the relevant information of the pole during the traverse process, in order to ensure the integrity and reliability of the original database and improve the speed of database traversal, the information of relevant substation should be saved in the temporary database before the actual traversal[6-7]. The traversal process is as follows. International Journal of Advanced Network, Monitoring and Controls Volume 05, No.02, 2020 74 (1) Using SQL "select into temporary table from original table where change table name" command to create temporary data table and copy the change table data information to be drawn to the temporary table. (2) Find the starting point "transformer" of the transformer in the temporary data table, and set the starting point coordinate of the drawing as  0 0,x y according to the actual position of the transformer in the transformer. Figure 2. Storage in a database (3) Find the distribution board connected with the transformer, calculate the coordinates  0 0,x y of the distribution board according to the distance between the distribution board and the transformer, the steering and the steering angle, mark in the temporary database that the relative position coordinates of the node and the parent node have been calculated, and mark in the parent node that the child node coordinates of the parent node have been calculated. (4) Execute the cycle in the temporary database to select the relative coordinates of this node and the parent node have been calculated, but the poles of the coordinates of the child nodes have not been calculated. (5) Repeat step (3) until all poles are traversed. In the process of traversal, every record in the database must participate in multiple operations. If there are many poles in a substation, the cycle of traversal operation may be too long. Therefore, in the actual traversal operation, it may be faster to use the stored procedure of the database to complete this work. IV. GENERATION OF POWER CIRCUIT DIAGRAM After traversal calculation and plane coordinate positioning, the actual drawing results also need to display other relevant information for users. Therefore, the following work should be completed before automatically generating circuit drawing. (1) Traverse from the starting point (transformer) to calculate the power supply radius of each pole. (2) Draw title block, mark drawing scale, drawing date, type and quantity of various poles, model and length of conductor, number of meter boxes, maximum power supply radius, etc. (3) Statistics of the types, specifications, quantities of various poles in the substation, the length of wires of various specifications and types, the number of various meter boxes (power meter boxes and lighting meter boxes), etc. (4) According to the requirements of the power supply enterprise, the pole will be represented as "○", and the container will be represented as "□". (5) Walk through the database again and draw the line diagram from the starting point. A multi-fork tree structure with transformer as the root node line as the path and pole as the node is established by analyzing the demand of power supply enterprises for the drawing and archiving of power circuit diagrams and combining with the characteristics of power lines. After identifying the information stored in the database, a hierarchical traversal algorithm based on multi-tree is proposed. In the process of drawing, only four parameters of node need to be processed : span, veer, angle and Id number. and then the relative coordinates of each node are calculated and converted into absolute coordinates by using a multi-tree layer traversal algorithm, so that the automatic drawing of power lines can be realized. Then, the relative coordinates of each node are calculated and converted into absolute coordinates by using a multi-tree layer traversal algorithm, so that the automatic drawing of International Journal of Advanced Network, Monitoring and Controls Volume 05, No.02, 2020 75 power lines can be realized. The drawing method discussed in this paper has been successfully applied to many power supply enterprises in our country. Figure 3 shows the circuit diagram of a certain substation automatically generated. Figure 3. Circuit diagram of a transformer station automatically generated V. CONCLUSION The system manages power line parameter data through a database, and realizes the function of automatically drawing power graphs according to the proportion set by users, thus saving human resources. It can quickly change the information in the database when the information about a power line is changed. Therefore, it can well meet the needs of China's power grid reconstruction with short drawing cycle and high working efficiency. This system has achieved good results in the practical application of power supply enterprises in many places. REFERENCES [1] Peng Liangyong, Li Xiaodan. Realization of fast coordinate transformation method for CAD graphics [J]. Surveying and mapping and spatial geographic information, 2020,43(04):199-201. [2] Li Huiping, He Lianfang. Discussion on the Teaching of Auxiliary Modules of AutoCAD Software [J]. Journal of Higher Education, 2020(14):90-92+96. [3] Peng Qiwei, Zhang Hao. Adaptive Relay Algorithm for Medium Voltage Distribution Line Carrier Based on Multitree Traversal [J]. Power System Communication, 2009,30(03):81-84. [4] Wang Fangxiu, Liu Chunhong. A New Algorithm for Constructing Binary Tree by Hierarchical Traversal and Other Traversal [J]. Journal of Wuhan University of Light Industry, 2016,35(04):67-72. [5] Zhao Xiang, Chen Yan. A Coordinate Transformation Algorithm in Geographic Information System [J]. Computer and Network, 2007(11):40-41. [6] Data Structure and Algorithm [M]. Beijing University of Aeronautics and Astronautics Press, Yu Xiaomin, 2010. [7] Kou Chunpeng. Design and Implementation of SQLServer Database Information Acquisition System [D]. beijing university of chemical technology, 2008.