控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GScompute.py 19KB

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