<?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 Re: Network Analyst - Pyhton export sublayers to a FeatureClass, each one. in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/network-analyst-pyhton-export-sublayers-to-a/m-p/507751#M16893</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/save-to-layer-file.htm" title="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/save-to-layer-file.htm"&gt;Save To Layer File—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/copy-features.htm" title="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/copy-features.htm"&gt;Copy Features—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only reason I as is that most of the NA arcpy code and function examples use it ... for example&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-network-analyst/routesolverproperties.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-network-analyst/routesolverproperties.htm"&gt;RouteSolverProperties—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 16 Jan 2016 02:41:08 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-01-16T02:41:08Z</dc:date>
    <item>
      <title>Network Analyst - Pyhton export sublayers to a FeatureClass, each one.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/network-analyst-pyhton-export-sublayers-to-a/m-p/507750#M16892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is my problem: How I can export to a feature class my sublayer Routes from outNALayer.&lt;/P&gt;&lt;P&gt;I been able to export just the tabular data but NOT the geometry. Down below is the code or part of the script.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Create a Closest Facility Layer. Optimize on Travel Time but&amp;nbsp; compute the distance traveled by accumulating the meters attribute.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outRouteResultObject = arcpy.na.MakeClosestFacilityLayer(Transportation_ND, "Closest_Facility", "Miles", "TRAVEL_TO", "", "1", "Miles", "ALLOW_UTURNS", "Oneway", "NO_HIERARCHY", "", "NO_LINES", "", "NOT_USED")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Creating Closest Facility Layer"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the layer object from the result object. The route layer can now be referenced using the layer object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outNALayer = outRouteResultObject.getOutput(0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "outNALayer : " + str(outNALayer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the names of all sublayers within the route layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; subLayerNames = arcpy.na.GetNAClassNames(outNALayer)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "subLayerNames : " + str(subLayerNames)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Store the layer names that we will use later - Facilities&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; facilityLayerName = subLayerNames["Facilities"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "facilityLayerName : " + str(facilityLayerName)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Store the layer names that we will use later - incidents&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; incidentsLayerName = subLayerNames["Incidents"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "incidentsLayerName : " + str(incidentsLayerName)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Store the layer names that we will use later&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; routeLayerName = subLayerNames["CFRoutes"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "routeLayerName : " + str(routeLayerName)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Add destination points.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.na.AddLocations(outRouteResultObject, facilityLayerName, Facilities, "", "1000 Meters", "", "test_area SHAPE;Transportation_ND_Junctions NONE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE", "test_area #;Transportation_ND_Junctions #")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Adding Faclitities to the Closest Facility layer"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Add Origin points.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddLocations_na(outRouteResultObject, incidentsLayerName, Incidents, "", "1000 Meters", "", "test_area SHAPE;Transportation_ND_Junctions NONE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE", "test_area #;Transportation_ND_Junctions #")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Adding Incidents to the Closest Facilty layer"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Solve&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.na.Solve(outNALayer, "SKIP", "TERMINATE", "")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Solving the Problem"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RoutesSubLayer = arcpy.mapping.ListLayers(outNALayer,routeLayerName)[0]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Selected sublayer : " + str(RoutesSubLayer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.FeatureClassToFeatureClass_conversion(RoutesSubLayer, network)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Jan 2016 00:08:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/network-analyst-pyhton-export-sublayers-to-a/m-p/507750#M16892</guid>
      <dc:creator>Jose_LuisGarcinuno-Oporto</dc:creator>
      <dc:date>2016-01-16T00:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Network Analyst - Pyhton export sublayers to a FeatureClass, each one.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/network-analyst-pyhton-export-sublayers-to-a/m-p/507751#M16893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/save-to-layer-file.htm" title="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/save-to-layer-file.htm"&gt;Save To Layer File—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/copy-features.htm" title="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/copy-features.htm"&gt;Copy Features—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only reason I as is that most of the NA arcpy code and function examples use it ... for example&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-network-analyst/routesolverproperties.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-network-analyst/routesolverproperties.htm"&gt;RouteSolverProperties—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Jan 2016 02:41:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/network-analyst-pyhton-export-sublayers-to-a/m-p/507751#M16893</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-01-16T02:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: Network Analyst - Pyhton export sublayers to a FeatureClass, each one.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/network-analyst-pyhton-export-sublayers-to-a/m-p/507752#M16894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The below snippet should be enough to get you started. It shows how I'm able to export each sublayer of the network analyst layer to its own feature class. I modified this sample from the online sample.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Name: MakeRouteLayer_Workflow.py
