统计
  • 文章总数:662 篇
  • 评论总数:0 条
  • 分类总数:13 个
  • 最后更新:2月17日

arcpy-将阻力栅格上的53各点两两相连,算出各两点间的最小路径

本文阅读 2 分钟
首页 ArcGIS 正文

请输入图片描述

【需求】将阻力栅格上面的53个点两两相连,求出他们两点间的最小距离

【解决初步思路】利用arcgis中的最小距离函数计算每两点间的最小阻力值,将生成栅格路径转化为矢量路径,将矢量路径进行链接,累加得到所有路径的合并路径

代码:

import os

import arcpy

arcpy.env.workspace="A:\\360data\\重要数据\\我的文档\\ArcGIS\\Packages\\最小树\\v101\\cost.gdb"#工作空间

shp="A:\\360data\\重要数据\\我的文档\\ArcGIS\\Packages\\最小树\\v101\\cost.gdb\\shi"

out_path="A:\\360data\\重要数据\\我的文档\\ArcGIS\\Packages\\最小树\\v101\\"

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:

cost = "cost"

te_po1 = "te_po1"

te_po2 = "te_po2"

julishange = "julishange"+shit[1]+"f"+row[1]+"t"

huisushange = "huisushange"+shit[1]+"f"+row[1]+"t"

lujingshangge = "lujingshangge"+shit[1]+"f"+row[1]+"t"

alline="alline"

tmp="tmp"

line="line"+shit[1]+"f"+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.DeleteFeatures_management(tmp)

arcpy.CopyFeatures_management(alline, tmp)

arcpy.DeleteFeatures_management(alline)

arcpy.Merge_management([line, tmp],alline)

最后实现将所有的最短路径合并。如果有机会将利用arcpy的相关工具制作一下add-in插件,使使用者用起来更加便捷。

本文来自投稿,不代表本站立场,如若转载,请注明出处:
ACDSee软件最常用的使用功能简介
« 上一篇 03-25
wps里ppt演讲者模式添加备注不投屏的方法
下一篇 » 03-25

作者信息

作者有点忙,还没写简介
TA的最新作品
    请设置要调用的作者ID

动态快讯

    请配置好页面缩略名选项

热门文章

标签TAG

没有任何标签