Arcpy - 将 NA 图层保存到特征 class
Arcpy - Save NA layer to feature class
我正在将一些旧工具和模型从 9.3 更新到 10.3,并且 运行 在尝试从网络分析层保存特定层时遇到问题。
下面是我的脚本的副本及其生成的错误:
arcpy.CheckOutExtension("Network")
arcpy.env.workspace = r"C:\aaa\response profile\test.gdb"
inNetworkDataset = "J:\projects\netmodels\roadnetwork\Vic_HERE_2014_Q2\Data\HERE_COREMAP.gdb\RoutingApplication\RoutingApplication_ND"
outNALayerName = "StationOfInterest"
allFacilities = r"C:\aaa\response profile\RMN.gdb\RNM_Statewide_Fire_Stations"
facilitiesQuery = "not occ_type = 'future fire station' and label in ('Springvale')"
arcpy.MakeFeatureLayer_management(allFacilities,"inFacilities", facilitiesQuery)
outLayerFile = r"C:\aaa\response profile" + "\" + outNALayerName + ".lyr"
timeBreaks = 30
print "varibles set"
SA_result_object = arcpy.na.MakeServiceAreaLayer(inNetworkDataset, outNALayerName,
"EmergencyServicesTime", "TRAVEL_FROM", timeBreaks,
"NO_POLYS", "NO_MERGE", "RINGS", "TRUE_LINES")
print "Service Area layer created"
#Get the layer object from the result object. The service layer can now be
#referenced using the layer object.
SA_layer_object = SA_result_object.getOutput(0)
#Get the names of all the sublayers within the service area layer.
SAClassesIn = arcpy.na.GetNAClassNames(SA_layer_object,"INPUT")
SAClassesOut = arcpy.na.GetNAClassNames(SA_layer_object,"OUTPUT")
#Stores the layer names to use later
facilitiesLayerName = SAClassesIn["Facilities"]
print "facilitiesLayerName: " + facilitiesLayerName
linesLayerName = SAClassesOut["SALines"]
print "linesLayerName: " + linesLayerName
arcpy.na.AddLocations(SA_layer_object , SAClassesIn["Facilities"], "inFacilities")
print "added locations to layer"
print "solving...."
arcpy.na.Solve(SA_layer_object )
print"solved"
********** these are the lines that is causing me issues **********
linesSublayer = SA_layer_object.listLayers(SAClassesOut["Lines"])[0]
arcpy.CopyFeatures_management(linesSublayer,"StationOfInterestLines")
我得到的错误是:
linesSublayer = SA_layer_object.listLayers(SAClassesOut["Lines"])[0]
AttributeError: 'Layer' object has no attribute 'listLayers'
知道是什么原因造成的,我正在努力解决它。
谢谢
Read over the ListLayers documentation -- 它调用 MXD 作为参数,而不是用作 Layer 对象的属性。
语法:
ListLayers (map_document_or_layer, {wildcard}, {data_frame})
所以您可能想要以下内容:
linesSublayer = arcpy.mapping.ListLayers(SA_layer_object, "Lines")[0]
我正在将一些旧工具和模型从 9.3 更新到 10.3,并且 运行 在尝试从网络分析层保存特定层时遇到问题。
下面是我的脚本的副本及其生成的错误:
arcpy.CheckOutExtension("Network")
arcpy.env.workspace = r"C:\aaa\response profile\test.gdb"
inNetworkDataset = "J:\projects\netmodels\roadnetwork\Vic_HERE_2014_Q2\Data\HERE_COREMAP.gdb\RoutingApplication\RoutingApplication_ND"
outNALayerName = "StationOfInterest"
allFacilities = r"C:\aaa\response profile\RMN.gdb\RNM_Statewide_Fire_Stations"
facilitiesQuery = "not occ_type = 'future fire station' and label in ('Springvale')"
arcpy.MakeFeatureLayer_management(allFacilities,"inFacilities", facilitiesQuery)
outLayerFile = r"C:\aaa\response profile" + "\" + outNALayerName + ".lyr"
timeBreaks = 30
print "varibles set"
SA_result_object = arcpy.na.MakeServiceAreaLayer(inNetworkDataset, outNALayerName,
"EmergencyServicesTime", "TRAVEL_FROM", timeBreaks,
"NO_POLYS", "NO_MERGE", "RINGS", "TRUE_LINES")
print "Service Area layer created"
#Get the layer object from the result object. The service layer can now be
#referenced using the layer object.
SA_layer_object = SA_result_object.getOutput(0)
#Get the names of all the sublayers within the service area layer.
SAClassesIn = arcpy.na.GetNAClassNames(SA_layer_object,"INPUT")
SAClassesOut = arcpy.na.GetNAClassNames(SA_layer_object,"OUTPUT")
#Stores the layer names to use later
facilitiesLayerName = SAClassesIn["Facilities"]
print "facilitiesLayerName: " + facilitiesLayerName
linesLayerName = SAClassesOut["SALines"]
print "linesLayerName: " + linesLayerName
arcpy.na.AddLocations(SA_layer_object , SAClassesIn["Facilities"], "inFacilities")
print "added locations to layer"
print "solving...."
arcpy.na.Solve(SA_layer_object )
print"solved"
********** these are the lines that is causing me issues **********
linesSublayer = SA_layer_object.listLayers(SAClassesOut["Lines"])[0]
arcpy.CopyFeatures_management(linesSublayer,"StationOfInterestLines")
我得到的错误是:
linesSublayer = SA_layer_object.listLayers(SAClassesOut["Lines"])[0]
AttributeError: 'Layer' object has no attribute 'listLayers'
知道是什么原因造成的,我正在努力解决它。 谢谢
Read over the ListLayers documentation -- 它调用 MXD 作为参数,而不是用作 Layer 对象的属性。
语法:
ListLayers (map_document_or_layer, {wildcard}, {data_frame})
所以您可能想要以下内容:
linesSublayer = arcpy.mapping.ListLayers(SA_layer_object, "Lines")[0]