# Description: Find a best route to visit the stop locations and save the 
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; route to a layer file. The stop locations are geocoded from a 
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; text file containing the addresses.
# Requirements: Network Analyst Extension 


#Import system modules
import arcpy
from arcpy import env
from arcpy import mapping as m
from os import path as p


srcPath = p.join(p.dirname(__file__), "data")


try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Check out the Network Analyst extension license
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CheckOutExtension("Network")


&amp;nbsp;&amp;nbsp;&amp;nbsp; #Set environment settings
&amp;nbsp;&amp;nbsp;&amp;nbsp; env.workspace = p.join(srcPath, "SanFrancisco.gdb")
&amp;nbsp;&amp;nbsp;&amp;nbsp; env.overwriteOutput = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Set local variables
&amp;nbsp;&amp;nbsp;&amp;nbsp; inNetworkDataset = "Transportation/Streets_ND"
&amp;nbsp;&amp;nbsp;&amp;nbsp; outNALayerName = "BestRoute"
&amp;nbsp;&amp;nbsp;&amp;nbsp; impedanceAttribute = "TravelTime"


&amp;nbsp;&amp;nbsp;&amp;nbsp; resGDB = p.join(srcPath, "Results.gdb")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(resGDB):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.management.Delete(resGDB)&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.management.CreateFileGDB(*p.split(resGDB))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Create a new Route layer. For this scenario, the default value for all the
&amp;nbsp;&amp;nbsp;&amp;nbsp; #remaining parameters statisfies the analysis requirements
&amp;nbsp;&amp;nbsp;&amp;nbsp; outNALayer = arcpy.na.MakeRouteLayer(inNetworkDataset, outNALayerName,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; impedanceAttribute)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Get the layer object from the result object. The route layer can now be
&amp;nbsp;&amp;nbsp;&amp;nbsp; #referenced using the layer object.
&amp;nbsp;&amp;nbsp;&amp;nbsp; outNALayer = outNALayer.getOutput(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Get the names of all the sublayers within the route layer.
&amp;nbsp;&amp;nbsp;&amp;nbsp; subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Stores the layer names that we will use later
&amp;nbsp;&amp;nbsp;&amp;nbsp; stopsLayerName = subLayerNames["Stops"]
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Load the geocoded address locations as stops mapping the address field from
&amp;nbsp;&amp;nbsp;&amp;nbsp; #geocoded stop features as Name property using field mappings.
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, stopsLayerName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMappings["Name"].mappedFieldName = "NAME"
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.na.AddLocations(outNALayer, stopsLayerName, "Analysis/CandidateStores", fieldMappings,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "", exclude_restricted_elements = "EXCLUDE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Solve the route layer, ignore any invalid locations such as those that
&amp;nbsp;&amp;nbsp;&amp;nbsp; #can not be geocoded
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.na.Solve(outNALayer,"SKIP")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # List sublayers in NALayer Group and export each
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in m.ListLayers(outNALayer):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isGroupLayer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; continue
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.management.CopyFeatures(lyr, p.join(resGDB, lyr.name))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Script completed successfully"


except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred, print line number and error message
&amp;nbsp;&amp;nbsp;&amp;nbsp; import traceback, sys
&amp;nbsp;&amp;nbsp;&amp;nbsp; tb = sys.exc_info()[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "An error occured on line %i" % tb.tb_lineno
&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(e)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:15:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/network-analyst-pyhton-export-sublayers-to-a/m-p/507752#M16894</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2021-12-11T22:15:02Z</dc:date>
    </item>
  </channel>
</rss>

