|
@@ -1,2 +1,547 @@
|
1
|
|
-def main_function(file_path, db_path):
|
2
|
|
- print("GS")
|
|
1
|
+import sqlite3
|
|
2
|
+import os
|
|
3
|
+import tkinter as tk
|
|
4
|
+from tkinter import messagebox
|
|
5
|
+import math
|
|
6
|
+import numpy as np
|
|
7
|
+
|
|
8
|
+#region 各种方法
|
|
9
|
+
|
|
10
|
+def to_utf8(text):
|
|
11
|
+ str1 = text.encode('utf-8')
|
|
12
|
+ return str1
|
|
13
|
+
|
|
14
|
+def sfjs(gsx,listx,gsy,listy):
|
|
15
|
+ s1 = gsx[len(gsx) - 1] - gsx[0]
|
|
16
|
+ s2 = s1 * s1
|
|
17
|
+ s3 = gsy[len(gsy) - 1] - gsy[0]
|
|
18
|
+ s4 = s3 * s3
|
|
19
|
+ s5 = s2 + s4
|
|
20
|
+ s6 = math.sqrt(s5)
|
|
21
|
+ t1 = listx[len(listx) - 1] - listx[0]
|
|
22
|
+ t2 = t1 * t1
|
|
23
|
+ t3 = listy[len(listy) - 1] - listy[0]
|
|
24
|
+ t4 = t3 * t3
|
|
25
|
+ t5 = t2 + t4
|
|
26
|
+ t6 = math.sqrt(t5)
|
|
27
|
+ num1 = round(s6/t6,8)
|
|
28
|
+ return num1
|
|
29
|
+
|
|
30
|
+def mxjd(gs,nw):
|
|
31
|
+ ii = 0
|
|
32
|
+ sum1 = 0
|
|
33
|
+ while ii < len(gs):
|
|
34
|
+ s1 = gs[ii] - nw[ii]
|
|
35
|
+ s2 = s1 * s1
|
|
36
|
+ sum1 = sum1 + s2
|
|
37
|
+ ii = ii + 1
|
|
38
|
+ s3 = sum1 / 2 / len(gs)
|
|
39
|
+ s4 = math.sqrt(s3)
|
|
40
|
+ num1 = s4 * 1000
|
|
41
|
+ return num1
|
|
42
|
+
|
|
43
|
+def xzjs(gsx,listx,gsy,listy):
|
|
44
|
+ s1 = gsx[len(gsx) - 1] - gsx[0]
|
|
45
|
+ s2 = gsy[len(gsy) - 1] - gsy[0]
|
|
46
|
+ s3 = s2 / s1
|
|
47
|
+ s4 = math.atan(s3)
|
|
48
|
+ t1 = listx[len(listx) - 1] - listx[0]
|
|
49
|
+ t2 = listy[len(listy) - 1] - listy[0]
|
|
50
|
+ t3 = t2 / t1
|
|
51
|
+ t4 = math.atan(t3)
|
|
52
|
+ n1 = s4 - t4
|
|
53
|
+ num1 = n1 * 180 / math.pi * 3600
|
|
54
|
+ return num1
|
|
55
|
+
|
|
56
|
+def gsjs(x,y,nlist):
|
|
57
|
+ listgsx = []
|
|
58
|
+ xstr1 = nlist[0] * x
|
|
59
|
+ xstr2 = nlist[1] * y
|
|
60
|
+ xx = xstr1 + xstr2 + nlist[2]
|
|
61
|
+ ystr1 = nlist[3] * x
|
|
62
|
+ ystr2 = nlist[4] * y
|
|
63
|
+ yy = ystr1 + ystr2 + nlist[5]
|
|
64
|
+ listgsx.append(xx)
|
|
65
|
+ listgsx.append(yy)
|
|
66
|
+ return listgsx
|
|
67
|
+
|
|
68
|
+def jzys1(listy, zxzby, listx, zxzbx, sf):
|
|
69
|
+ rlist = []
|
|
70
|
+ listlen = len(listy)
|
|
71
|
+ ll = 0
|
|
72
|
+ while ll < listlen:
|
|
73
|
+ # 第一个的值
|
|
74
|
+ # num1 = round(((listx[ll] - zxzbx) / sf),0)
|
|
75
|
+ # num2 = round(((listy[ll] - zxzby) / sf),0)
|
|
76
|
+ num1 = (listx[ll] - zxzbx)
|
|
77
|
+ num2 = (listy[ll] - zxzby)
|
|
78
|
+ rlist.append(num1)
|
|
79
|
+ rlist.append(num2)
|
|
80
|
+ ll = ll + 1
|
|
81
|
+ return rlist
|
|
82
|
+
|
|
83
|
+def jzys2(listy, zxzby, listx, zxzbx, sf):
|
|
84
|
+ rlist = []
|
|
85
|
+ listlen = len(listy)
|
|
86
|
+ ll = 0
|
|
87
|
+ while ll < listlen:
|
|
88
|
+ # 第一个的值
|
|
89
|
+ num2 = (-1) * (listx[ll] - zxzbx) / sf
|
|
90
|
+ num1 = (listy[ll] - zxzby) / sf
|
|
91
|
+ rlist.append(num1)
|
|
92
|
+ rlist.append(num2)
|
|
93
|
+ ll = ll + 1
|
|
94
|
+ return rlist
|
|
95
|
+
|
|
96
|
+def jzys3(listy, aa, bb):
|
|
97
|
+ rlist = []
|
|
98
|
+ listlen = len(listy)
|
|
99
|
+ ll = 0
|
|
100
|
+ while ll < listlen:
|
|
101
|
+ # 第一个的值
|
|
102
|
+ num1 = aa
|
|
103
|
+ num2 = bb
|
|
104
|
+ rlist.append(num1)
|
|
105
|
+ rlist.append(num2)
|
|
106
|
+ ll = ll + 1
|
|
107
|
+ return rlist
|
|
108
|
+
|
|
109
|
+def jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx, listnewy, zxzbnewy, listnewx, zxzbnewx, sf):
|
|
110
|
+ rlist = []
|
|
111
|
+ listlen = len(listnewx)
|
|
112
|
+ ll = 0
|
|
113
|
+ while ll < listlen:
|
|
114
|
+ num1 = (listpastx[ll] - listnewx[ll] - zxzbpastx + zxzbnewx) / sf
|
|
115
|
+ num2 = (listpasty[ll] - listnewy[ll] - zxzbpasty + zxzbnewy) / sf
|
|
116
|
+ rlist.append(round(num1,6))
|
|
117
|
+ rlist.append(round(num2,6))
|
|
118
|
+ ll = ll + 1
|
|
119
|
+ return rlist
|
|
120
|
+
|
|
121
|
+def jzys5(listp, zxzbp, sf):
|
|
122
|
+ rlist = []
|
|
123
|
+ listlen = len(listp)
|
|
124
|
+ ll = 0
|
|
125
|
+ while ll < listlen:
|
|
126
|
+ num1 = (listp[ll] - zxzbp) / sf
|
|
127
|
+ rlist.append(num1)
|
|
128
|
+ ll = ll + 1
|
|
129
|
+ return rlist
|
|
130
|
+
|
|
131
|
+def jzys6(listp, num):
|
|
132
|
+ rlist = []
|
|
133
|
+ listlen = len(listp)
|
|
134
|
+ ll = 0
|
|
135
|
+ while ll < listlen:
|
|
136
|
+ num1 = listp[ll] * num
|
|
137
|
+ rlist.append(num1)
|
|
138
|
+ ll = ll + 1
|
|
139
|
+ return rlist
|
|
140
|
+
|
|
141
|
+def cjh(listp):
|
|
142
|
+ rp = 0
|
|
143
|
+ listlen = len(listp)
|
|
144
|
+ ll = 0
|
|
145
|
+ while ll < listlen:
|
|
146
|
+ num1 = listp[ll] * listp[ll]
|
|
147
|
+ rp = rp + num1
|
|
148
|
+ ll = ll + 1
|
|
149
|
+ return rp
|
|
150
|
+
|
|
151
|
+def cjh2(lista, listb):
|
|
152
|
+ rp = 0
|
|
153
|
+ listlen = len(lista)
|
|
154
|
+ ll = 0
|
|
155
|
+ while ll < listlen:
|
|
156
|
+ num1 = lista[ll] * listb[ll]
|
|
157
|
+ rp = rp + num1
|
|
158
|
+ ll = ll + 1
|
|
159
|
+ return rp
|
|
160
|
+
|
|
161
|
+def gsys(listnewp, jxlist1, jylist1, lxlist, lylist, arrz, sf, zxzbnewp, zxzbpastp, ii):
|
|
162
|
+ # 新x+(矩阵[jx1 jy1 lx1 ly1]*矩阵z)*缩放-新重心坐标x+旧重心坐标x
|
|
163
|
+ rlist = []
|
|
164
|
+ listlen = len(listnewp)
|
|
165
|
+ ll = 0
|
|
166
|
+ while ll < listlen:
|
|
167
|
+ arr0 = np.array((jxlist1[ll], jylist1[ll],
|
|
168
|
+ lxlist[2*ll+ii], lylist[2*ll+ii]))
|
|
169
|
+ arr1 = np.matmul(arr0, arrz)
|
|
170
|
+ arr3 = sf * arr1
|
|
171
|
+ newp = listnewp[ll] + arr3 - zxzbnewp + zxzbpastp
|
|
172
|
+ rlist.append(newp)
|
|
173
|
+ ll = ll + 1
|
|
174
|
+ return rlist
|
|
175
|
+
|
|
176
|
+def xcys(newlist, pastlist):
|
|
177
|
+ listlen = len(newlist)
|
|
178
|
+ ll = 0
|
|
179
|
+ rlist = []
|
|
180
|
+ while ll < listlen:
|
|
181
|
+ num1 =pastlist[ll] - newlist[ll]
|
|
182
|
+ num2 = num1 * 1000
|
|
183
|
+ rlist.append(num2)
|
|
184
|
+ ll = ll + 1
|
|
185
|
+ return rlist
|
|
186
|
+
|
|
187
|
+def takeFirst(elem):
|
|
188
|
+ return elem[0]
|
|
189
|
+
|
|
190
|
+#endregion
|
|
191
|
+
|
|
192
|
+def insert_into_database1(database,utf_tn,listname1,listname,gsx,gsy,listpastx1,listpasty1,listnewx1,listnewy1,nlist,utf_pan,utf_nn,wypd,sfxs,xzj,pycsx,pycsy,mxjdx,mxjdy,zxzbpastx,zxzbpasty,zxzbnewx,zxzbnewy,n1,n2,n3,n4,n5,n6):
|
|
193
|
+ #将结果输出到数据库
|
|
194
|
+ db1 = sqlite3.connect(database)
|
|
195
|
+ #获取游标
|
|
196
|
+ cursor1 = db1.cursor()
|
|
197
|
+ #先清除已有数据,用来更新
|
|
198
|
+ try:
|
|
199
|
+ sqlstr3 = 'delete from GS_Trans_Param WHERE TableName = ?'
|
|
200
|
+ sqlstr4 = 'delete from GS_Trans_Point WHERE TableName = ?'
|
|
201
|
+ sqlstr5 = 'delete from GS_Result_Point WHERE TableName = ?'
|
|
202
|
+ cursor1.execute(sqlstr3,(utf_tn,))
|
|
203
|
+ cursor1.execute(sqlstr4,(utf_tn,))
|
|
204
|
+ cursor1.execute(sqlstr5,(utf_tn,))
|
|
205
|
+ except:
|
|
206
|
+ pass
|
|
207
|
+ cursor1.execute('INSERT INTO GS_Trans_Param(TableName,Last_ResultName,New_ResultName,Dis_RefValue,Pt_CalCount,Scale_Factor,Rotate_Angle,Trans_X,Trans_Y,Model_AccX,Model_AccY,Last_GcX,Last_GcY,New_GcX,New_GcY,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,wypd,len(listname),sfxs,xzj,pycsx,pycsy,mxjdx,mxjdy,zxzbpastx,zxzbpasty,zxzbnewx,zxzbnewy,n1,n2,n3,n4,n5,n6,))
|
|
208
|
+ #Trans_Point和Result_Point一起存
|
|
209
|
+ for iname in listname1:
|
|
210
|
+ if iname in listname:
|
|
211
|
+ #属于没问题点的
|
|
212
|
+ #直接使用gsx,gsy
|
|
213
|
+ utf_pointname = to_utf8(str(iname))
|
|
214
|
+ wystr = to_utf8('稳定')
|
|
215
|
+ index1 = listname.index(iname)
|
|
216
|
+ numm1 = round(gsx[index1],4)
|
|
217
|
+ numm2 = round(gsy[index1],4)
|
|
218
|
+ #先找到首次的index
|
|
219
|
+ index2 = listname1.index(iname)
|
|
220
|
+ r1 = (listpastx1[index2] - gsx[index1])*1000
|
|
221
|
+ r2 = (listpasty1[index2] - gsy[index1])*1000
|
|
222
|
+ r3 = r1 * r1
|
|
223
|
+ r4 = r2 * r2
|
|
224
|
+ r5 = r3 + r4
|
|
225
|
+ r6 = round(math.sqrt(r5),1)
|
|
226
|
+ numn1 = listpastx1[index2]
|
|
227
|
+ numn2 = listnewx1[index2]
|
|
228
|
+ cursor1.execute('INSERT INTO GS_Trans_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,New_X,New_Y) VALUES (?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listnewx1[index2],listnewy1[index2],))
|
|
229
|
+ cursor1.execute('INSERT INTO GS_Result_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,Result_X,Result_Y,Cal_X,Cal_Y,Last_ResultX,Last_ResultY,Last_ResultP,Last_CalX,Last_CalY,Last_CalP,Dis_Ass) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listpastx1[index2],listpasty1[index2],numm1,numm2,0,0,0,r1,r2,r6,wystr,))
|
|
230
|
+ else:
|
|
231
|
+ index2 = listname1.index(iname)
|
|
232
|
+ utf_pointname = to_utf8(str(iname))
|
|
233
|
+ #首先判断有没有第一个点
|
|
234
|
+ if listnewx1[index2] != 0:
|
|
235
|
+ #有问题的点,使用公式跑
|
|
236
|
+ listxy = gsjs(listnewx1[index2],listnewy1[index2],nlist)
|
|
237
|
+ #判断有没有第一次的数据,没有就不写
|
|
238
|
+ if listpastx1[index2] != 0:
|
|
239
|
+ r1 = (listpastx1[index2] - listxy[0])*1000
|
|
240
|
+ r2 = (listpasty1[index2] - listxy[1])*1000
|
|
241
|
+ r3 = r1 * r1
|
|
242
|
+ r4 = r2 * r2
|
|
243
|
+ r5 = r3 + r4
|
|
244
|
+ r6 = round(math.sqrt(r5),1)
|
|
245
|
+ if r6 > 500:
|
|
246
|
+ wystr = to_utf8('复建')
|
|
247
|
+ cursor1.execute('INSERT INTO GS_Result_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,Result_X,Result_Y,Cal_X,Cal_Y,Last_ResultX,Last_ResultY,Last_ResultP,Last_CalX,Last_CalY,Last_CalP,Dis_Ass) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listxy[0],listxy[1],listxy[0],listxy[1],r1,r2,r6,r1,r2,r6,wystr,))
|
|
248
|
+ else:
|
|
249
|
+ wystr = to_utf8('位移')
|
|
250
|
+ cursor1.execute('INSERT INTO GS_Result_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,Result_X,Result_Y,Cal_X,Cal_Y,Last_ResultX,Last_ResultY,Last_ResultP,Last_CalX,Last_CalY,Last_CalP,Dis_Ass) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listxy[0],listxy[1],listxy[0],listxy[1],r1,r2,r6,r1,r2,r6,wystr,))
|
|
251
|
+ else:
|
|
252
|
+ wystr = to_utf8('新建')
|
|
253
|
+ cursor1.execute('INSERT INTO GS_Result_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,Result_X,Result_Y,Cal_X,Cal_Y,Last_ResultX,Last_ResultY,Last_ResultP,Last_CalX,Last_CalY,Last_CalP,Dis_Ass) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listnewx1[index2],listnewy1[index2],listpastx1[index2],listpasty1[index2],0,0,0,0,0,0,wystr,))
|
|
254
|
+ #数据库执行
|
|
255
|
+ db1.commit()
|
|
256
|
+ #做完一切后,先关闭游标,再关闭数据库
|
|
257
|
+ cursor1.close()
|
|
258
|
+ db1.close()
|
|
259
|
+
|
|
260
|
+def tablein(outpath,str1):
|
|
261
|
+ listcgcs1 = []
|
|
262
|
+ listname1 = []
|
|
263
|
+ listpastx1 = []
|
|
264
|
+ listpasty1 = []
|
|
265
|
+ listname = []
|
|
266
|
+ listnewx = []
|
|
267
|
+ listnewy = []
|
|
268
|
+ listpastx = []
|
|
269
|
+ listpasty = []
|
|
270
|
+ listcgcs = []
|
|
271
|
+ listnewx1 = []
|
|
272
|
+ listnewy1 = []
|
|
273
|
+ points = 0
|
|
274
|
+ #查询,提取需要的数据
|
|
275
|
+ db2 = sqlite3.connect(outpath)
|
|
276
|
+ cursor2 = db2.cursor()
|
|
277
|
+ utfstr1 = to_utf8(str1)
|
|
278
|
+ sqlstr1 = 'SELECT * FROM GS_Input_Point WHERE TableName = ?'
|
|
279
|
+ cursor2.execute(sqlstr1,(utfstr1,))
|
|
280
|
+ all_da = cursor2.fetchall()
|
|
281
|
+ for da in all_da:
|
|
282
|
+ listpastx.append(da[3])
|
|
283
|
+ listpastx1.append(da[3])
|
|
284
|
+ listpasty.append(da[4])
|
|
285
|
+ listpasty1.append(da[4])
|
|
286
|
+ listnewx.append(da[5])
|
|
287
|
+ listnewx1.append(da[5])
|
|
288
|
+ listnewy.append(da[6])
|
|
289
|
+ listnewy1.append(da[6])
|
|
290
|
+ listname.append(da[7].decode('utf-8'))
|
|
291
|
+ listname1.append(da[7].decode('utf-8'))
|
|
292
|
+ listcgcs.append(da[8])
|
|
293
|
+ listcgcs1.append(da[8])
|
|
294
|
+ points = points + 1
|
|
295
|
+ sqlstr2 = 'SELECT * FROM GS_Input_Param WHERE TableName = ?'
|
|
296
|
+ cursor2.execute(sqlstr2,(utfstr1,))
|
|
297
|
+ all_par = cursor2.fetchall()
|
|
298
|
+ pastname = all_par[0][1].decode('utf-8')
|
|
299
|
+ newname = all_par[0][2].decode('utf-8')
|
|
300
|
+ # pjbc是平均边长
|
|
301
|
+ # fxzwc是方向中误差,zrbzwc是最弱边边长相对中误差,pjbcs是平均边数,pjfxs是平均方向数,sf是缩放值
|
|
302
|
+ # 新增总边数zbs,总方向数zfxs
|
|
303
|
+ # 先计算位移判断值
|
|
304
|
+ pjbc = all_par[0][3]
|
|
305
|
+ fxzwc = all_par[0][4]
|
|
306
|
+ zrbzwc = all_par[0][5]
|
|
307
|
+ zbs = all_par[0][7]
|
|
308
|
+ zfxs = all_par[0][8]
|
|
309
|
+ sf = all_par[0][9]
|
|
310
|
+ pjbcs = zbs / points
|
|
311
|
+ pjfxs = zfxs / points
|
|
312
|
+ # 再拆细点
|
|
313
|
+ wy1 = pjbc / 1000
|
|
314
|
+ wy2 = wy1 * zrbzwc * 1e6
|
|
315
|
+ wypd1 = wy2 * wy2 / pjbcs
|
|
316
|
+ # 206.265是常数系数
|
|
317
|
+ wy3 = pjbc * fxzwc / 206.265
|
|
318
|
+ wypd2 = wy3 * wy3 / pjfxs
|
|
319
|
+ wypd3 = math.sqrt(wypd1 + wypd2)
|
|
320
|
+ wypd = round(wypd3 * 3, 4)
|
|
321
|
+ wypd0 = wypd
|
|
322
|
+ #更新下数据库(参数部分)
|
|
323
|
+ sqlstr3 = 'update GS_Input_Param set Pt_Count=?,Avg_MSL=?,Avg_Dir=? WHERE TableName = ?'
|
|
324
|
+ cursor2.execute(sqlstr3,(points,pjbcs,pjfxs,utfstr1,))
|
|
325
|
+ #数据库执行
|
|
326
|
+ db2.commit()
|
|
327
|
+ #做完一切后,先关闭游标,再关闭数据库
|
|
328
|
+ cursor2.close()
|
|
329
|
+ db2.close()
|
|
330
|
+ js = 0
|
|
331
|
+ return listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs,sf, newname, pastname, js,listnewx1,listnewy1
|
|
332
|
+
|
|
333
|
+def bhjs(dbpath,listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs, sf, newname, pastname, js,listnewx1,listnewy1,excelname):
|
|
334
|
+ np.set_printoptions(suppress=False)
|
|
335
|
+ # pt用于给点数point计数
|
|
336
|
+ # point会随着回递函数而减少
|
|
337
|
+ pt = 0
|
|
338
|
+ sumnewx = 0
|
|
339
|
+ sumnewy = 0
|
|
340
|
+ sumpastx = 0
|
|
341
|
+ sumpasty = 0
|
|
342
|
+ gszbx = []
|
|
343
|
+ gszby = []
|
|
344
|
+ arrz = []
|
|
345
|
+ # #一个计数,把第一次改算坐标全部记下来
|
|
346
|
+ # 存的第一次的改算值和起限差
|
|
347
|
+ jslist = []
|
|
348
|
+ # 等同于listnewx/y1
|
|
349
|
+ jslist1 = []
|
|
350
|
+ # listnewx/y,listpastx/y,listcgcs都是要变的
|
|
351
|
+ # 带1的是原始的
|
|
352
|
+ while pt < points:
|
|
353
|
+ sumnewx = sumnewx + listnewx[pt]
|
|
354
|
+ sumnewy = sumnewy + listnewy[pt]
|
|
355
|
+ sumpastx = sumpastx + listpastx[pt]
|
|
356
|
+ sumpasty = sumpasty + listpasty[pt]
|
|
357
|
+ pt = pt + 1
|
|
358
|
+ # 计算4个重心坐标(最新一期和上一期的)
|
|
359
|
+ zxzbnewx = (sumnewx / points)
|
|
360
|
+ zxzbnewy = (sumnewy / points)
|
|
361
|
+ zxzbpastx = (sumpastx / points)
|
|
362
|
+ zxzbpasty = (sumpasty / points)
|
|
363
|
+ # 先计算平移参数
|
|
364
|
+ # pycsx = abs(zxzbnewx - zxzbpastx) * 1000
|
|
365
|
+ # pycsy = abs(zxzbnewy - zxzbpasty) * 1000
|
|
366
|
+ pycsx = round((zxzbpastx - zxzbnewx),4)
|
|
367
|
+ pycsy = round((zxzbpasty - zxzbnewy),4)
|
|
368
|
+ # 分别得k,sita的值
|
|
369
|
+ klist = jzys1(listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
|
|
370
|
+ slist = jzys2(listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
|
|
371
|
+ # 得dx,dy
|
|
372
|
+ dxlist = jzys3(listnewy, 1, 0)
|
|
373
|
+ dylist = jzys3(listnewy, 0, 1)
|
|
374
|
+ # 矩阵太难用了,还是手动计算
|
|
375
|
+ # 分别计算k、s、dx、dy的乘积和
|
|
376
|
+ k2 = cjh(klist)
|
|
377
|
+ s2 = cjh(slist)
|
|
378
|
+ dx2 = cjh(dxlist)
|
|
379
|
+ dy2 = cjh(dylist)
|
|
380
|
+ # 这里再创建矩阵1
|
|
381
|
+ arr1 = np.array(((k2, 0, 0, 0), (0, s2, 0, 0),
|
|
382
|
+ (0, 0, dx2, 0), (0, 0, 0, dy2)))
|
|
383
|
+ # 矩阵1的逆矩阵矩阵2
|
|
384
|
+ arr2 = np.linalg.inv(arr1)
|
|
385
|
+ # 求矩阵l
|
|
386
|
+ llist = jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx,
|
|
387
|
+ listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
|
|
388
|
+ # 得到数列e1,e2,e3,e4
|
|
389
|
+ e1 = cjh2(klist, llist)
|
|
390
|
+ e2 = cjh2(slist, llist)
|
|
391
|
+ e3 = cjh2(dxlist, llist)
|
|
392
|
+ e4 = cjh2(dylist, llist)
|
|
393
|
+ arrl = np.array(((e1), (e2), (e3), (e4)))
|
|
394
|
+ # 得到矩阵z
|
|
395
|
+ arrz = np.matmul(arr2, arrl)
|
|
396
|
+ # 求转换矩阵
|
|
397
|
+ jxlist1 = jzys5(listnewx, zxzbnewx, sf)
|
|
398
|
+ jylist1 = jzys5(listnewy, zxzbnewy, sf)
|
|
399
|
+ jxlist2 = jylist1
|
|
400
|
+ # jylist2 = jxlist1 * (-1)
|
|
401
|
+ jylist2 = jzys6(jxlist1, -1)
|
|
402
|
+ lxlist = jzys3(jylist1, 1, 0)
|
|
403
|
+ lylist = jzys3(jylist1, 0, 1)
|
|
404
|
+ # 求改算坐标
|
|
405
|
+ gsx = gsys(listnewx, jxlist1, jylist1, lxlist,
|
|
406
|
+ lylist, arrz, sf, zxzbnewx, zxzbpastx, 0)
|
|
407
|
+ gsy = gsys(listnewy, jxlist2, jylist2, lxlist,
|
|
408
|
+ lylist, arrz, sf, zxzbnewy, zxzbpasty, 1)
|
|
409
|
+ #缩放系数也是计算出来的sfxs
|
|
410
|
+ sfxs = sfjs(gsx,listnewx,gsy,listnewy)
|
|
411
|
+ #旋转角,模型精度
|
|
412
|
+ xzj = xzjs(gsx,listnewx,gsy,listnewy)
|
|
413
|
+ mxjdx = mxjd(gsx,listpastx)
|
|
414
|
+ mxjdy = mxjd(gsy,listpasty)
|
|
415
|
+ # 还是要先求较差
|
|
416
|
+ xcx = xcys(gsx, listpastx)
|
|
417
|
+ xcy = xcys(gsy, listpasty)
|
|
418
|
+ # 这里记录下第一次所有点的改算坐标
|
|
419
|
+ if js == 0:
|
|
420
|
+ lengs = len(gsx)
|
|
421
|
+ xx = 0
|
|
422
|
+ while xx < lengs:
|
|
423
|
+ gszbx.append(gsx[xx])
|
|
424
|
+ gszby.append(gsy[xx])
|
|
425
|
+ zblist1 = []
|
|
426
|
+ zblist1.append(gsx[xx])
|
|
427
|
+ zblist1.append(gsy[xx])
|
|
428
|
+ zblist1.append(xcx[xx])
|
|
429
|
+ zblist1.append(xcy[xx])
|
|
430
|
+ jslist.append(zblist1)
|
|
431
|
+ zblist2 = []
|
|
432
|
+ zblist2.append(listnewx[xx])
|
|
433
|
+ zblist2.append(listnewy[xx])
|
|
434
|
+ jslist1.append(zblist2)
|
|
435
|
+ xx = xx + 1
|
|
436
|
+ # 后面不需要经过这个if
|
|
437
|
+ # 判定方式是用差值平方和和位移对比
|
|
438
|
+ gxpd = 0
|
|
439
|
+ lenxc = len(xcx)
|
|
440
|
+ yy = 0
|
|
441
|
+ while yy < lenxc:
|
|
442
|
+ sumxcx = xcx[yy] * xcx[yy]
|
|
443
|
+ sumxcy = xcy[yy] * xcy[yy]
|
|
444
|
+ sumxc = sumxcx + sumxcy
|
|
445
|
+ xcpd = math.sqrt(sumxc)
|
|
446
|
+ if xcpd > wypd:
|
|
447
|
+ gxpd = -1
|
|
448
|
+ break
|
|
449
|
+ yy = yy + 1
|
|
450
|
+ if gxpd == 0:
|
|
451
|
+ # 输出之前把转换参数都算出来
|
|
452
|
+ # X=(z1+1)*x+z2*y+(旧重心坐标x-新重心坐标x-新重心坐标x*z1-新重心坐标y*z2+z3)
|
|
453
|
+ # Y=(-z2)*x+(z1+1)*y+(z1*新重心坐标y+新重心坐标x*z2+z4+旧重心坐标y-新重心坐标y)
|
|
454
|
+ n1 = float(arrz[0]) + 1
|
|
455
|
+ n2 = float(arrz[1])
|
|
456
|
+ s1 = zxzbnewx * float(arrz[0])
|
|
457
|
+ s2 = zxzbnewy * float(arrz[1])
|
|
458
|
+ n3 = zxzbpastx - zxzbnewx - s1 - s2 + float(arrz[2])
|
|
459
|
+ n4 = (-1) * float(arrz[1])
|
|
460
|
+ n5 = n1
|
|
461
|
+ s3 = (-1)*float(arrz[0])*zxzbnewy
|
|
462
|
+ s4 = float(arrz[1])*zxzbnewx
|
|
463
|
+ n6 = s3 + s4 + float(arrz[3])+zxzbpasty-zxzbnewy
|
|
464
|
+ sxylist = []
|
|
465
|
+ sxylist.append(n1)
|
|
466
|
+ sxylist.append(n2)
|
|
467
|
+ sxylist.append(n3)
|
|
468
|
+ sxylist.append(n4)
|
|
469
|
+ sxylist.append(n5)
|
|
470
|
+ sxylist.append(n6)
|
|
471
|
+ # 输出
|
|
472
|
+ relist1 = []
|
|
473
|
+ relist1.append(listname)
|
|
474
|
+ relist1.append(xcx)
|
|
475
|
+ relist1.append(xcy)
|
|
476
|
+ relist1.append(listcgcs)
|
|
477
|
+ relist1.append(gszbx)
|
|
478
|
+ relist1.append(gszby)
|
|
479
|
+ relist1.append(sxylist)
|
|
480
|
+ print(" Finish!")
|
|
481
|
+ # 输出的那个不是改算坐标,而是有计算的改算坐标
|
|
482
|
+ newgsx = []
|
|
483
|
+ newgsy = []
|
|
484
|
+ lengs1 = len(gszbx)
|
|
485
|
+ nlist = relist1[6]
|
|
486
|
+ # return relist
|
|
487
|
+ #中文再来一次
|
|
488
|
+ utf_pan = to_utf8(pastname)
|
|
489
|
+ utf_nn = to_utf8(newname)
|
|
490
|
+ utf_tn = to_utf8(excelname)
|
|
491
|
+ insert_into_database1(dbpath,utf_tn,listname1,listname,gsx,gsy,listpastx1,listpasty1,listnewx1,listnewy1,nlist,utf_pan,utf_nn,wypd,sfxs,xzj,pycsx,pycsy,mxjdx,mxjdy,zxzbpastx,zxzbpasty,zxzbnewx,zxzbnewy,n1,n2,n3,n4,n5,n6)
|
|
492
|
+
|
|
493
|
+ else:
|
|
494
|
+ # 先把所有的合在一起,方便删除
|
|
495
|
+ lenlist1 = len(xcx)
|
|
496
|
+ ii = 0
|
|
497
|
+ relist1 = []
|
|
498
|
+ while ii < lenlist1:
|
|
499
|
+ smlist1 = []
|
|
500
|
+ nn2 = xcx[ii] * xcx[ii]
|
|
501
|
+ mm2 = xcy[ii] * xcy[ii]
|
|
502
|
+ nm2 = math.sqrt(nn2 + mm2)
|
|
503
|
+ smlist1.append(nm2)
|
|
504
|
+ smlist1.append(listname[ii])
|
|
505
|
+ smlist1.append(listnewx[ii])
|
|
506
|
+ smlist1.append(listnewy[ii])
|
|
507
|
+ smlist1.append(listpastx[ii])
|
|
508
|
+ smlist1.append(listpasty[ii])
|
|
509
|
+ relist1.append(smlist1)
|
|
510
|
+ ii = ii + 1
|
|
511
|
+ # 直接删除最大的那个
|
|
512
|
+ relist1.sort(key=takeFirst, reverse=True)
|
|
513
|
+ num1 = relist1[0]
|
|
514
|
+ # 获取name
|
|
515
|
+ num2 = num1[1]
|
|
516
|
+ ii2 = 0
|
|
517
|
+ mm2 = 0
|
|
518
|
+ while ii2 < lenlist1:
|
|
519
|
+ if listname[ii2] == num2:
|
|
520
|
+ del listname[ii2]
|
|
521
|
+ del listnewx[ii2]
|
|
522
|
+ del listnewy[ii2]
|
|
523
|
+ del listpastx[ii2]
|
|
524
|
+ del listpasty[ii2]
|
|
525
|
+ points = points - 1
|
|
526
|
+ break
|
|
527
|
+ else:
|
|
528
|
+ ii2 = ii2 + 1
|
|
529
|
+ while mm2 < len(listcgcs):
|
|
530
|
+ if listname1[mm2] == num2:
|
|
531
|
+ listcgcs[mm2] = -1
|
|
532
|
+ break
|
|
533
|
+ else:
|
|
534
|
+ mm2 = mm2 + 1
|
|
535
|
+ print(" Finish!")
|
|
536
|
+ js1 = 1
|
|
537
|
+ bhjs(dbpath,listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx,
|
|
538
|
+ listpasty, points, listcgcs, sf, newname, pastname, js1,listnewx1,listnewy1,excelname)
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+# 主函数 计算
|
|
542
|
+def main_function(dbpath,file_name):
|
|
543
|
+ #从数据库中调用
|
|
544
|
+ listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs,sf, newname, pastname, js,listnewx1,listnewy1 = tablein(dbpath,file_name)
|
|
545
|
+ #计算
|
|
546
|
+ bhjs(dbpath,listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs,sf, newname, pastname, js,listnewx1,listnewy1,file_name)
|
|
547
|
+ messagebox.showinfo("提示",f"文件 '{file_name}' 计算成功!")
|