AnsweredAssumed Answered

Network Analyst Field Mapping with arcpy- How to carry fields from origins and destinations to lines sublayer?

Question asked by LCremin on Dec 16, 2016
Latest reply on Jan 9, 2017 by LCremin

Hi- I am fairly new to Network Analyst, and have a question about using field mapping for network analyst layers. 

I am using a python script (with, running on Desktop 10.4/10.5

I am trying to use field mappings to carry certain fields (for IDs and attributes) from input destinations and origins features to the lines layer. I am doing this to retain the IDs and to avoid a join step. 

I have figured out how to map these fields into the destinations sublayer (want SID and VALUE fields) and the origins sublayer (want BID field). 

None of these fields, however, are carried on after the solve step, and any field mapping I tried with the lines layer didn't work (inputs valid only for layers that exist before the solve). 

Is there a way to select which fields in the destinations and origins layers get carried on after the solve, and ultimately appear in the lines sublayer?


Thank you for any information (or corrections!)- I'm not quite sure what I'm missing here, if it's possible, or if there's a different approach. My code is below along with a screenshot of the fields I'm trying to transfer. 




# Process: Make OD Cost Matrix Layer
OD_matrix = "ODMatrix"
outNA_layer =, OD_matrix, cost) #, "Driving Time", "", "", "", "", "NO_LINES")
layer_object = outNA_layer.getOutput(0)


#Process: Add Destinations #Works to add and map SID and VALUE fields to destinations sublayer
field_name = "VALUE"
field_type = "FLOAT", destinations_layer_name, field_name, field_type), destinations_layer_name, "SID", "TEXT")

field_mappings =, destinations_layer_name)
field_mappings["VALUE"].mappedFieldName = "VALUE"
field_mappings["SID"].mappedFieldName = "Name", destinations_layer_name, stores, field_mappings) 


#Process: Add Origins  #Works to add and map BID fields to origins sublayer, origins_layer_name, "BID", "SHORT")
field_mappings =, origins_layer_name)
field_mappings["BID"].mappedFieldName = "BID", origins_layer_name, origins, field_mappings) 


#Are there any field mappings options for lines before the solve? Lines table only has fields FID, Shape#, Name, OriginID, DestinationID, and Total_Minutes. Want SID, VALUE, and BID to appear.

# Process: Solve, lineslayer_name, "SID", "TEXT")
#field_mappings =, lineslayer_name) ##Does not work. Tried from inputs directly and from destination and origin sublayers
#field_mappings["SID"].mappedFieldName = "SID"

solvestart = time.time(), "SKIP", "TERMINATE")
arcpy.AddMessage("Matrix solved: {} s".format(time.time()-solvestart))

subLayers = {} 
for layer in arcpy.mapping.ListLayers(layer_object)[1:]: 
   subLayers[layer.datasetName] = layer 
linesLayer = subLayers["ODLines"] 
arcpy.SaveToLayerFile_management(layer_object, "LayerOutput", lineslayer_name )


Origins, Destinations, and Lines layer fields- how to transfer between?


Matt Beyers