工具箱相关
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.

Newjson2023.py 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. import re
  2. import math
  3. import json
  4. import arcpy
  5. import os
  6. #基准点txt,位移list,夸张系数,输出txt(?),输出文件夹
  7. def drawline(shppath,linelist,ran1,outpath,txtpath,ran22):
  8. ran0 = float(ran1)
  9. ran2 = float(ran22)
  10. mm = 0
  11. nameA = ''
  12. #结果点(?)
  13. resultp = []
  14. #坐标系文件
  15. prjpath = r'D:\4work_now\20240226TZL\CGCS2000_3_Degree_GK_Zone_34.prj'
  16. prjpath1 = r'D:\4work_now\20240226TZL\GCS_WGS_1984.prj'
  17. #大概是先把计算结果写上
  18. with open(outpath,'w') as files:
  19. #循环列表
  20. while mm < len(linelist):
  21. kk = 0
  22. #读基准点文件
  23. with open(shppath,'r') as filesA:
  24. for ppstr1 in filesA:
  25. #基准点的信息
  26. pname = ppstr1.split(',',-1)[1]
  27. #这里加一点,识别角度值
  28. angleA = readangle(pname)
  29. xP = float(ppstr1.split(',',-1)[2])
  30. yP = float(ppstr1.split(',',-1)[3])
  31. zP = float(ppstr1.split(',',-1)[4])
  32. #读位移是否有和这个匹配的
  33. str0 = linelist[mm]
  34. #把一些数据反过来写
  35. nameA = str0.split(',',-1)[0]
  36. nameP = nameA.split('-',-1)[-1]
  37. if nameP == 'BPL':
  38. xA1= float(str0.split(',',-1)[2])
  39. yA1= float(str0.split(',',-1)[1])
  40. xA= float(str0.split(',',-1)[4])
  41. yA= float(str0.split(',',-1)[3])
  42. xA122= float(str0.split(',',-1)[2])
  43. yA122= float(str0.split(',',-1)[1])
  44. xA22= float(str0.split(',',-1)[4])
  45. yA22= float(str0.split(',',-1)[3])
  46. elif nameP == 'KHP':
  47. xA1= float(str0.split(',',-1)[1])* (-1)
  48. yA1= float(str0.split(',',-1)[2])* (-1)
  49. xA= float(str0.split(',',-1)[3])* (-1)
  50. yA= float(str0.split(',',-1)[4])* (-1)
  51. xA122= float(str0.split(',',-1)[1])
  52. yA122= float(str0.split(',',-1)[2])
  53. xA22= float(str0.split(',',-1)[3])
  54. yA22= float(str0.split(',',-1)[4])
  55. elif nameP == 'RFH':
  56. xA1= float(str0.split(',',-1)[1])
  57. yA1= float(str0.split(',',-1)[2])
  58. xA= float(str0.split(',',-1)[3])
  59. yA= float(str0.split(',',-1)[4])
  60. xA122= float(str0.split(',',-1)[1])
  61. yA122= float(str0.split(',',-1)[2])
  62. xA22= float(str0.split(',',-1)[3])
  63. yA22= float(str0.split(',',-1)[4])
  64. elif nameP == 'BPR':
  65. xA1= float(str0.split(',',-1)[2])*(-1)
  66. yA1= float(str0.split(',',-1)[1])
  67. xA= float(str0.split(',',-1)[4])*(-1)
  68. yA= float(str0.split(',',-1)[3])
  69. xA122= float(str0.split(',',-1)[2])
  70. yA122= float(str0.split(',',-1)[1])
  71. xA22= float(str0.split(',',-1)[4])
  72. yA22= float(str0.split(',',-1)[3])
  73. elif nameP == 'THP':
  74. xA1= float(str0.split(',',-1)[2])*(-1)
  75. yA1= float(str0.split(',',-1)[1])
  76. xA= float(str0.split(',',-1)[4])*(-1)
  77. yA= float(str0.split(',',-1)[3])
  78. xA122= float(str0.split(',',-1)[2])
  79. yA122= float(str0.split(',',-1)[1])
  80. xA22= float(str0.split(',',-1)[4])
  81. yA22= float(str0.split(',',-1)[3])
  82. else:
  83. xA1= float(str0.split(',',-1)[1])
  84. yA1= float(str0.split(',',-1)[2])
  85. xA= float(str0.split(',',-1)[3])
  86. yA= float(str0.split(',',-1)[4])
  87. xA122= float(str0.split(',',-1)[1])
  88. yA122= float(str0.split(',',-1)[2])
  89. xA22= float(str0.split(',',-1)[3])
  90. yA22= float(str0.split(',',-1)[4])
  91. if nameA == pname:
  92. #一些距离参数
  93. xB = (xA * ran0)
  94. yB = (yA * ran0)
  95. xB1 = (xA1 * ran2)
  96. yB1 = (yA1 * ran2)
  97. #总距离
  98. xA2 = xA * xA
  99. yA2 = yA * yA
  100. xA21 = xA1 * xA1
  101. yA21 = yA1 * yA1
  102. disA = math.sqrt(xA2 + yA2)
  103. disA1 = math.sqrt(xA21 + yA21)
  104. #这里分别对应x方向和y方向
  105. xpx = xP - xB
  106. xpy = yP
  107. ypx = xP
  108. ypy = yB + yP
  109. xpx1 = xP - xB1
  110. xpy1 = yP
  111. ypx1 = xP
  112. ypy1 = yB1 + yP
  113. #一同计算得到第二个点(大概)
  114. xangle = float(angleA)
  115. yangle = float(angleA)
  116. arrpointx = rotatecordiateX(xangle,xpx,xpy,xP,yP,xB)
  117. arrpointy = rotatecordiateY(yangle,ypx,ypy,xP,yP,yB)
  118. arrpointx1 = rotatecordiateX(xangle,xpx1,xpy1,xP,yP,xB1)
  119. arrpointy1 = rotatecordiateY(yangle,ypx1,ypy1,xP,yP,yB1)
  120. pppointx = float(arrpointx[0]) + float(arrpointy[0]) - xP
  121. pppointy = float(arrpointx[1]) + float(arrpointy[1]) - yP
  122. pppointx1 = float(arrpointx1[0]) + float(arrpointy1[0]) - xP
  123. pppointy1 = float(arrpointx1[1]) + float(arrpointy1[1]) - yP
  124. #写入
  125. files.write(pname + "," + "px," + str(arrpointx[0]) + "," + str(arrpointx[1]) + "," + str(zP) + "," +str(xA22)+ "\n")
  126. files.write(pname + "," + "py," + str(arrpointy[0]) + "," + str(arrpointy[1]) + "," + str(zP) + "," +str(yA22)+ "\n")
  127. files.write(pname + "," + "pp," + str(pppointx) + "," + str(pppointy) + "," + str(zP) + ","+ str(disA) + "\n")
  128. files.write(pname + "," + "px1," + str(arrpointx1[0]) + "," + str(arrpointx1[1]) + "," + str(zP) + "," +str(xA122)+ "\n")
  129. files.write(pname + "," + "py1," + str(arrpointy1[0]) + "," + str(arrpointy1[1]) + "," + str(zP) + "," +str(yA122)+ "\n")
  130. files.write(pname + "," + "pp1," + str(pppointx1) + "," + str(pppointy1) + "," + str(zP) + ","+ str(disA1) + "\n")
  131. mm = mm + 1
  132. kk = 1
  133. break
  134. else:
  135. #意思是继续寻找和位移匹配的点
  136. continue
  137. if kk == 0 :
  138. mm = mm + 1
  139. # print(nameA)
  140. #最后输出
  141. resultp.append(outpath)
  142. resultp.append(prjpath)
  143. resultp.append(prjpath1)
  144. resultp.append(txtpath)
  145. return resultp
  146. def rotatecordiateX(rang,xpx,xpy,xP,yP,zf):
  147. rx = float(xpx)
  148. ry = float(xpy)
  149. ox = float(xP)
  150. oy = float(yP)
  151. aa = 1
  152. dis = math.sqrt((rx - ox)*(rx-ox) + (ry - oy)*(ry-oy))
  153. if aa == 0:
  154. if zf > 0:
  155. if rang <= 90:
  156. angle = math.radians(rang)
  157. cosA = math.cos(angle)
  158. sinA = math.sin(angle)
  159. x0 = dis * cosA
  160. y0 = dis * sinA
  161. x0n = ox +x0
  162. y0n = oy +y0
  163. elif rang > 90 and rang <= 180:
  164. ang = 180 - rang
  165. angle = math.radians(ang)
  166. cosA = math.cos(angle)
  167. sinA = math.sin(angle)
  168. x0 = dis * cosA
  169. y0 = dis * sinA
  170. x0n = ox-x0
  171. y0n = oy+y0
  172. elif rang > 180 and rang <=270:
  173. ang = rang - 180
  174. angle = math.radians(ang)
  175. cosA = math.cos(angle)
  176. sinA = math.sin(angle)
  177. x0 = dis * cosA
  178. y0 = dis * sinA
  179. x0n =ox-x0
  180. y0n = oy-y0
  181. else:
  182. ang = 360 - rang
  183. angle = math.radians(ang)
  184. cosA = math.cos(angle)
  185. sinA = math.sin(angle)
  186. x0 = dis * cosA
  187. y0 = dis * sinA
  188. x0n = ox + x0
  189. y0n = oy-y0
  190. else:
  191. if rang <= 90:
  192. angle = math.radians(rang)
  193. cosA = math.cos(angle)
  194. sinA = math.sin(angle)
  195. x0 = dis * cosA
  196. y0 = dis * sinA
  197. x0n = ox - x0
  198. y0n = oy -y0
  199. elif rang > 90 and rang <= 180:
  200. ang = 180 - rang
  201. angle = math.radians(ang)
  202. cosA = math.cos(angle)
  203. sinA = math.sin(angle)
  204. x0 = dis * cosA
  205. y0 = dis * sinA
  206. x0n = ox + x0
  207. y0n = oy - y0
  208. elif rang > 180 and rang <=270:
  209. ang = rang - 180
  210. angle = math.radians(ang)
  211. cosA = math.cos(angle)
  212. sinA = math.sin(angle)
  213. x0 = dis * cosA
  214. y0 = dis * sinA
  215. x0n =ox + x0
  216. y0n = oy + y0
  217. else:
  218. ang = 360 - rang
  219. angle = math.radians(ang)
  220. cosA = math.cos(angle)
  221. sinA = math.sin(angle)
  222. x0 = dis * cosA
  223. y0 = dis * sinA
  224. x0n = ox - x0
  225. y0n = oy + y0
  226. else:
  227. if zf < 0:
  228. if rang <= 90:
  229. angle = math.radians(rang)
  230. cosA = math.cos(angle)
  231. sinA = math.sin(angle)
  232. x0 = dis * cosA
  233. y0 = dis * sinA
  234. x0n = ox +x0
  235. y0n = oy +y0
  236. elif rang > 90 and rang <= 180:
  237. ang = 180 - rang
  238. angle = math.radians(ang)
  239. cosA = math.cos(angle)
  240. sinA = math.sin(angle)
  241. x0 = dis * cosA
  242. y0 = dis * sinA
  243. x0n = ox-x0
  244. y0n = oy+y0
  245. elif rang > 180 and rang <=270:
  246. ang = rang - 180
  247. angle = math.radians(ang)
  248. cosA = math.cos(angle)
  249. sinA = math.sin(angle)
  250. x0 = dis * cosA
  251. y0 = dis * sinA
  252. x0n =ox-x0
  253. y0n = oy-y0
  254. else:
  255. ang = 360 - rang
  256. angle = math.radians(ang)
  257. cosA = math.cos(angle)
  258. sinA = math.sin(angle)
  259. x0 = dis * cosA
  260. y0 = dis * sinA
  261. x0n = ox + x0
  262. y0n = oy-y0
  263. else:
  264. if rang <= 90:
  265. angle = math.radians(rang)
  266. cosA = math.cos(angle)
  267. sinA = math.sin(angle)
  268. x0 = dis * cosA
  269. y0 = dis * sinA
  270. x0n = ox - x0
  271. y0n = oy -y0
  272. elif rang > 90 and rang <= 180:
  273. ang = 180 - rang
  274. angle = math.radians(ang)
  275. cosA = math.cos(angle)
  276. sinA = math.sin(angle)
  277. x0 = dis * cosA
  278. y0 = dis * sinA
  279. x0n = ox + x0
  280. y0n = oy - y0
  281. elif rang > 180 and rang <=270:
  282. ang = rang - 180
  283. angle = math.radians(ang)
  284. cosA = math.cos(angle)
  285. sinA = math.sin(angle)
  286. x0 = dis * cosA
  287. y0 = dis * sinA
  288. x0n =ox + x0
  289. y0n = oy + y0
  290. else:
  291. ang = 360 - rang
  292. angle = math.radians(ang)
  293. cosA = math.cos(angle)
  294. sinA = math.sin(angle)
  295. x0 = dis * cosA
  296. y0 = dis * sinA
  297. x0n = ox - x0
  298. y0n = oy + y0
  299. return [x0n,y0n]
  300. def rotatecordiateY(rang,xpx,xpy,xP,yP,zf):
  301. rx = float(xpx)
  302. ry = float(xpy)
  303. ox = float(xP)
  304. oy = float(yP)
  305. bb = 1
  306. dis = math.sqrt((rx - ox)*(rx-ox) + (ry - oy)*(ry-oy))
  307. if bb == 0:
  308. if zf > 0:
  309. if rang <= 90:
  310. angle = math.radians(rang)
  311. cosA = math.cos(angle)
  312. sinA = math.sin(angle)
  313. x0 = dis * sinA
  314. y0 = dis * cosA
  315. x0n1 = ox+x0
  316. y0n1 = oy-y0
  317. elif rang > 90 and rang <= 180:
  318. ang = 180 - rang
  319. angle = math.radians(ang)
  320. cosA = math.cos(angle)
  321. sinA = math.sin(angle)
  322. x0 = dis * sinA
  323. y0 = dis * cosA
  324. x0n1 = ox+x0
  325. y0n1 = oy+y0
  326. elif rang > 180 and rang <=270:
  327. ang = rang - 180
  328. angle = math.radians(ang)
  329. cosA = math.cos(angle)
  330. sinA = math.sin(angle)
  331. x0 = dis * sinA
  332. y0 = dis * cosA
  333. x0n1 = ox-x0
  334. y0n1 = oy+y0
  335. else:
  336. ang = 360 - rang
  337. angle = math.radians(ang)
  338. cosA = math.cos(angle)
  339. sinA = math.sin(angle)
  340. x0 = dis * sinA
  341. y0 = dis * cosA
  342. x0n1 = ox-x0
  343. y0n1 = oy-y0
  344. else:
  345. if rang <= 90:
  346. angle = math.radians(rang)
  347. cosA = math.cos(angle)
  348. sinA = math.sin(angle)
  349. x0 = dis * sinA
  350. y0 = dis * cosA
  351. x0n1 = ox-x0
  352. y0n1 = oy+y0
  353. elif rang > 90 and rang <= 180:
  354. ang = 180 - rang
  355. angle = math.radians(ang)
  356. cosA = math.cos(angle)
  357. sinA = math.sin(angle)
  358. x0 = dis * sinA
  359. y0 = dis * cosA
  360. x0n1 = ox-x0
  361. y0n1 = oy-y0
  362. elif rang > 180 and rang <=270:
  363. ang = rang - 180
  364. angle = math.radians(ang)
  365. cosA = math.cos(angle)
  366. sinA = math.sin(angle)
  367. x0 = dis * sinA
  368. y0 = dis * cosA
  369. x0n1 = ox+x0
  370. y0n1 = oy-y0
  371. else:
  372. ang = 360 - rang
  373. angle = math.radians(ang)
  374. cosA = math.cos(angle)
  375. sinA = math.sin(angle)
  376. x0 = dis * sinA
  377. y0 = dis * cosA
  378. x0n1 = ox+x0
  379. y0n1 = oy+y0
  380. else:
  381. if zf < 0:
  382. if rang <= 90:
  383. angle = math.radians(rang)
  384. cosA = math.cos(angle)
  385. sinA = math.sin(angle)
  386. x0 = dis * sinA
  387. y0 = dis * cosA
  388. x0n1 = ox+x0
  389. y0n1 = oy-y0
  390. elif rang > 90 and rang <= 180:
  391. ang = 180 - rang
  392. angle = math.radians(ang)
  393. cosA = math.cos(angle)
  394. sinA = math.sin(angle)
  395. x0 = dis * sinA
  396. y0 = dis * cosA
  397. x0n1 = ox+x0
  398. y0n1 = oy+y0
  399. elif rang > 180 and rang <=270:
  400. ang = rang - 180
  401. angle = math.radians(ang)
  402. cosA = math.cos(angle)
  403. sinA = math.sin(angle)
  404. x0 = dis * sinA
  405. y0 = dis * cosA
  406. x0n1 = ox-x0
  407. y0n1 = oy+y0
  408. else:
  409. ang = 360 - rang
  410. angle = math.radians(ang)
  411. cosA = math.cos(angle)
  412. sinA = math.sin(angle)
  413. x0 = dis * sinA
  414. y0 = dis * cosA
  415. x0n1 = ox-x0
  416. y0n1 = oy-y0
  417. else:
  418. if rang <= 90:
  419. angle = math.radians(rang)
  420. cosA = math.cos(angle)
  421. sinA = math.sin(angle)
  422. x0 = dis * sinA
  423. y0 = dis * cosA
  424. x0n1 = ox-x0
  425. y0n1 = oy+y0
  426. elif rang > 90 and rang <= 180:
  427. ang = 180 - rang
  428. angle = math.radians(ang)
  429. cosA = math.cos(angle)
  430. sinA = math.sin(angle)
  431. x0 = dis * sinA
  432. y0 = dis * cosA
  433. x0n1 = ox-x0
  434. y0n1 = oy-y0
  435. elif rang > 180 and rang <=270:
  436. ang = rang - 180
  437. angle = math.radians(ang)
  438. cosA = math.cos(angle)
  439. sinA = math.sin(angle)
  440. x0 = dis * sinA
  441. y0 = dis * cosA
  442. x0n1 = ox+x0
  443. y0n1 = oy-y0
  444. else:
  445. ang = 360 - rang
  446. angle = math.radians(ang)
  447. cosA = math.cos(angle)
  448. sinA = math.sin(angle)
  449. x0 = dis * sinA
  450. y0 = dis * cosA
  451. x0n1 = ox+x0
  452. y0n1 = oy+y0
  453. return [x0n1,y0n1]
  454. def readangle(pname):
  455. nameA = pname.split('-',-1)[-1]
  456. #作个键值对
  457. dict = {'BD':101, 'BDZ':101, 'BDY':101,'KHP':191, 'THP':191, 'BPR':11,'RFH':11,'BPL':210,'DQ':101}
  458. ang1 = dict[nameA]
  459. if nameA == 'THP' or nameA == 'BPR':
  460. ang2 = 360 - ang1
  461. elif nameA == 'KHP':
  462. ang2 = 90 - ang1
  463. else:
  464. ang2 = 270 - ang1
  465. return ang2
  466. def readtxt(listp):
  467. #输出和两个转换坐标文件
  468. txtpath = listp[0]
  469. prjpath = listp[1]
  470. prjpath1 = listp[2]
  471. outpath = listp[3]
  472. #创建需要用的
  473. gdbpath = outpath + '\\bd.mdb'
  474. gdbpath1 = outpath + '\\result.mdb'
  475. mdbpath = gdbpath1 + '\\BDp'
  476. foutpath = gdbpath + '\\BDp'
  477. try:
  478. arcpy.CreatePersonalGDB_management (outpath, 'bd.mdb')
  479. except:
  480. arcpy.Delete_management(gdbpath)
  481. arcpy.CreatePersonalGDB_management (outpath, 'bd.mdb')
  482. try:
  483. arcpy.CreatePersonalGDB_management (outpath, 'result.mdb')
  484. except:
  485. arcpy.Delete_management(gdbpath1)
  486. arcpy.CreatePersonalGDB_management (outpath, 'result.mdb')
  487. try:
  488. arcpy.CreateFeatureclass_management(gdbpath,'BDp', 'POINT')
  489. except:
  490. arcpy.Delete_management(foutpath)
  491. arcpy.CreateFeatureclass_management(gdbpath,'BDp', 'POINT')
  492. arcpy.MakeFeatureLayer_management(foutpath, 'bd')
  493. #cgcs2000的坐标系文件(务必放入输出文件夹)
  494. arcpy.DefineProjection_management('bd', prjpath)
  495. arcpy.AddField_management('bd','pname','TEXT')
  496. arcpy.AddField_management('bd','pxyp','TEXT')
  497. arcpy.AddField_management('bd','elevation','FLOAT')
  498. arcpy.AddField_management('bd','dis','FLOAT')
  499. with arcpy.da.InsertCursor('bd',['SHAPE@X','SHAPE@Y','elevation','pname','pxyp','dis']) as cursorZ:
  500. with open(txtpath,'r') as filesA:
  501. for ppstr1 in filesA:
  502. str1 = ppstr1.split(',',-1)[0]
  503. str2 = ppstr1.split(',',-1)[1]
  504. str3 = float(ppstr1.split(',',-1)[2])
  505. str4 = float(ppstr1.split(',',-1)[3])
  506. str5 = float(ppstr1.split(',',-1)[4])
  507. str61 = ppstr1.split(',',-1)[5]
  508. str62 = str61.replace('\n','')
  509. str6 = float(str62)
  510. listp1 = []
  511. listp1.append(str3)
  512. listp1.append(str4)
  513. listp1.append(str5)
  514. listp1.append(str1)
  515. listp1.append(str2)
  516. listp1.append(str6)
  517. cursorZ.insertRow(listp1)
  518. # print('3')
  519. listp2 = []
  520. listp2.append(foutpath)
  521. listp2.append(mdbpath)
  522. listp2.append(prjpath1)
  523. return listp2
  524. def transzb(listp):
  525. #原始点,转换点,转换文件
  526. shppath = listp[0]
  527. mdbpath = listp[1]
  528. prjpath = listp[2]
  529. try:
  530. arcpy.Project_management(shppath, mdbpath, prjpath)
  531. except:
  532. #检查空几何
  533. arcpy.MakeFeatureLayer_management(shppath, 'SHP2')
  534. with arcpy.da.UpdateCursor('SHP2',['SHAPE@']) as cursorD:
  535. for curD in cursorD:
  536. shp1 = curD[0]
  537. if shp1 == None:
  538. cursorD.deleteRow()
  539. arcpy.Project_management(shppath, mdbpath, prjpath)
  540. # print('4')
  541. return mdbpath
  542. def rejson(inpath,outpath):
  543. #这里的点就是位移两个点
  544. foutpath = outpath + '\\Result.json'
  545. arcpy.MakeFeatureLayer_management(inpath, 'bdlayer')
  546. #根据属性归类
  547. mm = 0
  548. pxstr = ''
  549. pystr = ''
  550. ppstr = ''
  551. pxstr1 = ''
  552. pystr1 = ''
  553. ppstr1 = ''
  554. pname = ''
  555. lx = ''
  556. ly = ''
  557. lp = ''
  558. lx1 = ''
  559. ly1 = ''
  560. lp1 = ''
  561. nameA = ''
  562. resultp = []
  563. with arcpy.da.SearchCursor('bdlayer',['SHAPE@X','SHAPE@Y','elevation','pname','pxyp','dis']) as cursorZ:
  564. for curZ in cursorZ:
  565. if mm == 0:
  566. #px
  567. pname = curZ[3]
  568. nameA = pname.split('-',-1)[-1]
  569. if nameA =='BPR' or nameA == 'THP':
  570. pystr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  571. ly = str(round(curZ[5],1))
  572. # pxstr = str(round(curZ[0],2)) + " ," + str(round(curZ[1],2)) + " ," + str(round(curZ[2]))
  573. # lx = str(round(curZ[5],2))
  574. else:
  575. pxstr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  576. lx = str(round(curZ[5],1))
  577. mm = mm + 1
  578. elif mm == 1 and curZ[3] == pname:
  579. if nameA =='BPR' or nameA == 'THP':
  580. pxstr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  581. lx = str(round(curZ[5],1))
  582. else:
  583. #py
  584. pystr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  585. ly = str(round(curZ[5],1))
  586. mm = mm + 1
  587. elif mm == 2 and curZ[3] == pname:
  588. #pp
  589. ppstr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  590. lp = str(round(curZ[5],1))
  591. mm = mm + 1
  592. elif mm == 3 and curZ[3] == pname:
  593. if nameA =='BPR' or nameA == 'THP':
  594. pystr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  595. ly1 = str(round(curZ[5],1))
  596. else:
  597. pxstr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  598. lx1 = str(round(curZ[5],1))
  599. mm = mm + 1
  600. elif mm == 4 and curZ[3] == pname:
  601. if nameA =='BPR' or nameA == 'THP':
  602. pxstr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  603. lx1 = str(round(curZ[5],1))
  604. else:
  605. pystr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  606. ly1 = str(round(curZ[5],1))
  607. mm = mm + 1
  608. elif mm == 5 and curZ[3] == pname:
  609. ppstr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
  610. lp1 = str(round(curZ[5],1))
  611. #此时加入item
  612. item = {
  613. "name": pname,
  614. "px": pxstr,
  615. "lx": lx,
  616. "py": pystr,
  617. "ly": ly,
  618. "pp": ppstr,
  619. "lp": lp,
  620. "px1": pxstr1,
  621. "lx1": lx1,
  622. "py1": pystr1,
  623. "ly1": ly1,
  624. "pp1": ppstr1,
  625. "lp1": lp1
  626. }
  627. resultp.append(item)
  628. mm = 0
  629. # print('5')
  630. with open(foutpath, 'w') as dump_f:
  631. json.dump(resultp,dump_f)
  632. def linew(bppath,inpath,outpath,ranA,ranB):
  633. # ang1 = 270 - float(angle1)
  634. ran = float(ranA)
  635. ran1 = float(ranB)
  636. #存储位移array
  637. txtarr = []
  638. #获取位移量文件名字
  639. txtfilename = inpath.split('\\',-1)[-1]
  640. txtfile = txtfilename.split('.',-1)[0]
  641. #读的是位移量文件
  642. with open(inpath,'r+') as fileA:
  643. for lineA in fileA:
  644. #直接读
  645. if lineA == '\n':
  646. continue
  647. elif 'end' in lineA:
  648. fulloutpath = outpath + '\\Resulttxt.txt'
  649. #进入第二步
  650. # print('1')
  651. #这里把所有的都理出来了
  652. resultp = drawline(bppath,txtarr,ran,fulloutpath,outpath,ran1)
  653. #这里读取
  654. list2 = readtxt(resultp)
  655. #坐标转换
  656. mdbpath = transzb(list2)
  657. #再输出为json
  658. rejson(mdbpath,outpath)
  659. # print('finish')
  660. break
  661. else:
  662. txtarr.append(lineA)
  663. if __name__ == '__main__':
  664. # 第一个是基准点,第二个是位移量,第三个是输出文件夹,夸张系数
  665. linew(r"D:\4work_now\20240226TZL\BP2024_cgcs2000.txt",r"D:\4work_now\20240226TZL\TZL2023.txt",r"D:\4work_now\20240226TZL\result",2,2)