1

I have a script in Python that solves a really simple route analysis problem (optimal way for given stops). I've found in the documentation that one can assign a start date for the analysis and get time information associated with its output layer. If everything is done through the ArcMap interface then the information is shown in a separate window. Unfortunately I've not been able to access this information in my script (using debugger) and the output layer doesn't seem to have that information, so I guess it needs to be extracted somehow.

Does anyone know how to do that?

6
  • do you have a network dataset that is time enabled (Traffic tab in the Network Dataset Properties window)? Jun 8, 2014 at 21:23
  • @AlexTereshenkov I'm not sure, how can I check that?
    – Michal
    Jun 8, 2014 at 21:43
  • @AlexTereshenkov I don't have that tab, on my ND I'm getting General, Source, Display and Symbology. If I bring up nd source layer properties I'm getting more, however still no traffic, instead I have a time tab with "Enable time on this layer" checkbox, which is not selected.
    – Michal
    Jun 8, 2014 at 22:06
  • You are looking at the Layer Properties. Right-click the network dataset in Catalog and choose Properties. Read Help on how to enable Traffic data (if you need it). Without traffic, you will always get the same speed for a road link regardless what time you are driving. It does not influence the process of route solving if you just want to keep the travel time in the output route feature though. Jun 8, 2014 at 22:11
  • @AlexTereshenkov OK, I'm starting to understand what's going on. My ND doesn't have the traffic information. Can I calculate the end time solely on speed limits from my ND? It calculates correctly if I generate route analysis in ArcMap and then use Directions.
    – Michal
    Jun 8, 2014 at 22:16

1 Answer 1

1

In order to be able to take advantage of the Start date time, you need to have the Traffic data enabled for the network dataset (to use Speed Profiles of TomTom/Navteq for instance).

To read more about Traffic data in Network Analyst. More info on na module in arcpy (some of which is used here).

Here is the code I use for getting the route exported to a new feature class after solving the route:

def solveroute():
    #Set up the environment
    arcpy.CheckOutExtension("network")

    #Set up variables
    networkDataset = r"C:\Program Files (x86)\ArcGIS\ArcTutor\Network Analyst\Tutorial\SanFrancisco.gdb\Transportation\Streets_ND"
    stops = r"C:\GIS\Temp\test.gdb\StopsSandiego"
    fastestRoute = r"C:\GIS\Temp\test.gdb\TimedRoute"

    #Make a new route layer using travel time as impedance to determine fastest route
    routeLayer = arcpy.na.MakeRouteLayer(networkDataset, "StopsRoute",
                                         "Minutes",accumulate_attribute_name=["TravelTime","Meters"],start_date_time="12/30/1899").getOutput(0)
    #Get the network analysis class names from the route layer
    naClasses = arcpy.na.GetNAClassNames(routeLayer)
    #Get the routes sublayer from the route layer
    routesSublayer = arcpy.mapping.ListLayers(routeLayer, naClasses["Routes"])[0]
    #Load stops
    arcpy.na.AddLocations(routeLayer, naClasses["Stops"], stops)
    #Solve the route layer
    arcpy.na.Solve(routeLayer)
    #Copy the route as a feature class
    if arcpy.Exists(fastestRoute):
        arcpy.Delete_management(fastestRoute)
    #print int(arcpy.GetCount_management(routesSublayer).getOutput(0))
    arcpy.management.CopyFeatures(routesSublayer, fastestRoute)

solveroute()

This gives me a route feature (Polyline M) saved to the disk with all the relevant attributes (including start/end time):

enter image description here

2
  • If I run your script adjusted for my data I'm getting this error: ERROR 030034: TravelTime is not a valid member of the domain.
    – Michal
    Jun 8, 2014 at 22:03
  • Please get back to the Help page of the tool to learn more about the parameters then. "TravelTime" is the attribute name used for the cost; it can vary from one network dataset to another. Check Python code samples for the tool. Jun 8, 2014 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.