python封装工具类多个项目使用_【arcpy项目实战】将多个点两两生成的最短路径pyhon代码封装入script中...
import os
import arcpy
arcpy.env.workspace=arcpy.GetParameterAsText(0)#選取環境
cost =arcpy.GetParameterAsText(1) #成本柵格
shp=arcpy.GetParameterAsText(2) #選取要素的要素類
out_path=arcpy.GetParameterAsText(3) #命名字段裁剪后輸出目錄
cursor=arcpy.da.SearchCursor(shp,['shape@','class','市'])#shape@代表單個要輸,class是其中一個字段
for shit in cursor:
num=str(shit[1]) #將class編號轉換為字符串
out_name=num+"f.shp"#輸出屬性表中每條要素
#arcpy.CopyFeatures_management(row,"c:\\users\\wolfer\\desktop\\test\\new\\"+out_name)#將生成的要素復制一份
#print shp#輸出要素名
arcpy.Select_analysis(shp,out_path+"\\"+out_name,'"class"=\''+num+ '\'')#利用sql查詢要素中的每一條字段,查詢語句需要專制
other=arcpy.da.SearchCursor(shp,['shape@','class','市'])
for row in other:
if row[1]>shit[1]:
out_name1=str(shit[1])+"f"+str(row[1])+"t.shp"
num1=str(row[1])
arcpy.Select_analysis(shp, out_path+"\\"+out_name1,'CLASS=\''+ num1+ '\'') # 利用sql查詢要素中的每一條字段,查詢語句需要專制
arcpy.CheckOutExtension("spatial")
#本地變量
# Local variables:
julishange = "juli"+shit[1]+"f"+row[1]+"t"
huisushange ="huisu"+shit[1]+"f"+row[1]+"t"
lujingshangge = "lujing"+shit[1]+"f"+row[1]+"t"
alline="alline"
tmp="tmp"
line="line"+str(shit[1])+"f"+str(row[1])+"t"
# Process: 成本回溯鏈接
arcpy.gp.CostBackLink_sa(out_path+"\\"+out_name, cost, huisushange, "", julishange)
# Process: 成本路徑
arcpy.gp.CostPath_sa(out_path+"\\"+out_name1, julishange, huisushange, lujingshangge, "EACH_CELL", "FID")
arcpy.AddField_management(lujingshangge,"cost", "LONG")
cursor = arcpy.da.UpdateCursor(lujingshangge, ["PATHCOST", "cost"])
# For each row, evaluate the WELL_YIELD value (index position
# of 0), and update WELL_CLASS (index position of 1)
for one in cursor:
one[1] =one[0]
# Update the cursor with the updated list
cursor.updateRow(one)
# Process: 柵格轉折線
arcpy.RasterToPolyline_conversion(lujingshangge,line, "ZERO", "0", "SIMPLIFY", "cost")
arcpy.AddField_management(line, "frm", "TEXT")
arcpy.AddField_management(line, "to", "TEXT")
cursor = arcpy.da.UpdateCursor(line, ["frm", "to"])
# For each row, evaluate the WELL_YIELD value (index position
# of 0), and update WELL_CLASS (index position of 1)
for m in cursor:
m[0] = shit[1]
m[1] = row[1]
# Update the cursor with the updated list
cursor.updateRow(m)
arcpy.RasterToPolyline_conversion(lujingshangge,line, "ZERO", "0", "SIMPLIFY", "cost")
if arcpy.Exists(alline) and arcpy.Exists(tmp): #判斷是否為第一次循環
arcpy.Delete_management(tmp)
arcpy.CopyFeatures_management(alline, tmp)
arcpy.Delete_management(alline)
arcpy.Merge_management([line, tmp], alline)
else:
arcpy.CopyFeatures_management(line, tmp)
arcpy.CopyFeatures_management(line, alline)
總結
以上是生活随笔為你收集整理的python封装工具类多个项目使用_【arcpy项目实战】将多个点两两生成的最短路径pyhon代码封装入script中...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 慧荣介绍新款 PCIe 5.0 SSD
- 下一篇: qq怎么删除收藏的表情包