fst77

How to access Route sublayer properties with ArcPy?

Discussion created by fst77 on Jul 2, 2013
Latest reply on Jul 4, 2013 by fst77
After solving a route I need to read the properties of the Route class. Concretely the Total_[Impedance] field as I want to compare different routes with regard to this attribute. Is there any way to do this with ArcPy?

My code until this step is typical:

route_lyr = arcpy.na.MakeRouteLayer(nwork,"BestRoute", "Length", output_path_shape="TRUE_LINES_WITH_MEASURES")
route_lyr = route_lyr.getOutput(0)
sub_layers = arcpy.na.GetNAClassNames(route_lyr)
arcpy.na.AddLocations("BestRoute",sub_layers["Stops"],"stops.shp")
arcpy.na.Solve(route_lyr)



Then I thought about the following to get the Total_Length value of the solve result:


for lyr in arcpy.mapping.ListLayers(route_lyr):
[INDENT]if lyr.name == "Routes":[/INDENT]
[INDENT][INDENT]print lyr.longName   ### Printed just for demonstration purposes[/INDENT][/INDENT]
[INDENT][INDENT]with arcpy.da.SearchCursor(lyr.longName, ['Total_Length']) as cursor:  [/INDENT][/INDENT]
[INDENT][INDENT][INDENT][INDENT]### "BestRoute\Routes" is passed. [/INDENT]
[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT][INDENT]### The error is thrown here[/INDENT][/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]for row in cursor:[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT][INDENT]cost = row[0][/INDENT][/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT][INDENT]print cost[/INDENT][/INDENT][/INDENT][/INDENT]



Which prints to standard output:


BestRoute\Routes
An error occurred on line XXX
cannot open 'BestRoute\Routes'



So "BestRoute\Routes" is the long name of the Routes layer but (apparently) not the input that arcpy.da.SearchCursor expects. Generic layer properties (longName, isBroken...) can be accessed with my code, but not those network-related.

I guess I'm missing the mechanism to access the network properties of the sublayer Routes that is stored in the composite layer...

Any help would be much appreciated.

[NOTE: Mistakenly, I posted this question in the Beta Programs forum before. Apologies]

Outcomes