工具箱相关
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DMzl20241023.py 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import arcpy
  2. import math
  3. def pp():
  4. dmxpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dmx.shp'
  5. dmdpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dmd.shp'
  6. # zdpath = r'D:\4work_now\20241017dm\1024gq\RMQ7\rmq200zdmd.shp'
  7. dwgpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dm.dwg'
  8. gqpath = r'D:\4work_now\20241017dm\20241129\hltdm3\zxx.shp'
  9. roadpath = r'D:\4work_now\20241017dm\20241129\hltdm3\road.shp'
  10. arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
  11. arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
  12. # arcpy.MakeFeatureLayer_management(zdpath, 'ZDshp')
  13. arcpy.MakeFeatureLayer_management(gqpath, 'GQshp')
  14. arcpy.MakeFeatureLayer_management(roadpath, 'roadshp')
  15. annopath = dwgpath + '\\Annotation'
  16. arcpy.MakeFeatureLayer_management(annopath, 'ANNO')
  17. arcpy.AddField_management('DMshp','KZ','LONG')
  18. arcpy.AddField_management('DMshp','JZ','LONG')
  19. arcpy.AddField_management('DMshp','ZH','TEXT')
  20. # arcpy.AddField_management('DMshp', 'ZH_1', 'TEXT')
  21. arcpy.AddField_management('DMDshp','ZH','TEXT')
  22. arcpy.AddField_management('DMDshp','LJ','FLOAT')
  23. arcpy.AddField_management('DMDshp','SFR','LONG')
  24. arcpy.AddField_management('DMDshp', 'SFL', 'LONG')
  25. nonehz = -1
  26. with arcpy.da.SearchCursor('GQshp',['SHAPE@']) as cursorZ:
  27. for curZ in cursorZ:
  28. GQline = curZ[0]
  29. # with arcpy.da.UpdateCursor('DMshp',['SHAPE@','KZ','JZ','ZH']) as cursorA:
  30. # for curA in cursorA:
  31. # zh = ''
  32. # line1 = curA[0]
  33. # buf1 = line1.buffer(10)
  34. # arcpy.SelectLayerByLocation_management('ANNO','WITHIN',buf1)
  35. # pc = int(arcpy.GetCount_management('ANNO')[0])
  36. # if pc == 0:
  37. # curA[1] = nonehz
  38. # curA[2] = nonehz
  39. # curA[3] = 'None' + str(nonehz)
  40. # cursorA.updateRow(curA)
  41. # elif pc == 1:
  42. # with arcpy.da.SearchCursor('ANNO',['SHAPE@','Text']) as cursorAA:
  43. # for curAA in cursorAA:
  44. # zh = curAA[1]
  45. # try:
  46. # kstr = zh.split('+',-1)[0]
  47. # kz = kstr.replace('K','')
  48. # jstr = zh.split('+',-1)[1]
  49. # try:
  50. # jz = jstr.split(' ',-1)[0]
  51. # except:
  52. # jz = jstr
  53. # curA[1] = int(kz)
  54. # curA[2] = int(float(jz))
  55. # zh = 'K' + str(int(kz)) + '+' +str(str(int(float(jz))).zfill(3))
  56. # curA[3] = zh
  57. # cursorA.updateRow(curA)
  58. # except:
  59. # print(zh)
  60. # else:
  61. # dis1 = 99999
  62. # zh = ''
  63. # with arcpy.da.SearchCursor('ANNO',['SHAPE@','Text']) as cursorAA:
  64. # for curAA in cursorAA:
  65. # if 'K' in curAA[1]:
  66. # annopt = curAA[0]
  67. # dis2 = line1.distanceTo (annopt)
  68. # if dis2 < dis1:
  69. # dis1 = dis2
  70. # zh = curAA[1]
  71. # else:
  72. # pass
  73. # try:
  74. # kstr = zh.split('+',-1)[0]
  75. # kz = kstr.replace('K','')
  76. # jstr = zh.split('+', -1)[1]
  77. # try:
  78. # jz = jstr.split(' ', -1)[0]
  79. # except:
  80. # jz = jstr
  81. # curA[1] = int(kz)
  82. # curA[2] = int(float(jz))
  83. # zh1 = 'K' + str(int(kz)) + '+' + str(str(int(float(jz))).zfill(3))
  84. # curA[3] = zh1
  85. # cursorA.updateRow(curA)
  86. # except:
  87. # pass
  88. # print('A')
  89. with arcpy.da.SearchCursor('DMshp', ['SHAPE@', 'KZ', 'JZ', 'ZH']) as cursorA:
  90. for curA in cursorA:
  91. line1 = curA[0]
  92. # len = line1.length / 2
  93. # cpt = line1.positionAlongLine (len)
  94. buf1 = line1.buffer(1)
  95. zh = curA[3]
  96. arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
  97. pc2 = int(arcpy.GetCount_management('DMDshp')[0])
  98. if pc2 > 0:
  99. min = 999
  100. with arcpy.da.SearchCursor('DMDshp',['SHAPE@']) as cursorZ:
  101. for curZ in cursorZ:
  102. pt = curZ[0].firstPoint
  103. lj = round(GQline.distanceTo(pt), 4)
  104. if lj < min:
  105. min = lj
  106. cpt = curZ[0]
  107. with arcpy.da.UpdateCursor('DMDshp',['SHAPE@','ZH','LJ','SFR','SFL']) as cursorB:
  108. for curB in cursorB:
  109. tuple1 = GQline.queryPointAndDistance(curB[0])
  110. lj = round(cpt.distanceTo(curB[0]),4)
  111. if tuple1[3] == False:
  112. curB[3] = -1
  113. else:
  114. curB[3] = 1
  115. pt = curB[0]
  116. buf2 = pt.buffer(1)
  117. arcpy.SelectLayerByLocation_management('roadshp', 'INTERSECT', buf2)
  118. pc3 = int(arcpy.GetCount_management('roadshp')[0])
  119. # arcpy.SelectLayerByLocation_management('roadshp', 'CONTAINS', buf2)
  120. # pc4 = int(arcpy.GetCount_management('roadshp')[0])
  121. if pc3 > 0 :
  122. curB[4] = 1
  123. curB[1] = zh
  124. curB[2] = lj
  125. cursorB.updateRow(curB)
  126. print('1')
  127. if __name__ == '__main__':
  128. try:
  129. # arcpy.AddMessage ('start at {0}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())))
  130. pp()
  131. # Lake(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1),arcpy.GetParameterAsText(2),arcpy.GetParameterAsText(3),arcpy.GetParameterAsText(4))
  132. # arcpy.AddMessage ('end at {0}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())))
  133. except arcpy.ExecuteError:
  134. arcpy.AddMessage (arcpy.GetMessages())