控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

GScompute.py 21KB

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