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

drawDMlineCOM1022_pan.py 8.5KB

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