2

I've created script in Python for ArcGIS to save shapefile as layer file... the code throws an error:

ERROR 000732: Input Layer: Dataset D:\core i 5 data\symon assignment\Swat\clipped\buffer.shp does not exist or is not supported

Here is my code:

import arcpy
from arcpy import env 
env.workspace = "D:/core i 5 data/symon assignment/Swat/clipped"
buf= "D:\core i 5 data\symon assignment\Swat\clipped\buffer.shp"
ou2= "D:\core i 5 data\symon assignment\Swat\clipped\layer1.lyr"
arcpy.SaveToLayerFile_management(buf, ou2, "ABSOLUTE")
nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Apr 15, 2016 at 10:11
1
  • Not an expert in arcpy but I am pretty sure the paths cannot contain spaces and backspaces are escape signs so they need to be doubled to be taken literally. e.g. "D:\\file\\path\\layer1.lyr". Commented Apr 15, 2016 at 10:20

1 Answer 1

2

Save to Layer File saves a Layer (in memory, layer from disk, or layer from ArcMap) to a layer (.lyr) file. It won't work directly on a feature class or shapefile. You need to first use Make Feature Layer. See Save to Layer File and Make Feature Layer on ArcGIS Desktop Help.

import arcpy
from arcpy import env 
env.workspace = r"D:/core i 5 data/symon assignment/Swat/clipped"
buf= r"D:\core i 5 data\symon assignment\Swat\clipped\buffer.shp"
ou2= r"D:\core i 5 data\symon assignment\Swat\clipped\layer1.lyr"
arcpy.MakeFeatureLayer_management(buf, 'buf_layer')
arcpy.SaveToLayerFile_management('buf_layer', ou2, "ABSOLUTE")

Also, as mentioned in @Kersten's comment above, you need to be careful with back-slash in path names. Either reverse them using a forward-slash /, double back-slash \\, or prefix the string with an r.

answered Apr 15, 2016 at 10:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.