日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

arcgis出界址点成果表_界址点成果表打印

發布時間:2025/3/11 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 arcgis出界址点成果表_界址点成果表打印 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#coding: UTF-8

importarcpyimportosimporttypesimportstringimportshutilimportsysimportreimportopenpyxl#ws是一個xls的工作表#mode是替換模型,1完全替換,2模糊替換,3 追加替換

defreplacexls(ws,mode, text, replaceText):

rows=ws.max_row

cols=ws.max_column

changeCells=0if (mode <0):return -1

elif (mode>3):return -1

for row in range(1, rows + 1):for col in range(1, cols + 1):try:

content= ws.cell(row=row, column=col).valueif (content !=None):#mode1: fullmatch replacement

if (mode == 1):if (content ==text):

ws.cell(row=row, column=col).value =replaceText

changeCells+= 1

#mode2: partial replacement

elif (mode == 2):if (type(content) ==str):

ws.cell(row=row, column=col).value = content.replace(text, replaceText, 1)

changeCells+= 1

#mode3: partialmatch and filling

elif (mode == 3):if (type(content) ==str):

ws.cell(row=row, column=col).value = content.replace(text, text + replaceText, 1)

changeCells+= 1

exceptException as e:print(traceback.format_exc())returnchangeCellsdefchangeData(file, mode, text, replaceText):#load the file(*.xlsx)

wb =openpyxl.load_workbook(file)#! deal with one sheet

ws=wb.worksheets[0]

replacexls(ws, mode, text, replaceText)definitProgress(hint,num):

arcpy.SetProgressor("step", hint,0,num,1)defstep():

arcpy.SetProgressorLabel(u"waiting....")

arcpy.SetProgressorPosition()deffreeProgress():

arcpy.ResetProgressor()defAddLayer(mxd,inFeature):

df=arcpy.mapping.ListDataFrames(mxd)[0]

addLayer=arcpy.mapping.Layer(inFeature)

arcpy.mapping.AddLayer(df, addLayer,"TOP") #AUTO_ARRANGE�?BOTTOM",TOP#######

defgetLayer(layername):

layername=layername.upper()

mxd= arcpy.mapping.MapDocument("CURRENT")try:for lyr inarcpy.mapping.ListLayers(mxd):if lyr.name.upper()==layername:returnlyrreturnNonefinally:delmxd###

defmidFill(sumn,mystr,Fill):

n=getlength(mystr)if n>=sumn:returnmystr

leftn=int((sumn-n)/2)

s=""lefts=s.ljust(leftn,Fill)

s=""rightn=sumn-n-leftn

rights=s.ljust(rightn,Fill)return lefts+mystr+rights#獲得一個表的記錄數

defgetCount(inFeature):

result=arcpy.GetCount_management(inFeature)

count=int(result.getOutput(0))returncountdefclearSelect(inFeature):

mylyr="mylyr"arcpy.MakeFeatureLayer_management (inFeature, mylyr)

arcpy.SelectLayerByAttribute_management (mylyr,"CLEAR_SELECTION")defvalidate_sheet_name(sheet_name):"""Validate sheet name to excel limitations

- 31 character length

- there characters not allowed : \ / ? * [ ]"""

importreif len(sheet_name) > 31:

sheet_name= sheet_name[:31]#Replace invalid sheet character names with an underscore

r = re.compile(r'[:\\\/?*\[\]]')

sheet_name= r.sub("_", sheet_name)returnsheet_name#把內多邊形,分解出來

defsplitNgeometry(mgeometry):

num=mgeometry.count

Sumarray=arcpy.Array()

parray=arcpy.Array()for i inrange(num):

pt=mgeometry[i]ifpt:

parray.add(pt)else:#內邊形

Sumarray.add(parray)

parray.removeAll()

Sumarray.add(parray)returnSumarraydefgetJZDH(pgeometry):

mylayer="mylayer"arcpy.MakeFeatureLayer_management(JZDFeature, mylayer)

arcpy.SelectLayerByLocation_management (mylayer,'intersect',pgeometry )

num=getCount(mylayer)

cur=arcpy.da.SearchCursor(mylayer,[JZDHFieldName])

myJZDH=""i=1

for row incur:

myJZDH=row[0]ifcur:delcurreturnmyJZDH

