0
import arcpy
arcpy.env.workspace = r'c:\data'
fcs = str(raw_input('Please enter the layers you would like to buffer: '))
dist = str(raw_input('What would you like your buffer distance to be? '))
output = str(raw_input('Name your output: '))
for fc in fcs:
 if arcpy.Exists(fcs):
 arcpy.Buffer_analysis(inputs, output, dist)
if not arcpy.Exists(fcs):
 print "Feature class does not exist"

The above script executes but does not create the feature class I want. Where am I going wrong?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 24, 2015 at 10:01
3
  • 1
    Debug your code to see what is the fc value is. You supply the inputs to the Buffer however, it should be fc. Indentation is wrong, arcpy.Buffer_analysis should be one level to the right. Commented Mar 24, 2015 at 10:19
  • Print the contents of each variable before you use them - I think you are assuming that they have a value different to what is actually being stored. Commented Mar 24, 2015 at 10:39
  • Any time you take a user entered string you should check the entry to make sure it's valid. For example, someone could enter 'abc' for dist. This would, obviously, be incorrect. Commented Mar 24, 2015 at 12:07

1 Answer 1

1

As indicated in the comments, you have a few issues. The first one I see is your enumerating through fcs. What do you expect to enter at the prompt? Your code will enumerate through each letter, which I expect is not what you want. For example, if you enter "fred, bob", the list will be: [f,r,e,d, , b,o,b].

Try:

arcpy.env.workspace = r'c:\data'
string_input = raw_input('Please enter the layers you would like to buffer: ')
fcs = map(str.strip, string_input.split(','))
dist = raw_input('What would you like your buffer distance to be? ')
output = raw_input('Name your output: ')
for fc in fcs:
 if arcpy.Exists(fc):
 arcpy.Buffer_analysis(fc, output, dist)
 if not arcpy.Exists(fc):
 print "Feature class does not exist"

Where you would enter a comma-delimited list for the layers to buffer. For example, "trees, shrubs, plants".

Warning: this is untested code, so there may be other issues. I am unsure what you want youroutput to be as all the inputs will go to the same output feature class.

answered Mar 24, 2015 at 11:15

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.