avatar
f*c
1
我有美国road shape file和全美500个城市的longtitude and latitude。
现在需要计算每对城市之间的road distance.
我从网上找的办法是用python写code,可是总是出错。
各位大神帮忙看一下 。由于没有时间变量,所以里面关于时间的我都给省去了
import arcpy, os, sys
arcpy.env.overwriteOutput = True
try:
# costDic1 = {}
f = open(r"C:UsersUserDocumentsArcGISindia.txt", 'r+')
layer1 = "Route" #an open in-memory layer

for line in f:
twoPs = line.split(",")

# if the line contains number
if twoPs[0].isdigit():
OPoint = arcpy.Point()
DPoint = arcpy.Point()
pointGeometryList = []

OPoint.X = twoPs[1]
OPoint.Y = twoPs[2]
DPoint.X = twoPs[3]
DPoint.Y = twoPs[4]
pointGeometry = arcpy.PointGeometry(OPoint)
pointGeometryList.append(pointGeometry)
pointGeometry = arcpy.PointGeometry(DPoint)
pointGeometryList.append(pointGeometry)
myPoints = "Mypoints"
arcpy.CopyFeatures_management(pointGeometryList, myPoints)
arcpy.na.AddLocations(layer1,"Stops",myPoints)
arcpy.Solve_na(layer1)

# get the cost info from the layer
# rows = arcpy.SearchCursor(lyrName + "\Routes")
# for row in rows:
# costDic1[twoPs[0]] = row.Total_TravelTime

# delete stops and route from the layer
arcpy.DeleteRows_management(lyrName + "\Stops")
arcpy.DeleteRows_management(lyrName + "\Routes")
f.close

# Output the result to a txt file
fOut = open(r"C:UsersUserDocumentsArcGISOut.txt", 'w')
# for costKey in costDic1.keys():
# line = str(costKey) + "," + str(costDic1[costKey])
# fOut.writelines(line)
fOut.close
except:
print "NO RESULTS"
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。