Summary
Creates an output layer file (.lyr) that references geographic data stored on disk.
Usage
This tool is used to save an in-memory layer, a layer file stored on disk, or a feature layer in ArcMap to a layer file (.lyr) that references geographic data stored on disk.
This tool accepts as input feature layers created by tools such as Make Feature Layer or Make XY Event Layer.
If the input layer has a selection applied to it, the output layer file will maintain this selection.
Syntax
SaveToLayerFile_management (in_layer, out_layer, {is_relative_path}, {version})
Parameter | Explanation | Data Type |
in_layer | The in-memory layer, layer file stored on disk, or feature layer in ArcMap to be saved to disk as a layer file (.lyr). | Layer |
out_layer | The output layer file (.lyr) to be created. | Layer File |
is_relative_path (Optional) | Determines if the output layer file (.lyr) will store a relative path to the source data stored on disk, or an absolute path.
| Boolean |
version (Optional) | The version of layer file the output will be saved as. The default is CURRENT.
| String |
Code sample
SaveToLayerFile Example (Python Window)
The following Python Window script demonstrates how to use the SaveToLayerFile tool in immediate mode.
import arcpy
arcpy.env.workspace = "C:/data"
arcpy.SaveToLayerFile_management("studyquadsLyr", "C:/output/studyquadsLyr.lyr", "ABSOLUTE")
SaveToLayerFile Example (stand-alone Python script)
The following Python script demonstrates how to use the SaveToLayerFile tool in a stand-alone script.
# Name: SaveToLayerFile_Example2.py
# Description: Saves an inMemory layer to a file on disk
# Import system modules
import arcpy
# Set workspace
arcpy.env.workspace = "C:/data"
# Set local variables
in_layer = "studyquadsLyr"
out_layer = "studyquadsLyr.lyr"
# MakeFeatureLayer variables
in_features = "study_quads.shp"
out_layer0 = "studyquadsLyr"
where_clause = '"NAME" = \'LA MESA\''
workspace = "C:/output"
# Execute MakeFeatureLayer
arcpy.MakeFeatureLayer_management(in_features, out_layer0, where_clause, workspace)
# Execute SaveToLayerFile
arcpy.SaveToLayerFile_management(in_layer, out_layer, "ABSOLUTE")
Environments
Licensing information
- ArcGIS for Desktop Basic: Yes
- ArcGIS for Desktop Standard: Yes
- ArcGIS for Desktop Advanced: Yes