I have some feature classes (7 feature classes) and I want to batch buffer in ArcGIS 10. I don't know how can I buffer at once. Please help me.
6 Answers
To buffer several features, you need to use some control structure. A technique I have found very useful is to store all of the shapefiles you are using in one folder, then loop through everything that is a shapefile. I do this using the glob
module, as follows:
# import modules
import arcpy, glob
# folder where shapefiles are stored
folder = 'C:/myfiles/'
# loop through all shapefiles
for shapefile in glob.glob( folder + '*.shp' ):
arcpy.Buffer_analysis( shapefile, "C:/output/" + shapefile[-8:-4] + "buffer.shp" "100 Feet", "FULL", "ROUND", "LIST", "Distance")
(See ArcGIS help here for more details)
I'm using an awkward way of naming the buffered file here (shapefile[-8:-4]
); a better way is to set the workspace using something like arcpy.env.workspace = "C:/data"
.
-
Should have read @jburka's answer more carefully before posting!– djqCommented May 5, 2011 at 23:39
As someone else already pointed out, you can use the Batch option by right-clicking the tool in Toolbox. Otherwise, it's hard to know how best to batch it without knowing more about the feature classes and their locations (are they all in the same workspace? are they the only feature classes in that workspace?) and the type of buffers you want to create (e.g. will they all have the same distance)
These things all go into, for instance, whether you're better off just typing in the name of a few feature classes into a list or if you should be using something like arcpy.ListFeatureClasses
to generate a list of feature classes to process.
Something as simple as:
import arcpy
arcpy.env.workspace = r'path\to\workspace'
featureClasses = ['fc1', 'fc2', 'fc3']
for featureClass in featureClasses:
arcpy.Buffer_analysis(featureClass, "C:/output/" + featureClass + "Buffered" "100 Feet", "FULL", "ROUND", "LIST", "Distance")
would likely take care of it...
To batch buffer in ArcMap 10 you can use the built in tools. Just browse to Buffer in ArcToolbox (Analysis Tools < Proximity < Buffer), right-click the buffer tool and select batch.
Sorry, I couldn't edit my comment properly; this is how I would go
arcpy.env.workspace = r'path\to\workspace'
fcs = arcpy.ListFeatureClasses()
try:
for fc in fcs:
arcpy.Buffer_analysis(fc, outBufferFeatureClass, "X meters")
except:
print "Error buffering FeatureClasses."`
I hope that helps. You will have to thread if you want to do it all at the same time.
-
can you plaese Edit or comment back with
arcpy.GetParameterAsText(0) for Input folder
|arcpy.GetParameterAsText(1) for Buffer(Double)
|arcpy.GetParameterAsText(2) for outputfolder
` arcpy.Buffer_analysis(fc, outputfolder+ fc", buffer) Commented May 17, 2015 at 6:14
Here is the ESRI Buffer/ArcPy link. Here you will find some general code examples.
-
thanks but there is not example for buffering more than one feture class at once– BBG_GISCommented May 5, 2011 at 18:54
-
@GISlove Why would you need to buffer more than one feature class at a time? Just curious. Commented May 5, 2011 at 19:04
-
i want to learn for and while loop in python . this is the reason for batch buffering– BBG_GISCommented May 5, 2011 at 20:44
-
@GISlove Ah, I thought you meant that you wanted to run all of the buffering jobs simultaneously. Batch buffering via python makes more sense. Commented May 5, 2011 at 23:17
-
If you want to do them all at the same time, you'll have to put it into threads.– HairyCommented May 6, 2011 at 10:40
The Buffer
tool does not work on more than one feature class at a time. If you want to buffer all the features in multiple feature classes, you will have to either merge the feature classes into one combined feature class and buffer that, or buffer each of the individual feature classes in a loop.