startrow=4

#獲得點的距離

defpointDistance(pt1,pt2):return math.sqrt((pt1.X-pt2.X)*(pt1.X-pt2.X)+(pt1.Y-pt2.Y)*(pt1.Y-pt2.Y))defwriteonexls(partgeometry,ws):globalstartrow

num=partgeometry.countfor i inrange(num):

pt=partgeometry[i]

x=pt.X

y=pt.Y

arcpy.AddMessage(str(x)+":"+str(y))

xstr="%.3f" %x

ystr="%.3f" %y

ws.cell(row=startrow, column=3).value=ystr

ws.cell(row=startrow, column=4).value=xstr

pointGeometry=arcpy.PointGeometry(pt)

JZDH=getJZDH(pointGeometry)

ws.cell(row=startrow, column=1).value =JZDHif (i < num - 1):

pt2= partgeometry[i+1]

linelen=pointDistance(pt,pt2)

ws.cell(row=startrow+1, column=2).value = "%.2f" %linelen

startrow=startrow+2

defwriteXLS(ZDH,geometry):

scriptPath=sys.path[0]

toolSharePath=scriptPath #os.path.dirname(scriptPath)

myxls="界址點2000國家大地坐標系.xlsx" ##encode("GBK")

sFile=toolSharePath+u"/xls/"+myxls

tFile=outpath+"/"+ZDH+".xlsx"arcpy.AddMessage(u"sFile"+sFile+","+tFile)

shutil.copyfile(sFile,tFile)

wb=openpyxl.load_workbook(tFile)

ws=wb.worksheets[0]

replacexls(ws,2, "[宗地號]", ZDH)

area=geometry.area

replacexls(ws,2, "[平方米]", '%.2f'%area)

area=area/10000replacexls(ws,2, "[公頃]", '%.4f' %area)

linelen=geometry.length

replacexls(ws,2, "[總長]", '%.2f' %linelen)globalstartrow

startrow= 4part_count= geometry.partCount #有幾部分

pointcount=geometry.pointCount

replacexls(ws,2, "[總節點]", '%d' % (pointcount+part_count-1) )

Sumarray=arcpy.Array()for i inrange(part_count):

partgeometry=geometry.getPart(i)

SpliArray=splitNgeometry(partgeometry)

N=SpliArray.count#arcpy.AddMessage("NNNNN=====:"+str(N))

for j inrange(N):

Splitgeometry=SpliArray[j]

writeonexls(Splitgeometry,ws)

wb.save(tFile)defmain():

num=getCount(ZDFeature)if num<1:

arcpy.AddMessage(u"宗地沒有數據")returnclearSelect(JZDFeature)

num=getCount(JZDFeature)if num<1:

arcpy.AddMessage(u"宗地沒有數據")return

for row in arcpy.da.SearchCursor(ZDFeature, ["OID@", "SHAPE@",ZDHFieldName]):

FID=row[0]

pgeometry=row[1]

ZDH=row[2]

writeXLS(ZDH,pgeometry)defprintauthor(toolname):

titlestr=""sumn=60Fill='*'titlestr=titlestr.ljust(sumn,Fill)

arcpy.AddMessage(titlestr)

arcpy.AddMessage(midFill(sumn,u"歡迎使用:"+toolname,Fill))

mystr=u"本工具閆磊編寫QQ:276529800,電話:18987281928"arcpy.AddMessage(midFill(sumn,mystr,Fill))

mystr=u"使用前請做好數據備份,工具產生的不良后果請自行承擔!"arcpy.AddMessage(midFill(sumn,mystr,Fill))

arcpy.AddMessage(titlestr)

ZDFeature= arcpy.GetParameterAsText(0) #宗地

ZDHFieldName=arcpy.GetParameterAsText(1) #宗地號字段

JZDFeature=arcpy.GetParameterAsText(2) #輸出數據

JZDHFieldName=arcpy.GetParameterAsText(3) #界址點號字段

outpath=arcpy.GetParameterAsText(4) #路徑

arcpy.env.overwriteOutput=True#printauthor(u"部標準坐標導入")

if notos.path.exists(outpath):

os.makedirs(outpath)

main()

總結

以上是生活随笔為你收集整理的arcgis出界址点成果表_界址点成果表打印的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。