工具箱相关
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

dmname_onZH_rename.py 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. else:
  9. str2 = str1
  10. return str2
  11. def dmname():
  12. dmxpath = r'D:\4work_now\20241017dm\1028gq\RMQ7\rmqdmx.shp'
  13. # dmdpath = r'D:\4work_now\20241017dm\1028gq\PYH\PYH2\pyhzdmd.shp'
  14. gqpath = r'D:\4work_now\20241017dm\1028gq\RMQ7\rmqzxx.shp'
  15. arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
  16. # arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
  17. arcpy.MakeFeatureLayer_management(gqpath, 'GQshp')
  18. arcpy.AddField_management('DMshp', 'ZH', 'TEXT')
  19. mm = 0
  20. nn = 0
  21. ii = 0
  22. with arcpy.da.SearchCursor('GQshp',['SHAPE@']) as cursorZ:
  23. for curZ in cursorZ:
  24. GQline = curZ[0]
  25. length = GQline.length
  26. with arcpy.da.SearchCursor('DMshp', ['SHAPE@', 'KZ', 'JZ', 'ZH']) as cursorA:
  27. for curA in cursorA:
  28. line1 = curA[0]
  29. # while ii <= GQline.length:
  30. # pt1 = GQline.positionAlongLine (ii)
  31. # buf1 = pt1.buffer(1)
  32. # arcpy.SelectLayerByLocation_management('DMshp', 'INTERSECT', buf1)
  33. # pc = int(arcpy.GetCount_management('DMshp')[0])
  34. # if pc != 0:
  35. # with arcpy.da.UpdateCursor('DMshp',['SHAPE@','ZH','KZ','JZ']) as cursorA:
  36. # for curA in cursorA:
  37. # # if curA[1] == '':
  38. # line1 = curA[0]
  39. # if nn < 1000:
  40. # str1 = fillzh(str(nn))
  41. # zh1 = 'K' + str(mm) + '+' + str1
  42. # curA[2] = mm
  43. # curA[3] = nn
  44. # curA[1] = zh1
  45. # cursorA.updateRow(curA)
  46. # nn = nn + 50
  47. # else:
  48. # nn = 0
  49. # mm = mm + 1
  50. # str1 = fillzh(str(nn))
  51. # zh1 = 'K' + str(mm) + '+' + str1
  52. # curA[2] = mm
  53. # curA[3] = nn
  54. # curA[1] = zh1
  55. # cursorA.updateRow(curA)
  56. # nn = nn + 50
  57. # ii = ii + 50
  58. # print('1')
  59. arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
  60. pc = int(arcpy.GetCount_management('DMDshp')[0])
  61. if pc == 0:
  62. pass
  63. else:
  64. with arcpy.da.SearchCursor('DMDshp',['SHAPE@','height']) as cursorAA:
  65. for curAA in cursorAA:
  66. len1 = GQline.measureOnLine(curAA[0])
  67. len2 = round(length - len1)
  68. kz = int(len2 // 1000)
  69. jz = int(len2 % 1000)
  70. gc = round(curAA[1],1)
  71. str2 = fillzh(str(jz))
  72. str1 = 'K' + str(kz) + '+' + str2 + ' '
  73. curA[1] = str1
  74. cursorA.updateRow(curA)
  75. print('1')
  76. # arcpy.SelectLayerByLocation_management('DMDshp', 'WITHIN', buf1)
  77. # pc2 = int(arcpy.GetCount_management('DMDshp')[0])
  78. # if pc2 > 0:
  79. # with arcpy.da.UpdateCursor('DMDshp', ['SHAPE@', 'ZH', 'LJ', 'SFR', 'SFL']) as cursorB:
  80. # for curB in cursorB:
  81. # tuple1 = GQline.queryPointAndDistance(curB[0])
  82. # lj = round(tuple1[2], 4)
  83. # if tuple1[3] == False:
  84. # curB[3] = -1
  85. # else:
  86. # curB[3] = 1
  87. # pt = curB[0]
  88. # buf2 = pt.buffer(1)
  89. # arcpy.SelectLayerByLocation_management('roadshp', 'INTERSECT', buf2)
  90. # pc3 = int(arcpy.GetCount_management('roadshp')[0])
  91. # # arcpy.SelectLayerByLocation_management('roadshp', 'CONTAINS', buf2)
  92. # # pc4 = int(arcpy.GetCount_management('roadshp')[0])
  93. # if pc3 > 0:
  94. # curB[4] = 1
  95. # curB[1] = zh
  96. # curB[2] = lj
  97. # cursorB.updateRow(curB)
  98. if __name__ == '__main__':
  99. try:
  100. dmname()
  101. except arcpy.ExecuteError:
  102. arcpy.AddMessage (arcpy.GetMessages())