12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import arcpy
- import math
-
- def zhname(gc,zh):
- try:
- zh1 = zh.replace('.000','')
- except:
- zh1 = zh
- str1 = zh1 + ' ' + str(gc)
- return str1
-
- def dmname():
- dmxpath = r'D:\4work_now\20241017dm\20241129\hltdm2\dmx.shp'
- dmdpath = r'D:\4work_now\20241017dm\20241129\hltdm2\dmd.shp'
- arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
- arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
-
- arcpy.AddField_management('DMshp', 'ZH_1', 'TEXT')
- with arcpy.da.UpdateCursor('DMshp',['SHAPE@','ZH','ZH_1']) as cursorA:
- for curA in cursorA:
- zh = curA[1]
- if ' ' in zh:
- str2 = zh
- else:
- line1 = curA[0]
- buf1 = line1.buffer(0.5)
- arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
- pc = int(arcpy.GetCount_management('DMDshp')[0])
- if pc == 0:
- curA[2] = zh
- cursorA.updateRow(curA)
- print('2')
- else:
- list1 = []
- minnum = 9999
- gc = 0
- with arcpy.da.SearchCursor('DMDshp',['SHAPE@','LJ','height']) as cursorAA:
- for curAA in cursorAA:
- lj = curAA[1]
- if lj < minnum:
- minnum = lj
- gc = curAA[2]
-
- str2 = zhname(gc,zh)
- curA[2] = str2
- cursorA.updateRow(curA)
- print('1')
-
-
-
- if __name__ == '__main__':
- try:
- dmname()
- except arcpy.ExecuteError:
- arcpy.AddMessage (arcpy.GetMessages())
|