import arcpy import math def fillzh(str1): if len(str1) == 1: str2 = '00' + str1 elif len(str1) == 2: str2 = '0' + str1 else: str2 = str1 return str2 def dmname(): dmxpath = r'D:\4work_now\20241017dm\1028gq\RMQ7\rmqdmx.shp' # dmdpath = r'D:\4work_now\20241017dm\1028gq\PYH\PYH2\pyhzdmd.shp' gqpath = r'D:\4work_now\20241017dm\1028gq\RMQ7\rmqzxx.shp' arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp') # arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp') arcpy.MakeFeatureLayer_management(gqpath, 'GQshp') arcpy.AddField_management('DMshp', 'ZH', 'TEXT') mm = 0 nn = 0 ii = 0 with arcpy.da.SearchCursor('GQshp',['SHAPE@']) as cursorZ: for curZ in cursorZ: GQline = curZ[0] length = GQline.length with arcpy.da.SearchCursor('DMshp', ['SHAPE@', 'KZ', 'JZ', 'ZH']) as cursorA: for curA in cursorA: line1 = curA[0] # while ii <= GQline.length: # pt1 = GQline.positionAlongLine (ii) # buf1 = pt1.buffer(1) # arcpy.SelectLayerByLocation_management('DMshp', 'INTERSECT', buf1) # pc = int(arcpy.GetCount_management('DMshp')[0]) # if pc != 0: # with arcpy.da.UpdateCursor('DMshp',['SHAPE@','ZH','KZ','JZ']) as cursorA: # for curA in cursorA: # # if curA[1] == '': # line1 = curA[0] # if nn < 1000: # str1 = fillzh(str(nn)) # zh1 = 'K' + str(mm) + '+' + str1 # curA[2] = mm # curA[3] = nn # curA[1] = zh1 # cursorA.updateRow(curA) # nn = nn + 50 # else: # nn = 0 # mm = mm + 1 # str1 = fillzh(str(nn)) # zh1 = 'K' + str(mm) + '+' + str1 # curA[2] = mm # curA[3] = nn # curA[1] = zh1 # cursorA.updateRow(curA) # nn = nn + 50 # ii = ii + 50 # print('1') arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1) pc = int(arcpy.GetCount_management('DMDshp')[0]) if pc == 0: pass else: with arcpy.da.SearchCursor('DMDshp',['SHAPE@','height']) as cursorAA: for curAA in cursorAA: len1 = GQline.measureOnLine(curAA[0]) len2 = round(length - len1) kz = int(len2 // 1000) jz = int(len2 % 1000) gc = round(curAA[1],1) str2 = fillzh(str(jz)) str1 = 'K' + str(kz) + '+' + str2 + ' ' curA[1] = str1 cursorA.updateRow(curA) print('1') # arcpy.SelectLayerByLocation_management('DMDshp', 'WITHIN', buf1) # pc2 = int(arcpy.GetCount_management('DMDshp')[0]) # if pc2 > 0: # with arcpy.da.UpdateCursor('DMDshp', ['SHAPE@', 'ZH', 'LJ', 'SFR', 'SFL']) as cursorB: # for curB in cursorB: # tuple1 = GQline.queryPointAndDistance(curB[0]) # lj = round(tuple1[2], 4) # if tuple1[3] == False: # curB[3] = -1 # else: # curB[3] = 1 # pt = curB[0] # buf2 = pt.buffer(1) # arcpy.SelectLayerByLocation_management('roadshp', 'INTERSECT', buf2) # pc3 = int(arcpy.GetCount_management('roadshp')[0]) # # arcpy.SelectLayerByLocation_management('roadshp', 'CONTAINS', buf2) # # pc4 = int(arcpy.GetCount_management('roadshp')[0]) # if pc3 > 0: # curB[4] = 1 # curB[1] = zh # curB[2] = lj # cursorB.updateRow(curB) if __name__ == '__main__': try: dmname() except arcpy.ExecuteError: arcpy.AddMessage (arcpy.GetMessages())