1

I'm very new to arcpy, my terminology might not be the most precise/accurate.

I'm having trouble saving a sublayer (named "LALines") from a Location Allocation Solve Result as a feature class. As I understand it, these sublayers are children objects of the LocationAllocation layer that results from the Solve function.

My code looks like this:

    desc = arcpy.Describe(LocationAllocation_Output)
    for child in desc.children:
        if child.name == 'LALines':
            arcpy.FeatureClassToFeatureClass_conversion(child, "\\\\DC1\\ExampleLocation", "ChildLines")`

and I receive this error every time:

RuntimeError: Object: Error in executing tool

I've done some pretty thorough searching/googling but can't seem to find an exact answer. Anyone have any ideas?

2

The GetNAClassNames method outlined here will help you to grab the LALines: http://pro.arcgis.com/en/pro-app/arcpy/network-analyst/getnaclassnames.htm

Note the link above is for ArcGIS Pro but the process is similar in ArcMap 10.x.

The code reference for LocationAllocation also includes these steps: http://pro.arcgis.com/en/pro-app/tool-reference/network-analyst/make-location-allocation-layer.htm

  1. Create an object for your LocationAllocation.
  2. Get the network analysis layer names
  3. Get the result object sublayer for the lines
  4. Export using copy features

My example below has combined code from the two links above.

#Create a new location-allocation layer. 
result_object = arcpy.na.MakeLocationAllocationLayer(network, layer_name,
                                                  impedance,
                                                  "DEMAND_TO_FACILITY",
                                                  "MAXIMIZE_ATTENDANCE", 3,
                                                  5, "LINEAR")

#Get the layer object from the result object. The location-allocation layer
#can now be referenced using the layer object.
layer_object = result_object.getOutput(0)

#Get the names of all the sublayers within the location-allocation layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
facilities_layer_name = sublayer_names["Facilities"]
demand_points_layer_name = sublayer_names["DemandPoints"]
lalines_layer_name = sublayer_names["LALines"]

 #Get the lalines sublayer from the service area layer
lalinesSublayer = layer_object.listLayers(lalines_layer_name)[0]
# if you want to do in one step instead, skip the lalines_layer_name step above and use the following:
# lalinesSublayer = layer_object.listLayers(sublayer_names["SALines"])[0]

#Export the lalines sublayer as a feature class
output_lines = pathtooutputdestination
arcpy.management.CopyFeatures(lalinesSublayer, output_lines)

EDIT: The syntax is pretty much the same from my quick scan, but just in case I included a link to the 10.x docs for this function. http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-network-analyst/getnaclassnames.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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