import arcpy import xlwt import os import random def dmorder(dmxname,zxx,list1): #循环一遍list1,找到交点和交点离起点的距离 ii = 0 #创建一个list,存放线形、距离,交点(point) list2 = [] while ii < len(list1): xjpg = zxx.intersect (list1[ii], 1) xjp = xjpg.firstPoint disxj = zxx.measureOnLine (xjp) list3 = [] list3.append(list1[ii]) list3.append(disxj) list3.append(xjp) list2.append(list3) ii = ii + 1 #排序(用第二个参数排序,排升序) list2.sort(key=lambda x: x[1], reverse=False) #再创建一个list,放线形、线名 list4 = [] mm = 0 while mm < len(list2): list3 = [] list3.append(list2[mm][0]) num = mm + 1 #不足两位的用0填补 if mm < 9: lname = dmxname + '#0' + str(num) else: lname = dmxname + '#' + str(num) list3.append(lname) list3.append(list2[mm][2]) list4.append(list3) mm = mm + 1 return list4 def diszd(zxx,zds): ii = 0 #存放折点,距离 list1 = [] while ii < zds.count: dis1 = zxx.measureOnLine (zds[ii]) list2 = [] list2.append(zds[ii]) list2.append(dis1) list1.append(list2) ii = ii + 1 return list1 def jdpd(line,listzd,disxjp): fp = line.firstPoint #挨个和交点比对,得到距离刚好大于当前点,且小于下一个点的 ii = 0 #以防出现空的 strResult = '' while ii < listzd.count: disf = listzd[ii][1] disl = listzd[ii + 1][1] #有可能正好在某个点上,所以要细分情况 if disxjp > disf and disxjp < disl: #获得A和B两个点,然后就是套用算法 lnfpx = listzd[ii][0].X lnfpy = listzd[ii][0].Y lnlpx = listzd[ii + 1][0].X lnlpy = listzd[ii + 1][0].Y ax = lnlpx - lnfpx ay = lnlpy - lnfpy bx = fp.X - lnfpx by = fp.Y - lnfpy judge = ax * by - ay * bx if judge > 0 : strResult= "LEFT" else: strResult = "RIGHT" break elif disxjp == disf and disxjp < disl: #获得A和B两个点,然后就是套用算法 lnfpx = listzd[ii][0].X lnfpy = listzd[ii][0].Y lnlpx = listzd[ii + 1][0].X lnlpy = listzd[ii + 1][0].Y ax = lnlpx - lnfpx ay = lnlpy - lnfpy bx = fp.X - lnfpx by = fp.Y - lnfpy judge = ax * by - ay * bx if judge > 0 : strResult= "LEFT" else: strResult = "RIGHT" break elif disxjp > disf and disxjp == disl: #获得A和B两个点,然后就是套用算法 lnfpx = listzd[ii][0].X lnfpy = listzd[ii][0].Y lnlpx = listzd[ii + 1][0].X lnlpy = listzd[ii + 1][0].Y ax = lnlpx - lnfpx ay = lnlpy - lnfpy bx = fp.X - lnfpx by = fp.Y - lnfpy judge = ax * by - ay * bx if judge > 0 : strResult= "LEFT" else: strResult = "RIGHT" break else: ii = ii + 1 return strResult def tbclip(dxtgpath,dxtapath,outpath): #创建一个shp文件 gcpath = outpath + '\\GCtb.shp' try: arcpy.CreateFeatureclass_management(outpath, 'GCtb.shp', 'POLYGON') except: arcpy.Delete_management(gcpath) arcpy.CreateFeatureclass_management(outpath, 'GCtb.shp', 'POLYGON') #读取 arcpy.MakeFeatureLayer_management(dxtgpath, 'dxtg') arcpy.MakeFeatureLayer_management(dxtapath, 'dxta') arcpy.MakeFeatureLayer_management(gcpath, 'gc') #加图斑类型字段(英文) arcpy.AddField_management('gc','LX','TEXT') #先存图形,再更新图形,再赋值 with arcpy.da.InsertCursor('gc', ['SHAPE@']) as cursorH: with arcpy.da.SearchCursor('dxtg',['SHAPE@','Layer']) as cursorI: for curI in cursorI: if curI[1] == '9611': list1 = [] list1.append(curI[0]) cursorH.insertRow(list1) with arcpy.da.UpdateCursor('gc',['SHAPE@','FID','LX']) as cursorJ: for curJ in cursorJ: pg4 = curJ[0] id1 = curJ[1] #判断是否有没有相交的 arcpy.SelectLayerByLocation_management('gc',"INTERSECT",pg4) count1 = int(arcpy.GetCount_management('gc')[0]) if count1 != 0: #其中小的裁大的 with arcpy.da.SearchCursor('gc',['SHAPE@','FID']) as cursorK: for curK in cursorK: pg5 = curK[0] id2 = curK[1] if id1 == id2: pass else: if pg4.area >= pg5.area: #再看下是否相交 pg7 = pg4.intersect (pg5, 4) if pg7.area != 0: #直接裁剪,再赋值 #如果差异没办法用的话,换成交集取反 pg6 = pg4.difference (pg5) if pg6.area == 0: pg8 = pg4.symmetricDifference (pg7) if pg8.area != 0: curJ[0] = pg8 pg4 = pg8 cursorJ.updateRow(curJ) else: curJ[0] = pg6 pg4 = pg6 cursorJ.updateRow(curJ) #判断是否有包含的 arcpy.SelectLayerByLocation_management('gc',"WITHIN",pg4) count2 = int(arcpy.GetCount_management('gc')[0]) if count2 != 0: with arcpy.da.SearchCursor('gc',['SHAPE@','FID']) as cursorL: for curL in cursorL: pg7 = curL[0] id3 = curL[1] if id3 == id1: pass else: pg8 = pg4.symmetricDifference (pg7) curJ[0] = pg8 pg4 = pg8 cursorJ.updateRow(curJ) #在这里找赋值 arcpy.SelectLayerByLocation_management('dxta',"WITHIN",pg4) count2 = int(arcpy.GetCount_management('dxta')[0]) if count2 != 0: with arcpy.da.SearchCursor('dxta',['Layer','RefName']) as cursorG: for curG in cursorG: if curG[0] == '9611': if curG[1] == '0101' or curG[1] == '0102' or curG[1] == '0103': #耕地 curJ[2] = 'GD' cursorJ.updateRow(curJ) break elif curG[1] == '0301' or curG[1] == '0302' or curG[1] == '0307': #林地 curJ[2] = 'LD' cursorJ.updateRow(curJ) break elif curG[1] == '0401' or curG[1] == '0402' or curG[1] == '0403' or curG[1] == '0404': #都是草地 curJ[2] = 'CD' cursorJ.updateRow(curJ) break elif curG[1] == '1101': #河流 curJ[2] = 'HL' cursorJ.updateRow(curJ) break elif curG[1] == '1003': #公路 curJ[2] = 'GL' cursorJ.updateRow(curJ) break elif curG[1] == '1004' or curG[1] == '1006': #道路 curJ[2] = 'DL' cursorJ.updateRow(curJ) break elif curG[1] == '1107': #沟渠 curJ[2] = 'GQ' cursorJ.updateRow(curJ) break elif curG[1] == '1106': #滩涂 curJ[2] = 'TT' cursorJ.updateRow(curJ) break elif curG[1] == '1104': #坑塘 curJ[2] = 'KT' cursorJ.updateRow(curJ) break elif curG[1] == '0701' or curG[1] == '0702': #房屋 curJ[2] = 'FW' cursorJ.updateRow(curJ) break elif curG[1] == '1204': #盐碱地 curJ[2] = 'YJD' cursorJ.updateRow(curJ) break elif curG[1] == '1205': #沙地 curJ[2] = 'SD' cursorJ.updateRow(curJ) break elif curG[1] == '1206': #裸土地 curJ[2] = 'LTD' cursorJ.updateRow(curJ) break elif curG[1] == '1207': #石砾地 curJ[2] = 'SLD' cursorJ.updateRow(curJ) break elif curG[1] == '0305': #灌木 curJ[2] = 'GM' cursorJ.updateRow(curJ) break return gcpath def dwpd(lx): dw = '' if lx == 'GD': dw = '耕地' elif lx == 'LD': dw = '林地' elif lx == 'CD': dw = '草地' elif lx == 'TT': dw = '滩涂' elif lx == 'KT': dw = '坑塘' elif lx == 'YJD': dw = '盐碱地' elif lx == 'SD': dw = '沙地' elif lx == 'LTD': dw = '裸土地' elif lx == 'SLD': dw = '石砾地' elif lx == 'GM': dw = '灌木' elif lx == '': dw = 'XX' return dw def randomjj(jjs,jjz): #随机一个数 rand_num = round(random.uniform(jjs, jjz),3) return rand_num def DM(dmxpath,dxtpath,dempath,jjs0,jjz0,outpath): #间距 jjs = float(jjs0) jjz = float(jjz0) #把图名的开头提出来 dmxfile = dmxpath.split('\\',-1)[-1] dmxname = dmxfile.split('.',-1)[0] #读取断面线 dmxlpath = dmxpath + '\\Polyline' arcpy.MakeFeatureLayer_management(dmxlpath,'dmx') #读取水下点 sxdpath = dmxpath + '\\Point' arcpy.MakeFeatureLayer_management(sxdpath,'sxd') #读取地形图的线、面、注记 dxtlpath = dxtpath + '\\Polyline' arcpy.MakeFeatureLayer_management(dxtlpath,'dxtl') dxtgpath = dxtpath + '\\Polygon' dxtapath = dxtpath + '\\Annotation' #需要一个过程文件,把图斑裁出来 gcpath = tbclip(dxtgpath,dxtapath,outpath) arcpy.MakeFeatureLayer_management(gcpath,'gcshp') #找寻所有的断面线,生成一个包含断面线形状的list #找到zzx list1 = [] with arcpy.da.SearchCursor('dmx',['SHAPE@','Layer']) as cursorA: for curA in cursorA: layer = curA[1] if layer == 'DMX': list1.append(curA[0]) elif layer == 'zxx': zxx = curA[0] #通过中心线找到断面名(断面前缀、zxx、断面线list) #list2包括线形和线名,交点 list2 = dmorder(dmxname,zxx,list1) #对每根线做操作 ii = 0 #先得到zxx的所有折点 zds = zxx.getPart(0) #把折点距起点的距离全部算出来,再存放为listzd(折点,距离) listzd = diszd(zxx,zds) while ii < len(list2): line = list2[ii][0] xjp = list2[ii][2] disxjp = zxx.measureOnLine (xjp) #首先判定线的起点是左基点还是右基点 bl = jdpd(line,listzd,disxjp) #对应线的水下点,其距起点的距离,高程,地物类型搞出来 list4 = [] #这个是最终的不管左右的list list40 = [] linebuf = line.buffer(0.1) arcpy.SelectLayerByLocation_management('sxd',"WITHIN",linebuf) with arcpy.da.SearchCursor('sxd',['SHAPE@','Layer','Elevation']) as cursorB: for curB in cursorB: layer1 = curB[1] if layer1 == 'sxd': list3 = [] #先把点挪到线上 disp = line.distanceTo (curB[0]) if disp == 0: #那就直接用 list3.append(curB[0]) dissxd = line.measureOnLine (curB[0]) list3.append(dissxd) list3.append(curB[2]) list3.append('水下') list4.append(list3) else: sxd1 = line.queryPointAndDistance(curB[0]) sxd = sxd1[0].firstPoint list3.append(sxd) list3.append(sxd1[1]) list3.append(curB[2]) list3.append('水下') list4.append(list3) #把河流图斑踢出来 #坎子、房子、沟渠、道路需要岔线上的先添加 #线地形图涉及到坎子 arcpy.SelectLayerByLocation_management('dxtl',"INTERSECT",line) count1 = int(arcpy.GetCount_management('dxtl')[0]) if count1 != 0: with arcpy.da.SearchCursor('dxtl',['SHAPE@','Layer','Linetype']) as cursorC: for curC in cursorC: layer2 = curC[1] lt = curC[2] if layer2 == 'DMTZ' and lt == '10421': line1 = curC[0] kjdg = line.intersect (line1, 1) kjd = kjdg.firstPoint kjdx = kjd.X kjdy = kjd.Y kjdstr = str(kjdx) + ' ' + str(kjdy) list5 = [] list5.append(kjd) #距起点的距离 disk = line.measureOnLine (kjd) list5.append(disk) #z值 kjz = arcpy.GetCellValue_management(dempath, kjdstr) try: list5.append(float(kjz.getOutput(0))) except: list5.append(0) # list5.append(-100) #地物类型 list5.append('坎上') list4.append(list5) #找出所有相交的图斑 arcpy.SelectLayerByLocation_management('gcshp',"INTERSECT",line) with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorD: for curD in cursorD: layer3 = curD[1] if layer3 == 'FW': pg1 = curD[0] pgb = pg1.boundary () pjdg = pgb.intersect (line, 1) pjdgc = pjdg.pointCount mm = 0 while mm < pjdgc: list6 = [] pjd = pjdg[mm] pjdx = pjd.X pjdy = pjd.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(pjd) #距离 dispj = line.measureOnLine (pjd) list6.append(dispj) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append('房屋') list4.append(list6) mm = mm + 1 elif layer3 == 'GL': pg1 = curD[0] pgb = pg1.boundary () pjdg = pgb.intersect (line, 1) pjdgc = pjdg.pointCount mm = 0 while mm < pjdgc: list6 = [] pjd = pjdg[mm] pjdx = pjd.X pjdy = pjd.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(pjd) #距离 dispj = line.measureOnLine (pjd) list6.append(dispj) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append('公路') list4.append(list6) mm = mm + 1 elif layer3 == 'DL': pg1 = curD[0] pgb = pg1.boundary () pjdg = pgb.intersect (line, 1) pjdgc = pjdg.pointCount mm = 0 while mm < pjdgc: list6 = [] pjd = pjdg[mm] pjdx = pjd.X pjdy = pjd.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(pjd) #距离 dispj = line.measureOnLine (pjd) list6.append(dispj) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append('道路') list4.append(list6) mm = mm + 1 elif layer3 == 'GQ': pg1 = curD[0] pgb = pg1.boundary () pjdg = pgb.intersect (line, 1) pjdgc = pjdg.pointCount mm = 0 while mm < pjdgc: list6 = [] pjd = pjdg[mm] pjdx = pjd.X pjdy = pjd.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(pjd) #距离 dispj = line.measureOnLine (pjd) list6.append(dispj) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append('沟渠') list4.append(list6) mm = mm + 1 #一个布尔值,用于判断端点是否需要挪 bl1 = 0 #从左基点开始,每2.8m取一个点,避开上面已经剃过点的地方 if bl == "LEFT": #那么前面的距离顺序都是对的,直接找就成了 #先存放左基点 #判定是否在水里 fp = line.firstPoint fpp = arcpy.PointGeometry(fp) #首先看点落在哪个图斑里 arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",fpp) with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorF: for curF in cursorF: lx = curF[1] dw = dwpd(lx) if dw != '': list6 = [] pjdx = fp.X pjdy = fp.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(fp) #距离 list6.append(0) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append(dw) list4.append(list6) else: #如果不是就记录下它的坐标,到时候套第一个水下点的高程 list6 = [] pjdx = fp.X pjdy = fp.Y list6.append(fp) #距离 list6.append(0) #z值 pjz = -9999 list6.append(float(pjz)) #备注 list6.append(dw) list4.append(list6) bl1 = 1 #隔一定距离存一个点 length = line.length #总长 zlen = 0 while length - zlen > jjz: #如果比最大值小的话就直接取 jj1 = randomjj(jjs,jjz) zlen = zlen + jj1 ptg2 = line.positionAlongLine(zlen) pt2 = ptg2.firstPoint list6 = [] arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",ptg2) count2 = int(arcpy.GetCount_management('gcshp')[0]) with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorG: for curG in cursorG: lx = curG[1] dw = dwpd(lx) if dw != '': list6 = [] pjdx = pt2.X pjdy = pt2.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(pt2) #距离 list6.append(zlen) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append(dw) list4.append(list6) #右基点 fp = line.lastPoint fpp = arcpy.PointGeometry(fp) #首先看点落在哪个图斑里 arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",fpp) with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorF: for curF in cursorF: lx = curF[1] dw = dwpd(lx) if dw != '': list6 = [] pjdx = fp.X pjdy = fp.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(fp) #距离 list6.append(length) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append(dw) list4.append(list6) else: list6 = [] list6.append(fp) #距离 list6.append(length) #z值 pjz = -9999 list6.append(float(pjz)) #备注 list6.append(dw) list4.append(list6) bl1 = -1 list40 = list4 else: fp = line.lastPoint fpp = arcpy.PointGeometry(fp) #首先看点落在哪个图斑里 arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",fpp) with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorF: for curF in cursorF: lx = curF[1] dw = dwpd(lx) if dw != '': list6 = [] pjdx = fp.X pjdy = fp.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(fp) #距离 list6.append(0) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append(dw) list40.append(list6) else: list6 = [] list6.append(fp) #距离 list6.append(0) #z值 pjz = -9999 list6.append(float(pjz)) #备注 list6.append(dw) list40.append(list6) bl1 = 1 #隔一定距离存一个点 length = line.length zlen = 0 while length - zlen > jjz: jj1 = randomjj(jjs,jjz) zlen = zlen + jj1 jj2 = length - zlen ptg2 = line.positionAlongLine(jj2) pt2 = ptg2.firstPoint list6 = [] arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",ptg2) with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorG: for curG in cursorG: lx = curG[1] dw = dwpd(lx) if dw != '': list6 = [] pjdx = pt2.X pjdy = pt2.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(pt2) #距离 list6.append(zlen) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append(dw) list40.append(list6) #右基点 fp = line.firstPoint fpp = arcpy.PointGeometry(fp) #首先看点落在哪个图斑里 arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",fpp) with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorF: for curF in cursorF: lx = curF[1] dw = dwpd(lx) if dw != '': list6 = [] pjdx = fp.X pjdy = fp.Y pjdstr = str(pjdx) + ' ' + str(pjdy) list6.append(fp) #距离 list6.append(length) #z值 pjz = arcpy.GetCellValue_management(dempath, pjdstr) try: list6.append(float(pjz.getOutput(0))) except: list6.append(0) # list6.append(-100) #备注 list6.append(dw) list40.append(list6) else: list6 = [] list6.append(fp) #距离 list6.append(length) #z值 pjz = -9999 list6.append(float(pjz)) #备注 list6.append(dw) list40.append(list6) bl1 = -1 #把list4里的距离重新计算后放入40 oo = 0 while oo < len(list4): list9 = [] list9.append(list4[oo][0]) dis1 = length - list4[oo][1] list9.append(dis1) list9.append(list4[oo][2]) list9.append(list4[oo][3]) list40.append(list9) oo = oo + 1 #排序 list40.sort(key=lambda x: x[1], reverse=False) #把起点或者终点的水下点挪到第一个 if bl1 == 1: #左端点 if list40[0][1] == 0 and list40[0][2] == -9999: fp1 = list40[0][0] list40[1][0] = fp1 list40[1][1] = 0 del list40[0] else: fp1 = list40[1][0] list40[0][0] = fp1 list40[0][1] = 0 del list40[1] if bl1 == -1: #右端点 len1 = len(list40)-1 if list40[len1][1] == length and list40[len1][2] == -9999: fp1 = list40[len(list40)-1][0] list40[len(list40)-2][0] = fp1 list40[len(list40)-2][1] = length del list40[len(list40)-1] else: fp1 = list40[len(list40)-2][0] list40[len(list40)-1][0] = fp1 list40[len(list40)-1][1] = length del list40[len(list40)-2] #排除距离相同的尾巴 if round(list40[len(list40)-1][1],3) == round(list40[len(list40)-2][1],3): del list40[len(list40)-1] if round(list40[0][1],3) == round(list40[1][1],3): del list40[1] #这里把地形变换的第一个水下,和最后一个水下写成水边线 qq = 0 while qq < (len(list40) - 1): if list40[qq][3] == '水下': #判断它的前后是否不是水下 if list40[qq-1][3] != '水下' and list40[qq-1][3] != '左端点' and list40[qq-1][3] != '水边线': list40[qq][3] = '水边线' elif list40[qq+1][3] != '水下' and list40[qq+1][3] != '右端点' and list40[qq+1][3] != '水边线': list40[qq][3] = '水边线' qq = qq + 1 else: qq = qq + 1 #新建一个excel expath = outpath + '\\' + list2[ii][1] + '.xls' #判断下存不存在,存在则删除 if os.path.exists(expath): # 删除文件 os.remove(expath) #写个抬头 workBook = xlwt.Workbook(encoding='utf-8') sheet = workBook.add_sheet("sheet1") sheet.write(0,0,'点号') sheet.write(0,1,'X') sheet.write(0,2,'Y') sheet.write(0,3,'Z') sheet.write(0,4,'备注') sheet.write(0,5,'累距') pp = 0 while pp < len(list40): if pp == 0: pp1 = pp + 1 sheet.write(pp1,0,(pp+1)) try: sheet.write(pp1,1,round(list40[pp][0].X,4)) sheet.write(pp1,2,round(list40[pp][0].Y,4)) except: pt3 = list40[pp][0].firstPoint sheet.write(pp1,1,round(pt3.X,4)) sheet.write(pp1,2,round(pt3.Y,4)) sheet.write(pp1,3,round(list40[pp][2],3)) sheet.write(pp1,4,'左端点') sheet.write(pp1,5,round(list40[pp][1],3)) pp = pp + 1 elif pp == len(list40) - 1: pp1 = pp + 1 sheet.write(pp1,0,(pp+1)) try: sheet.write(pp1,1,round(list40[pp][0].X,4)) sheet.write(pp1,2,round(list40[pp][0].Y,4)) except: pt3 = list40[pp][0].firstPoint sheet.write(pp1,1,round(pt3.X,4)) sheet.write(pp1,2,round(pt3.Y,4)) sheet.write(pp1,3,round(list40[pp][2],3)) sheet.write(pp1,4,'右端点') sheet.write(pp1,5,round(list40[pp][1],3)) pp = pp + 1 else: pp1 = pp + 1 sheet.write(pp1,0,(pp+1)) try: sheet.write(pp1,1,round(list40[pp][0].X,4)) sheet.write(pp1,2,round(list40[pp][0].Y,4)) except: pt3 = list40[pp][0].firstPoint sheet.write(pp1,1,round(pt3.X,4)) sheet.write(pp1,2,round(pt3.Y,4)) sheet.write(pp1,3,round(list40[pp][2],3)) sheet.write(pp1,4,list40[pp][3]) sheet.write(pp1,5,round(list40[pp][1],3)) pp = pp + 1 workBook.save(expath) arcpy.AddMessage (list2[ii][1] + ' finish') ii = ii + 1 if __name__ == '__main__': try: #断面线所在的dwg,地形图,dem,上间距,下间距,输出文件夹 DM(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1),arcpy.GetParameterAsText(2),arcpy.GetParameterAsText(3),arcpy.GetParameterAsText(4),arcpy.GetParameterAsText(5)) # DM(r"D:\3work_now\20231108HHdm\1121\QJM2.dwg",r'D:\3work_now\20231108HHdm\1121\21求吉玛村2#护岸工程.dwg',r'D:\3work_now\20231108HHdm\1121\21.tif',2,3,r'D:\3work_now\20231108HHdm\1121\19') except arcpy.ExecuteError: arcpy.AddMessage (arcpy.GetMessages())