Python 网络分析员回路错误(ArcGIS 9.3)

Python 网络分析员回路错误(ArcGIS 9.3),python,networking,Python,Networking,我正在使用NetworkAnalyst的MakeServiceAreaLayer工具进行循环,但它不起作用。 我想做3个不同的服务区,3个不同的点,每个点匹配一个设施。设施是作为新网络位置源的要素类或图层。这些点被称为“盔甲”、“布格奈斯”和“唱诗班”。 我的阻抗属性是“分钟数” 这是我的代码: import arcgisscripting gp = arcgisscripting.create() gp.CheckOutExtension("Network") gp.AddToolbox("C

我正在使用NetworkAnalyst的MakeServiceAreaLayer工具进行循环,但它不起作用。 我想做3个不同的服务区,3个不同的点,每个点匹配一个设施。设施是作为新网络位置源的要素类或图层。这些点被称为“盔甲”、“布格奈斯”和“唱诗班”。 我的阻抗属性是“分钟数”

这是我的代码:

import arcgisscripting
gp = arcgisscripting.create()
gp.CheckOutExtension("Network")
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Network Analyst Tools.tbx")
network = "D:/Travaux/NantesMetropole/Traitements/SIG_Final/Modelisation/voiture/Reseau_Voiture_TOP_ND.nd" 
Armor = "D:/Travaux/NantesMetropole/Traitements/SIG_Final/pts_kml/Pt_Ar.shp"
Bouguenais = "D:/Travaux/NantesMetropole/Traitements/SIG_Final/pts_kml/Pt_Boug.shp"
Chantrerie = "D:/Travaux/NantesMetropole/Traitements/SIG_Final/pts_kml/Pt_Chanr.shp"

facilities_points = ["Armor", "Bouguenais", "Chantrerie"]
while 1:
    for i in facilities_points:
        try:
            gp.MakeServiceAreaLayer_na (network, "Service Area_" + i, "Minutes_S1", "TRAVEL_FROM", "10 20 30 40 50", "SIMPLE_POLYS", "MERGE", "DISKS", "NO_LINES", "OVERLAP", "NO_SPLIT", "", "", "ALLOW_UTURNS", "", "TRIM_POLYS", "200 Meters", "NO_LINES_SOURCE_FIELDS")
            gp.AddLocations_na("Service Area_" + i, "Facilities_" + i, i, "", "100 Meters")
            gp.Solve_na ("Service Area_" + i, "HALT")
            gp.CopyFeatures_management("Service Area_" + i + "/Polygons", "D:/Travaux/NantesMetropole/Traitements/SIG_Final/Modelisation/voiture/test_" + i +".shp")
            print "Minutes_S1 done on", i
        except:
             print "Error on", i
    break
实际上,“gp.AddLocations\u na”行上已经出现了一个错误:


我查看了ESRI帮助,但仍然不知道如何解决问题。你能帮我吗?

你说gp.AddLocations\u na是导致问题的原因,但从你的代码中看不出来。若要调试,请将raise语句添加到except块。这将告诉您是哪一行导致了错误。当你解决了这些问题时,你可以随时移除它

看来我是唯一的罪犯。当它可能应该是要素类变量时,您将它作为字符串传递。您可以使用字典来存储名称和变量

#store table/feature class names with the variables
facilities_points = {"Armor":Armor, "Bouguenais":Bouguenais, "Chantrerie":Chantrerie}

#note the while loop is superfluous here
while 1:
    for i in facilities_points:
        try:
            gp.MakeServiceAreaLayer_na (network, "Service Area_" + i, "Minutes_S1", "TRAVEL_FROM", "10 20 30 40 50", "SIMPLE_POLYS", "MERGE", "DISKS", "NO_LINES", "OVERLAP", "NO_SPLIT", "", "", "ALLOW_UTURNS", "", "TRIM_POLYS", "200 Meters", "NO_LINES_SOURCE_FIELDS")
            gp.AddLocations_na("Service Area_" + i, "Facilities_" + i, facilities_points[i], "", "100 Meters")
            gp.Solve_na ("Service Area_" + i, "HALT")
            gp.CopyFeatures_management("Service Area_" + i + "/Polygons", "D:/Travaux/NantesMetropole/Traitements/SIG_Final/Modelisation/voiture/test_" + i +".shp")
            print "Minutes_S1 done on", i
        except:
            #this error message tells you nothing about what really happened
            print "Error on", i

            #Raise the full exception to assist with debugging
            #comment it out once the script works
            raise
    break 

另外,尽管错误处理是一个好习惯,但在我看来,它对这种类型的脚本编写很少有帮助。除非您愿意接受失败的地理处理函数调用并继续,否则最好让脚本停止并返回发生错误的位置。但是,如果您实现了日志记录以捕获回溯,并将其作为计划任务运行,则except块将是放置日志消息的位置。

Hi Tharen!我刚刚试过你的代码,它非常有效!非常感谢你的帮助!很高兴来到这里。因为你是新来的SE退房。对于GIS和Python相关的问题,这里有很多很好的帮助。此外,接受答案也很有帮助,因为这有助于会员获得积分和特权。
#store table/feature class names with the variables
facilities_points = {"Armor":Armor, "Bouguenais":Bouguenais, "Chantrerie":Chantrerie}

#note the while loop is superfluous here
while 1:
    for i in facilities_points:
        try:
            gp.MakeServiceAreaLayer_na (network, "Service Area_" + i, "Minutes_S1", "TRAVEL_FROM", "10 20 30 40 50", "SIMPLE_POLYS", "MERGE", "DISKS", "NO_LINES", "OVERLAP", "NO_SPLIT", "", "", "ALLOW_UTURNS", "", "TRIM_POLYS", "200 Meters", "NO_LINES_SOURCE_FIELDS")
            gp.AddLocations_na("Service Area_" + i, "Facilities_" + i, facilities_points[i], "", "100 Meters")
            gp.Solve_na ("Service Area_" + i, "HALT")
            gp.CopyFeatures_management("Service Area_" + i + "/Polygons", "D:/Travaux/NantesMetropole/Traitements/SIG_Final/Modelisation/voiture/test_" + i +".shp")
            print "Minutes_S1 done on", i
        except:
            #this error message tells you nothing about what really happened
            print "Error on", i

            #Raise the full exception to assist with debugging
            #comment it out once the script works
            raise
    break