工具箱相关
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TFpolygon1129.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from asyncore import write
  2. import arcpy
  3. def TFtoTB(tbshp,tfshp,outfilepath):
  4. outpath = outfilepath + '\\TF.txt'
  5. #加载
  6. arcpy.MakeFeatureLayer_management(tbshp, 'TB')
  7. arcpy.MakeFeatureLayer_management(tfshp, 'TF')
  8. with open(outpath,'w') as f:
  9. with arcpy.da.SearchCursor('TB',['SHAPE@','宗地编码']) as cursorA:
  10. for curA in cursorA:
  11. list1 = []
  12. shape1 = curA[0]
  13. zdh = curA[1]
  14. #相交,包含,被包含
  15. arcpy.SelectLayerByLocation_management('TF',"INTERSECT",shape1)
  16. ma1 = int(arcpy.GetCount_management('TF').getOutput(0))
  17. if ma1 != 0:
  18. with arcpy.da.SearchCursor('TF',['TFH']) as cursorB:
  19. for curB in cursorB:
  20. tfh1 = str(curB[0])
  21. list1.append(tfh1)
  22. arcpy.SelectLayerByLocation_management('TF',"WITHIN",shape1)
  23. ma2 = int(arcpy.GetCount_management('TF').getOutput(0))
  24. if ma2 != 0:
  25. with arcpy.da.SearchCursor('TF',['TFH']) as cursorC:
  26. for curC in cursorC:
  27. tfh2 = str(curC[0])
  28. list1.append(tfh2)
  29. arcpy.SelectLayerByLocation_management('TF',"COMPLETELY_CONTAINS",shape1)
  30. ma3 = int(arcpy.GetCount_management('TF').getOutput(0))
  31. if ma3 != 0:
  32. with arcpy.da.SearchCursor('TF',['TFH']) as cursorD:
  33. for curD in cursorD:
  34. tfh3 = str(curD[0])
  35. list1.append(tfh3)
  36. if list1 == []:
  37. pass
  38. else:
  39. f.write(zdh)
  40. f.write(':')
  41. ii = 0
  42. list2 = []
  43. while ii < len(list1):
  44. if list1[ii] in list2:
  45. pass
  46. else:
  47. if ii == 0:
  48. f.write(list1[ii])
  49. list2.append(list1[ii])
  50. else:
  51. f.write(',')
  52. f.write(list1[ii])
  53. list2.append(list1[ii])
  54. ii = ii + 1
  55. f.write('\n')
  56. f.flush()
  57. print('ok')
  58. arcpy.AddMessage ('ok')
  59. if __name__ == '__main__':
  60. try:
  61. #输入shp,图幅shp,输出文件夹
  62. TFtoTB(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1),arcpy.GetParameterAsText(2))
  63. except arcpy.ExecuteError:
  64. arcpy.AddMessage (arcpy.GetMessages())