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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import arcpy
  2. import math
  3. def zhname(gc,zh):
  4. try:
  5. zh1 = zh.replace('.000','')
  6. except:
  7. zh1 = zh
  8. str1 = zh1 + ' ' + str(gc)
  9. return str1
  10. def dmname():
  11. dmxpath = r'D:\4work_now\20241017dm\20241129\hltdm2\dmx.shp'
  12. dmdpath = r'D:\4work_now\20241017dm\20241129\hltdm2\dmd.shp'
  13. arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
  14. arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
  15. arcpy.AddField_management('DMshp', 'ZH_1', 'TEXT')
  16. with arcpy.da.UpdateCursor('DMshp',['SHAPE@','ZH','ZH_1']) as cursorA:
  17. for curA in cursorA:
  18. zh = curA[1]
  19. if ' ' in zh:
  20. str2 = zh
  21. else:
  22. line1 = curA[0]
  23. buf1 = line1.buffer(0.5)
  24. arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
  25. pc = int(arcpy.GetCount_management('DMDshp')[0])
  26. if pc == 0:
  27. curA[2] = zh
  28. cursorA.updateRow(curA)
  29. print('2')
  30. else:
  31. list1 = []
  32. minnum = 9999
  33. gc = 0
  34. with arcpy.da.SearchCursor('DMDshp',['SHAPE@','LJ','height']) as cursorAA:
  35. for curAA in cursorAA:
  36. lj = curAA[1]
  37. if lj < minnum:
  38. minnum = lj
  39. gc = curAA[2]
  40. str2 = zhname(gc,zh)
  41. curA[2] = str2
  42. cursorA.updateRow(curA)
  43. print('1')
  44. if __name__ == '__main__':
  45. try:
  46. dmname()
  47. except arcpy.ExecuteError:
  48. arcpy.AddMessage (arcpy.GetMessages())