Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a Python script that I'm working on. I have created a Closest Facility layer (in memory). I add facilities. I add incidents. I perform the Solve. These all complete. The only problem is, there doesn't appear to be a way to access any of the results.

I have gotten a describe object off the Network Analysis layer. I got the children of the network analysis layer. I can get the name of each child, but that is the extent. Each child is supposed to be a feature layer, but no layer operations work on any of them: "Error in executing tool". I can get the dataset object for each layer. Each dataset object calls itself a Feature Class. I cannot get any Feature Class operations to work on these "Feature Classes" either. I get the same stupid error.

The documentation on implementing Network Analysis work in Python is woefully incomplete.

How can I gain access to the results of a solve? I just need something I can feed into the arcpy.GetCount tool, nothing else.

share|improve this question

2 Answers 2

I'm not 100% sure I understand your question...is all you need the number of solved records for the various child layers, or are you looking to extract data such as travel time, etc.?

In any case, the following code snippet might help. It uses cursors to step through a Routes sublayer in a Network Analyst Route layer and extract field data and a count of all solved routes. The variable sCur is the cursor that searches through the routes layer, uRow is the cursor that updates another feature class's attribute table with the values gathered.

 # Get field value for travel time from Routes sublayer 

            #initialize a variable to hold the count
            recordCount = 0
            #create a search cursor
            sCur = arcpy.SearchCursor("Route\\Routes")

            for row in sCur:
                    TripTime = row.getValue("Total_TravelTime")
                    EndTime = row.getValue("EndTime")
                    #print EndTime

            # Set field value of travel time in origin feature table.
            uRow.setValue("Trip_A_Time850", TripTime)
            uRow.setValue("Trip_A_EndTime850", EndTime)
            # Update the row.
            # move cursor to next record.
            uRow = uCur.next()
            recordCount += 1
            #(used for diagnostics): print "recordCount: ", recordCount
            x += 1

A couple of reading links (please don't hit me if you've been over these a million times already):

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Closest_facility_analysis/00470000004n000000/ (the list of all closest facility layer field names).

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001q000000 (description of cursors).

Hope this helps,


share|improve this answer
It worked for me in 9.3 for Closest Facility. However one has to expand for with row = sCur.next() and while row:. Otherwise there is an error TypeError: 'geoprocessing cursor object' object is not iterable. –  mlt May 23 '13 at 23:21

The answer to my question is that when the Solve is executed, an in-memory layer named "Routes" is created. To get the count of the number of features, you simply do this:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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