Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm pretty new in python, and I'm trying to iterate through a list of feature classes, and perform a buffer on each feature class. So I've done this:

import arcpy  
from arcpy import env  
env.workspace = "C:/EsriPress/Python/Data/Midterm/Oil_project.gdb"  
env.overwriteOutput = True  
fclist = arcpy.ListFeatureClasses("", "Polyline", "Well_Data")  

for fc in fclist  
buffer = arcpy.Buffer_analysis(fc, fcname_buffer, "75 FEET")

However, I want each output file name to be the original feature class name with _buffer at the end. For example, the name of the first feature class in the list is Well_A_BB05.shp. I want the output to be "Well_A_BB05_buffer". I can't get this to work.

share|improve this question

In the arcpy.Buffer_analysis() set your output to be '{}_buffer'.format(fc) which will add your feature class name from fc in front of the _buffer text e.g. if your feature class is called "Line3" the output buffer feature class would be called "Line3_buffer"

import arcpy  
from arcpy import env  
env.workspace = "C:/EsriPress/Python/Data/Midterm/Oil_project.gdb"  
env.overwriteOutput = True  

fclist = arcpy.ListFeatureClasses("", "Polyline", "Well_Data")  

for fc in fclist: 
    arcpy.Buffer_analysis(fc, '{}_buffer'.format(fc), "75 FEET")
share|improve this answer
    
Thank you so much!! This is great! – Andy Fisher Mar 13 at 9:19
2  
@AndyFisher Please consider accepting this answer by selecting the green check mark next to the answer. This question can then be considered resolved. – Aaron Mar 13 at 16:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.