工具箱相关
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

drawDMlineCOM1022_pan_1.py 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. # -*- coding: utf-8 -*-
  2. import arcpy
  3. import math
  4. def drawDM(shppath,outpath,jj0,bj0):
  5. jj = float(jj0)
  6. bj = float(bj0)
  7. szd = 'Sp'
  8. sx = 'SX'
  9. sw = 'S_Weizhi'
  10. arcpy.MakeFeatureLayer_management(shppath, 'DMshp')
  11. shppath1 = outpath + '\\DMpoint.shp'
  12. try:
  13. arcpy.CreateFeatureclass_management(outpath, 'DMpoint.shp', 'POINT')
  14. except:
  15. arcpy.Delete_management(shppath1)
  16. arcpy.CreateFeatureclass_management(outpath, 'DMpoint.shp', 'POINT')
  17. arcpy.MakeFeatureLayer_management(shppath1, 'DMP')
  18. shppath2 = outpath + '\\DMpolyline.shp'
  19. try:
  20. arcpy.CreateFeatureclass_management(outpath, 'DMpolyline.shp', 'POLYLINE')
  21. except:
  22. arcpy.Delete_management(shppath2)
  23. arcpy.CreateFeatureclass_management(outpath, 'DMpolyline.shp', 'POLYLINE')
  24. arcpy.MakeFeatureLayer_management(shppath2, 'DML')
  25. arcpy.AddField_management('DMP','ZH','TEXT')
  26. arcpy.AddField_management('DML','ZH','TEXT')
  27. with arcpy.da.InsertCursor('DMP', ['SHAPE@','ZH']) as cursorA:
  28. with arcpy.da.InsertCursor('DML', ['SHAPE@','ZH']) as cursorB:
  29. with arcpy.da.SearchCursor('DMshp',['SHAPE@',szd,sw,sx,'length']) as cursorC:
  30. for curC in cursorC:
  31. dm = curC[0]
  32. zf = curC[3]
  33. pts = dm.getPart(0)
  34. if zf == 1:
  35. sk = int(curC[1]) // 1000
  36. sj = int(curC[1]) % 1000
  37. len = curC[2]
  38. dmgeopt = dm.positionAlongLine(len)
  39. dmpt = dmgeopt.firstPoint
  40. zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
  41. minp = findminp(dm,pts,len)
  42. try:
  43. pl = jsdp(dmpt,minp,bj)
  44. list1 = []
  45. list1.append(dmgeopt)
  46. list1.append(zh)
  47. cursorA.insertRow(list1)
  48. list2 = []
  49. list2.append(pl)
  50. list2.append(zh)
  51. cursorB.insertRow(list2)
  52. except:
  53. pass
  54. len = len + 50
  55. while len <= curC[4]:
  56. ptg1 = dm.positionAlongLine(len)
  57. pt1 = ptg1.firstPoint
  58. minp = findminp(dm,pts,len)
  59. sj = sj + 50
  60. if sj == 1000:
  61. sk = sk + 1
  62. sj = 0
  63. zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
  64. try:
  65. pl = jsdp(pt1,minp,bj)
  66. listp1 = []
  67. listp1.append(ptg1)
  68. listp1.append(zh)
  69. cursorA.insertRow(listp1)
  70. listl1 = []
  71. listl1.append(pl)
  72. listl1.append(zh)
  73. cursorB.insertRow(listl1)
  74. except:
  75. pass
  76. len = len + 50
  77. print('B2')
  78. mk = int(curC[2]) // 1000
  79. mj = int(curC[2]) % 1000
  80. zh1 = 'K' + str(mk) + '+' + str(str(mj).zfill(3))
  81. if zh1 == zh:
  82. pass
  83. else:
  84. qd = dm.lastPoint
  85. lens = curC[5] - (len - 50)
  86. sj = sj + int(lens)
  87. zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
  88. try:
  89. plZ = jsdp(qd,pts[pts.count - 2],bj)
  90. listp1 = []
  91. listp1.append(arcpy.PointGeometry(qd))
  92. listp1.append(zh)
  93. cursorA.insertRow(listp1)
  94. listl1 = []
  95. listl1.append(plZ)
  96. listl1.append(zh)
  97. cursorB.insertRow(listl1)
  98. except:
  99. pass
  100. print('B')
  101. else:
  102. sk = int(curC[1]) // 1000
  103. sj = int(curC[1]) % 1000
  104. len = curC[4] - curC[2]
  105. dmgeopt = dm.positionAlongLine(len)
  106. dmpt = dmgeopt.firstPoint
  107. zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
  108. minp = findminp(dm,pts,len)
  109. try:
  110. pl = jsdp(dmpt,minp,bj)
  111. list1 = []
  112. list1.append(dmgeopt)
  113. list1.append(zh)
  114. cursorA.insertRow(list1)
  115. list2 = []
  116. list2.append(pl)
  117. list2.append(zh)
  118. cursorB.insertRow(list2)
  119. except:
  120. pass
  121. len = len - 50
  122. while len >= 0:
  123. ptg1 = dm.positionAlongLine(len)
  124. pt1 = ptg1.firstPoint
  125. minp = findminp(dm,pts,len)
  126. sj = sj + 50
  127. if sj == 1000:
  128. sk = sk + 1
  129. sj = 0
  130. zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
  131. try:
  132. pl = jsdp(pt1,minp,bj)
  133. listp1 = []
  134. listp1.append(ptg1)
  135. listp1.append(zh)
  136. cursorA.insertRow(listp1)
  137. listl1 = []
  138. listl1.append(pl)
  139. listl1.append(zh)
  140. cursorB.insertRow(listl1)
  141. except:
  142. pass
  143. len = len - 50
  144. print('C2')
  145. mk = int(curC[2]) // 1000
  146. mj = int(curC[2]) % 1000
  147. zh1 = 'K' + str(mk) + '+' + str(str(mj).zfill(3))
  148. if zh1 == zh:
  149. pass
  150. else:
  151. qd = dm.firstPoint
  152. lens = len + 50
  153. sj = sj + int(lens)
  154. zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
  155. try:
  156. plZ = jsdp(qd, pts[1], bj)
  157. listp1 = []
  158. listp1.append(arcpy.PointGeometry(qd))
  159. listp1.append(zh)
  160. cursorA.insertRow(listp1)
  161. listl1 = []
  162. listl1.append(plZ)
  163. listl1.append(zh)
  164. cursorB.insertRow(listl1)
  165. except:
  166. pass
  167. print('C')
  168. def findminp(dm,pts,len):
  169. mm = 1
  170. disM = 9999
  171. minp = pts[0]
  172. while mm < (pts.count - 1):
  173. dis2 = dm.measureOnLine(pts[mm])
  174. dis = abs(dis2 - len)
  175. if dis == 0:
  176. minp = pts[mm - 1]
  177. break
  178. if dis < disM:
  179. disM = dis
  180. minp = pts[mm]
  181. mm = mm + 1
  182. return minp
  183. def jsdp(pt1,pt2,bj):
  184. qdx = pt1.X
  185. qdy = pt1.Y
  186. qdx1 = pt2.X
  187. qdy1 = pt2.Y
  188. qdk = (qdx1 - qdx) / (qdy1-qdy) * (-1)
  189. num0 = qdk * qdx
  190. qdb = qdy - num0
  191. numA = (qdk * qdk) + 1
  192. num1 = qdb - qdy
  193. num2 = 2 * qdk * num1
  194. num3 = 2 * qdx
  195. numB = num2 - num3
  196. num4 = num1 * num1
  197. num5 = qdx * qdx
  198. num51 = bj * bj
  199. numC = num4 + num5 - num51
  200. num6 = numB * numB
  201. num7 = 4 * numA * numC
  202. num8 = math.sqrt(num6 - num7)
  203. num9 = (-1) * numB
  204. num101 = num9 + num8
  205. num102 = num9 - num8
  206. num11 = 2 * numA
  207. numX1 = num101 / num11
  208. numX2 = num102 / num11
  209. numY1 = qdk * numX1 + qdb
  210. numY2 = qdk * numX2 + qdb
  211. pt1 = arcpy.Point(numX1, numY1)
  212. pt2 = arcpy.Point(numX2, numY2)
  213. arr1 = arcpy.Array()
  214. arr1.append(pt1)
  215. arr1.append(pt2)
  216. pl1 = arcpy.Polyline(arr1)
  217. return pl1
  218. if __name__ == '__main__':
  219. try:
  220. drawDM(r"D:\4work_now\20241017dm\1024gq\MYQ\1\myqzxx.shp",r'D:\4work_now\20241017dm\1024gq\MYQ\1',50,30)
  221. except arcpy.ExecuteError:
  222. arcpy.AddMessage (arcpy.GetMessages())