1

I have one shapefile that covers an entire city. I also have a list of 100 shapefiles which are buffers in different places in the city. Now I want to clip for each buffer from that city using ArcMap and python. I tried using arcpy in python but the code is not working.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "U:\Park and Residential Area\Test\SBA park_res_buffer_5\SBA.gdb"
infeature= "U:\Park and Residential Area\Test\park_res_merge.shp"
clipfeatture = arcpy.ListFeatureClasses("*", "polygon")
for i in clipfeatture:
    outclipfeatture = arcpy.Clip_analysis(infeature,i)
    outclipfeatture.save("U:\Park and Residential Area\Test\SBA park_res_buffer_5/"*i)

This is the error i get:

Traceback (most recent call last):
File "<pyshell#10>", line 3, in <module> outclipfeatture.save("U:\Park and Residential Area\Test\SBA park_res_buffer_5/"*i)
AttributeError: 'Result' object has no attribute 'save'
  • 1
    What are the results of your current code? Are you receiving an error message? – nmpeterson Jan 20 '16 at 21:40
  • This is the error i get:Traceback (most recent call last): File "<pyshell#10>", line 3, in <module> outclipfeatture.save("U:\Park and Residential Area\Test\SBA park_res_buffer_5/"*i) AttributeError: 'Result' object has no attribute 'save' – Lira Jan 20 '16 at 21:45
  • 1
    You may want to try using the raw string form for the URLs. Example: r"U:\Park and Residential Area\Test\SBA park_res_buffer_5\SBA.gdb" in order to avoid having to escape the back slashes. Also did you mean to use a + instead of a * in the last expression? – Chaz Jan 20 '16 at 21:56
5

arcpy.Clip_analysis() has 3 required parameters: in_features, clip_features, and out_feature_class. You're only supplying the first two. Additionally, there is no save method for the Result object, as your error message indicates.

Instead, you should set outclipfeatture = r"U:\path\to\output.shp" (which will need to be unique for each clip feature) and then call arcpy.Clip_analysis(infeature, i, outclipfeatture). This will create the output shapefile and save the result to it.


One other note: your current paths will not be interpreted correctly. You either need to convert them to raw strings by placing an r in front of the string as in my example, change your backslashes (\) to forward slashes (/), or double them up (\\) so they are properly escaped.

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.