3

I want to write a loop that will cause the output to be multiple buffer shapefiles.

For example, I want a circle buffer of 50ft, 100ft, 150ft, etc.

Can anyone help?

I'm new to this and am trying to figure it out myself.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 21, 2012 at 1:10
1
  • 1
    I know there is a tool that can do this (Multiple Ring Buffer) but I want to know how to write a loop. Commented Sep 21, 2012 at 1:20

1 Answer 1

16

The ArcGIS Resource Center has the following sample script demonstrating how to do multiple ring buffers using Python

# Name: MultipleRingBuffer_Example2.py
# Description: Create multiple buffers for the input features
# Author: ESRI
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
env.workspace = "C:/data/airport.gdb"
# Set local variables
inFeatures = "schools"
outFeatureClass = "c:/output/output.gdb/multibuffer1"
distances = [10,20,30]
bufferUnit = "meters"
# Execute MultipleRingBuffer
arcpy.MultipleRingBuffer_analysis(inFeatures, outFeatureClass, distances, bufferUnit, "", "ALL")

Here's how to do it if you insist on having a for loop

import arcpy
arcpy.env.workspace = "C:/data" 
distances =[50, 100, 150]
for distance in distances:
 outfile = "C:/output/majorrdsBuffered%s" % distance 
 arcpy.Buffer_analysis("roads", outfile, distance, "FULL", "ROUND", "LIST", "Distance")
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Sep 21, 2012 at 1:30
5
  • 4
    Would that for loop code not overwrite it's own outputs? It could be altered to say out_file = "C:/output/majorrdsBuffered" + str(distance) to put the buffersize in the filename. Commented Sep 24, 2012 at 8:09
  • arcpy.Buffer_analysis(clipoutfile, buffered + "_" + str(x) + ".shp", str(x)+" "+buff_unit) this is what I ended up doing as a call. Commented Sep 26, 2012 at 0:09
  • Did it work? Good to know. The file names are your call in the end. Commented Sep 26, 2012 at 5:18
  • Interesting! But what if I want the buffers to be on different layers e.g. 50 meters on roads, 100 meters on schools, 200 meters on bars? Commented Sep 19, 2014 at 12:56
  • 2
    @user37199 an answer to that is too long for comments. Why don't you post a separate question? :) Commented Sep 19, 2014 at 14:10

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.