Water supply network according to traffic demand node cad file request

In the course design process, data processing often allow students to headaches. But this the work done by the computer to impose, it is no wonder the students were hurt. Especially when seeking node traffic, although Hongye Tengen and other software have this feature, but interested students can develop their own program from the ground up. Here are some of my ways, that is based on the output .dxf cad mapping file, use the python matplotlib make node traffic patterns. Of course, there is another to use a third-party library dxfgrabber. Specific methods are as follows:

1, according to a city road map according to the relevant specifications (mains or connecting pipe with a spacing between Specification) nodes and design. It should be noted that the node must use cad point of order to draw, then line connection.

2, according to the results of the highest maximum daily water consumption, the implementation of the program, you can get the results map

Graphic .dxf file is as follows:

 

code show as below:

1  '' ' according to the flow pipe flow computer node ' '' 
2  Import dxfgrabber
 . 3  Import matplotlib.pyplot AS PLT
 . 4  Import numpy AS NP
 . 5  
. 6 DXF dxfgrabber.readfile = ( " C: \\ 1.dxf " )
 . 7 J = - . 1
 . 8 pipe = []
 . 9 coodinate = []
 10 q_total = 1012-92 # highest water, (L / s), 92 is the total flow rate of concentrate 
. 11  for E in dxf.entities:
 12 is      IF e.dxftype == ' the LINE ' :
 13 is         j += 1
14         start_node = [int(i) for i in list(e.start)]
15         end_node = [int(i) for i in list(e.end)]
16         length = int(((start_node[0] - end_node[0])**2 +
17                   (start_node[1] - end_node[1])**2)**(0.5))
18         pipe.append([start_node, end_node, length])
19         #print([start_node, end_node, length])
20     elif e.dxftype == 'POINT':
21         coodinate.append([int(i) for i in e.point])
 22 is      the else :
 23 is          None
 24  # Print (coodinate) 
25  
26 is L_total = SUM ([I [2] for I in pipe])
 27 q_specific = [q_total * I [2] / L_total for I in pipe ] # pipe flow list 
28  Print (q_specific)
 29          
30 X = []
 31 is Y = []
 32 Z = []
 33 is node = [] # node coordinates of two elements in the list of presence node 
34 is J = -1
 35  for Iin coodinate:
36     j+=1
37     x.append(i[0])
38     y.append(i[1])
39     z.append(i[2])
40     node.append([int(x[j]), int(y[j]), int(z[j])])
41     #print(node[j])
42     
43 dic = {}    
44 for i in range(len(node)):
45     dic[i]=node[i]
46 print(dic)
47 for i in node:
48     for element in pipe:
49         None
50         
51 dic_q = {k:0 for k in range(len(node))}
52 for k in dic.keys():
53     for p in range(len(pipe)):
54         if dic[k]==pipe[p][0]:
55             dic_q[k] += q_specific[p]/2
56         elif dic[k]==pipe[p][1]:
57             dic_q[k] += q_specific[p]/2
58         else:
59             None             
60 print(dic_q)           
61             
62 
63 
64 
65 fig = plt.figure(1)
66 ax = fig.gca()
67 
68 x = np.array(x)
69 y = np.array(y)
70 qtext = [i for i in dic_q.values()]
71 ax.scatter(x,y,c='r',marker='o')#print(x,y)
72 for i in range(len(pipe)):
73     ax.plot([pipe[i][0][0], pipe[i][1][0]], [pipe[i][0][1], pipe[i][1][1]], c='b')
74 
75 for i in range(len(x)):
76     ax.annotate(int(qtext[i]), xy=(x[i],y[i]))
77 
78 fig = plt.figure()
79 ax = fig.add_subplot(111)
80 for i in range(len(pipe)):
81     ax.plot([pipe[i][0][0], pipe[i][1][0]], [pipe[i][0][1], pipe[i][1][1]], c='b')
82     ax.annotate(pipe[i][2], xy=((pipe[i][0][0]+pipe[i][1][0])/2, (pipe[i][0][1]+pipe[i][1][1])/2))
83 plt.show
Seek node traffic program

Guess you like

Origin www.cnblogs.com/w-netboy/p/12185833.html