Closest Facilities analysis

431
3
Jump to solution
11-22-2017 07:37 PM
Highlighted
New Contributor III

I have a script to do a closest facility analysis using Network Analyst. The script works very well until the last line where I want to save the layer as a feature class.

I get an error message.

Excerpt of the script;

###############

print "Solving"
    #Solve the closest facility layer
    arcpy.na.Solve(layer_object)

   

   # Get the output layer and save it to a feature class

    arcpy.management.CopyFeatures(layer_object, outRoutesFC)

#############

This is the error message:

Processing T1 routes
Solving
An error occured on line 85
Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Feature Layer.
ERROR 000840: The value is not a Raster Catalog Layer.
Failed to execute (CopyFeatures).

I will appreciate any help. Thanks.

Dionisio

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Regular Contributor

If you want to save the entire Closest Facility Layer as a layer file, use SaveToLayerFile as Dan suggests.  If you just want to save the output Closest Facility routes sublayer to a feature class, you will have to retrieve the sublayer.  An example of retrieving and saving sublayers can be found in the last code sample on this page: Make OD Cost Matrix Layer—Help | ArcGIS Desktop 

The example is for OD Cost Matrix, but the same principles hold for Closest Facility.  Essentially you have to grab the sublayer object and use that in CopyFeatures.

View solution in original post

3 Replies
Highlighted
MVP Esteemed Contributor

You want to use SaveToLayerFile as documented in the code example at the bottom of the help topic for Solve

http://desktop.arcgis.com/en/arcmap/latest/tools/network-analyst-toolbox/solve.htm

Reply
0 Kudos
Highlighted
Esri Regular Contributor

If you want to save the entire Closest Facility Layer as a layer file, use SaveToLayerFile as Dan suggests.  If you just want to save the output Closest Facility routes sublayer to a feature class, you will have to retrieve the sublayer.  An example of retrieving and saving sublayers can be found in the last code sample on this page: Make OD Cost Matrix Layer—Help | ArcGIS Desktop 

The example is for OD Cost Matrix, but the same principles hold for Closest Facility.  Essentially you have to grab the sublayer object and use that in CopyFeatures.

View solution in original post

Highlighted
New Contributor III

Thank you very mu

Reply
0 Kudos