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

dmname_onZH.py 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import arcpy
  2. import math
  3. def fillzh(str1):
  4. if len(str1) == 1:
  5. str2 = '00' + str1
  6. elif len(str1) == 2:
  7. str2 = '0' + str1
  8. elif len(str1) == 4:
  9. str2 = '000'
  10. else:
  11. str2 = str1
  12. return str2
  13. def dmname():
  14. dmxpath = r'D:\4work_now\20241017dm\20241129\dzgq1\dmx.shp'
  15. dmdpath = r'D:\4work_now\20241017dm\20241129\dzgq1\dmd.shp'
  16. gqpath = r'D:\4work_now\20241017dm\20241129\dzgq1\zxx.shp'
  17. arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
  18. arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
  19. arcpy.MakeFeatureLayer_management(gqpath, 'GQshp')
  20. arcpy.AddField_management('DMshp', 'ZH', 'TEXT')
  21. arcpy.AddField_management('DMshp','KZ','LONG')
  22. arcpy.AddField_management('DMshp','JZ','LONG')
  23. with arcpy.da.SearchCursor('GQshp',['SHAPE@']) as cursorZ:
  24. for curZ in cursorZ:
  25. GQline = curZ[0]
  26. length = GQline.length
  27. # mm = 0
  28. # nn = 0
  29. with arcpy.da.UpdateCursor('DMshp',['SHAPE@','ZH','KZ','JZ']) as cursorA:
  30. for curA in cursorA:
  31. line1 = curA[0]
  32. buf1 = line1.buffer(1)
  33. arcpy.SelectLayerByLocation_management('DMDshp', 'WITHIN', buf1)
  34. pc = int(arcpy.GetCount_management('DMDshp')[0])
  35. if pc == 0:
  36. pass
  37. else:
  38. minnum = 9999
  39. with arcpy.da.SearchCursor('DMDshp', ['SHAPE@']) as cursorAA:
  40. for curAA in cursorAA:
  41. tuple1 = GQline.queryPointAndDistance(curAA[0])
  42. lj = tuple1[2]
  43. if lj < minnum:
  44. minnum = lj
  45. pt = curAA[0]
  46. len1 =GQline.measureOnLine(pt)
  47. kz = int(len1 // 1000)
  48. jz = int(len1 % 1000)
  49. if jz % 10 <5:
  50. num1 = jz % 10
  51. jz = jz - num1
  52. else:
  53. num1 = jz % 10
  54. num2 = 10 - num1
  55. jz = jz + num2
  56. str2 = fillzh(str(jz))
  57. if jz == 1000:
  58. kz = kz+1
  59. str1 = 'K' + str(kz) + '+' + str2 + ' '
  60. jz = 0
  61. else:
  62. str1 = 'K' + str(kz) + '+' + str2 + ' '
  63. curA[1] = str1
  64. curA[2] = kz
  65. curA[3] = jz
  66. cursorA.updateRow(curA)
  67. print(str1)
  68. # if curA[1] == '':
  69. # line1 = curA[0]
  70. # if nn < 1000:
  71. # str1 = fillzh(str(nn))
  72. # zh1 = 'K' + str(mm) + '+' + str1
  73. # curA[2] = mm
  74. # curA[3] = nn
  75. # curA[1] = zh1
  76. # cursorA.updateRow(curA)
  77. # nn = nn + 50
  78. # else:
  79. # nn = 0
  80. # mm = mm + 1
  81. # str1 = fillzh(str(nn))
  82. # zh1 = 'K' + str(mm) + '+' + str1
  83. # curA[2] = mm
  84. # curA[3] = nn
  85. # curA[1] = zh1
  86. # cursorA.updateRow(curA)
  87. # nn = nn + 50
  88. # arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
  89. # pc = int(arcpy.GetCount_management('DMDshp')[0])
  90. # if pc == 0:
  91. # pass
  92. # else:
  93. # with arcpy.da.SearchCursor('DMDshp',['SHAPE@','height']) as cursorAA:
  94. # for curAA in cursorAA:
  95. # len1 = GQline.measureOnLine(curAA[0])
  96. # len2 = round(length - len1)
  97. # kz = int(len2 // 1000)
  98. # jz = int(len2 % 1000)
  99. # if jz % 10 != 0:
  100. # jz = jz + 1
  101. # gc = round(curAA[1],1)
  102. # str2 = fillzh(str(jz))
  103. # str1 = 'K' + str(kz) + '+' + str2 + ' '
  104. # curA[1] = str1
  105. # cursorA.updateRow(curA)
  106. # print('1')
  107. # arcpy.SelectLayerByLocation_management('DMDshp', 'WITHIN', buf1)
  108. # pc2 = int(arcpy.GetCount_management('DMDshp')[0])
  109. # if pc2 > 0:
  110. # with arcpy.da.UpdateCursor('DMDshp', ['SHAPE@', 'ZH', 'LJ', 'SFR', 'SFL']) as cursorB:
  111. # for curB in cursorB:
  112. # tuple1 = GQline.queryPointAndDistance(curB[0])
  113. # lj = round(tuple1[2], 4)
  114. # if tuple1[3] == False:
  115. # curB[3] = -1
  116. # else:
  117. # curB[3] = 1
  118. # pt = curB[0]
  119. # buf2 = pt.buffer(1)
  120. # arcpy.SelectLayerByLocation_management('roadshp', 'INTERSECT', buf2)
  121. # pc3 = int(arcpy.GetCount_management('roadshp')[0])
  122. # # arcpy.SelectLayerByLocation_management('roadshp', 'CONTAINS', buf2)
  123. # # pc4 = int(arcpy.GetCount_management('roadshp')[0])
  124. # if pc3 > 0:
  125. # curB[4] = 1
  126. # curB[1] = zh
  127. # curB[2] = lj
  128. # cursorB.updateRow(curB)
  129. if __name__ == '__main__':
  130. try:
  131. dmname()
  132. except arcpy.ExecuteError:
  133. arcpy.AddMessage (arcpy.GetMessages())