<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Network Analyst Field Mapping with arcpy- How to carry fields from origins and destinations to lines sublayer? in ArcGIS Network Analyst Questions</title>
    <link>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599842#M5770</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi- I am fairly new to Network Analyst, and have a question about using field mapping for network analyst layers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using a python script (with arcpy.na), running on Desktop 10.4/10.5&lt;/P&gt;&lt;P&gt;I am trying to use field mappings to carry certain fields (for IDs and attributes) from input destinations and origins features to&amp;nbsp;the lines layer. I am doing this to retain the IDs&amp;nbsp;and to avoid a join step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;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).&amp;nbsp;&lt;/P&gt;&lt;P&gt;None of these fields, however, are carried on after the solve step, and any&amp;nbsp;field mapping I tried with the lines layer didn't work (inputs valid only for layers that exist before the solve).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;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?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Laura&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Make OD Cost Matrix Layer&lt;BR /&gt; OD_matrix = "ODMatrix"&lt;BR /&gt; outNA_layer = arcpy.na.MakeODCostMatrixLayer(streets, OD_matrix, cost) #, "Driving Time", "", "", "", "", "NO_LINES")&lt;BR /&gt; layer_object = outNA_layer.getOutput(0)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Process: Add Destinations &lt;STRONG&gt;#Works to add and map SID and VALUE fields to destinations sublayer&lt;/STRONG&gt;&lt;BR /&gt;field_name = "VALUE"&lt;BR /&gt; field_type = "FLOAT"&lt;BR /&gt; arcpy.na.AddFieldToAnalysisLayer(layer_object, destinations_layer_name, field_name, field_type)&lt;BR /&gt; arcpy.na.AddFieldToAnalysisLayer(layer_object, destinations_layer_name, "SID", "TEXT")&lt;/P&gt;&lt;P&gt;field_mappings = arcpy.na.NAClassFieldMappings(layer_object, destinations_layer_name)&lt;BR /&gt; field_mappings["VALUE"].mappedFieldName = "VALUE"&lt;BR /&gt; field_mappings["SID"].mappedFieldName = "Name"&lt;BR /&gt;arcpy.na.AddLocations(layer_object, destinations_layer_name, stores, field_mappings)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Process: Add Origins &amp;nbsp;&lt;STRONG&gt;#Works to add and map BID fields to origins sublayer&lt;/STRONG&gt;&lt;BR /&gt; arcpy.na.AddFieldToAnalysisLayer(layer_object, origins_layer_name, "BID", "SHORT")&lt;BR /&gt; field_mappings = arcpy.na.NAClassFieldMappings(layer_object, origins_layer_name)&lt;BR /&gt; field_mappings["BID"].mappedFieldName = "BID"&lt;BR /&gt; arcpy.na.AddLocations(layer_object, origins_layer_name, origins, field_mappings)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#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.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;# Process: Solve&lt;/P&gt;&lt;P&gt;#arcpy.na.AddFieldToAnalysisLayer(layer_object, lineslayer_name, "SID", "TEXT")&lt;BR /&gt; #field_mappings = arcpy.na.NAClassFieldMappings(layer_object, lineslayer_name) ##Does not work. Tried from inputs directly and from destination and origin sublayers&lt;BR /&gt; #field_mappings["SID"].mappedFieldName = "SID"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; solvestart = time.time()&lt;BR /&gt; arcpy.na.Solve(layer_object, "SKIP", "TERMINATE")&lt;BR /&gt; arcpy.AddMessage("Matrix solved: {} s".format(time.time()-solvestart))&lt;/P&gt;&lt;P&gt;subLayers = {}&amp;nbsp;&lt;BR /&gt; for layer in arcpy.mapping.ListLayers(layer_object)[1:]:&amp;nbsp;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;subLayers[layer.datasetName] = layer&amp;nbsp;&lt;BR /&gt; linesLayer = subLayers["ODLines"]&amp;nbsp;&lt;BR /&gt;arcpy.SaveToLayerFile_management(layer_object, "LayerOutput"&amp;nbsp;&lt;BR /&gt; arcpy.management.CopyFeatures(linesLayer, lineslayer_name )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Origins, Destinations, and Lines layer fields- how to transfer between?" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/285074_Untitled.png" style="width: 620px; height: 361px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/54213"&gt;Matt Beyers&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 16 Dec 2016 20:01:05 GMT</pubDate>
    <dc:creator>LauraCremin</dc:creator>
    <dc:date>2016-12-16T20:01:05Z</dc:date>
    <item>
      <title>Network Analyst Field Mapping with arcpy- How to carry fields from origins and destinations to lines sublayer?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599842#M5770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi- I am fairly new to Network Analyst, and have a question about using field mapping for network analyst layers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using a python script (with arcpy.na), running on Desktop 10.4/10.5&lt;/P&gt;&lt;P&gt;I am trying to use field mappings to carry certain fields (for IDs and attributes) from input destinations and origins features to&amp;nbsp;the lines layer. I am doing this to retain the IDs&amp;nbsp;and to avoid a join step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;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).&amp;nbsp;&lt;/P&gt;&lt;P&gt;None of these fields, however, are carried on after the solve step, and any&amp;nbsp;field mapping I tried with the lines layer didn't work (inputs valid only for layers that exist before the solve).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;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?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Laura&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Make OD Cost Matrix Layer&lt;BR /&gt; OD_matrix = "ODMatrix"&lt;BR /&gt; outNA_layer = arcpy.na.MakeODCostMatrixLayer(streets, OD_matrix, cost) #, "Driving Time", "", "", "", "", "NO_LINES")&lt;BR /&gt; layer_object = outNA_layer.getOutput(0)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Process: Add Destinations &lt;STRONG&gt;#Works to add and map SID and VALUE fields to destinations sublayer&lt;/STRONG&gt;&lt;BR /&gt;field_name = "VALUE"&lt;BR /&gt; field_type = "FLOAT"&lt;BR /&gt; arcpy.na.AddFieldToAnalysisLayer(layer_object, destinations_layer_name, field_name, field_type)&lt;BR /&gt; arcpy.na.AddFieldToAnalysisLayer(layer_object, destinations_layer_name, "SID", "TEXT")&lt;/P&gt;&lt;P&gt;field_mappings = arcpy.na.NAClassFieldMappings(layer_object, destinations_layer_name)&lt;BR /&gt; field_mappings["VALUE"].mappedFieldName = "VALUE"&lt;BR /&gt; field_mappings["SID"].mappedFieldName = "Name"&lt;BR /&gt;arcpy.na.AddLocations(layer_object, destinations_layer_name, stores, field_mappings)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Process: Add Origins &amp;nbsp;&lt;STRONG&gt;#Works to add and map BID fields to origins sublayer&lt;/STRONG&gt;&lt;BR /&gt; arcpy.na.AddFieldToAnalysisLayer(layer_object, origins_layer_name, "BID", "SHORT")&lt;BR /&gt; field_mappings = arcpy.na.NAClassFieldMappings(layer_object, origins_layer_name)&lt;BR /&gt; field_mappings["BID"].mappedFieldName = "BID"&lt;BR /&gt; arcpy.na.AddLocations(layer_object, origins_layer_name, origins, field_mappings)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#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.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;# Process: Solve&lt;/P&gt;&lt;P&gt;#arcpy.na.AddFieldToAnalysisLayer(layer_object, lineslayer_name, "SID", "TEXT")&lt;BR /&gt; #field_mappings = arcpy.na.NAClassFieldMappings(layer_object, lineslayer_name) ##Does not work. Tried from inputs directly and from destination and origin sublayers&lt;BR /&gt; #field_mappings["SID"].mappedFieldName = "SID"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; solvestart = time.time()&lt;BR /&gt; arcpy.na.Solve(layer_object, "SKIP", "TERMINATE")&lt;BR /&gt; arcpy.AddMessage("Matrix solved: {} s".format(time.time()-solvestart))&lt;/P&gt;&lt;P&gt;subLayers = {}&amp;nbsp;&lt;BR /&gt; for layer in arcpy.mapping.ListLayers(layer_object)[1:]:&amp;nbsp;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;subLayers[layer.datasetName] = layer&amp;nbsp;&lt;BR /&gt; linesLayer = subLayers["ODLines"]&amp;nbsp;&lt;BR /&gt;arcpy.SaveToLayerFile_management(layer_object, "LayerOutput"&amp;nbsp;&lt;BR /&gt; arcpy.management.CopyFeatures(linesLayer, lineslayer_name )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Origins, Destinations, and Lines layer fields- how to transfer between?" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/285074_Untitled.png" style="width: 620px; height: 361px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/54213"&gt;Matt Beyers&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Dec 2016 20:01:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599842#M5770</guid>
      <dc:creator>LauraCremin</dc:creator>
      <dc:date>2016-12-16T20:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Network Analyst Field Mapping with arcpy- How to carry fields from origins and destinations to lines sublayer?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599843#M5771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Moved to the &lt;A href="https://community.esri.com/community/gis/analysis/network-analyst?sr=search&amp;amp;searchId=0c554793-8ecc-4194-96e4-38fd871c1583&amp;amp;searchIndex=0"&gt;https://community.esri.com/community/gis/analysis/network-analyst?sr=search&amp;amp;searchId=0c554793-8ecc-4194-96e4-38fd871c1583&amp;amp;searchIndex=0&lt;/A&gt;‌ place to increase your chances of getting an answer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Jan 2017 03:06:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599843#M5771</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-01-07T03:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Network Analyst Field Mapping with arcpy- How to carry fields from origins and destinations to lines sublayer?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599844#M5772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank&amp;nbsp;you!&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Jan 2017 21:46:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599844#M5772</guid>
      <dc:creator>LauraCremin</dc:creator>
      <dc:date>2017-01-07T21:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Network Analyst Field Mapping with arcpy- How to carry fields from origins and destinations to lines sublayer?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599845#M5773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately, no, there is no way to automatically carry over fields from the input into the output Lines sublayer. &amp;nbsp;You have to use a join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The last code sample on the Make OD Cost Matrix Layer documentation page gives an example of doing something very similar to this, using joins:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/tools/network-analyst-toolbox/make-od-cost-matrix-layer.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/network-analyst-toolbox/make-od-cost-matrix-layer.htm"&gt;Make OD Cost Matrix Layer—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jan 2017 16:10:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599845#M5773</guid>
      <dc:creator>MelindaMorang</dc:creator>
      <dc:date>2017-01-09T16:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Network Analyst Field Mapping with arcpy- How to carry fields from origins and destinations to lines sublayer?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599846#M5774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the notes and pointing out the example! Looks like there's no way to avoid the join, which for some reason is running very slowly (although I may try an update cursor with dictionaries and compare times).&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jan 2017 16:26:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/network-analyst-field-mapping-with-arcpy-how-to/m-p/599846#M5774</guid>
      <dc:creator>LauraCremin</dc:creator>
      <dc:date>2017-01-09T16:26:10Z</dc:date>
    </item>
  </channel>
</rss>

