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.
-
1I know there is a tool that can do this (Multiple Ring Buffer) but I want to know how to write a loop.George Diamond– George Diamond2012年09月21日 01:20:51 +00:00Commented Sep 21, 2012 at 1:20
1 Answer 1
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")
-
4Would 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.sgrieve– sgrieve2012年09月24日 08:09:39 +00:00Commented 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.George Diamond– George Diamond2012年09月26日 00:09:50 +00:00Commented Sep 26, 2012 at 0:09
-
Did it work? Good to know. The file names are your call in the end.R.K.– R.K.2012年09月26日 05:18:05 +00:00Commented 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?user37199– user371992014年09月19日 12:56:05 +00:00Commented 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? :)nmpeterson– nmpeterson2014年09月19日 14:10:37 +00:00Commented Sep 19, 2014 at 14:10
Explore related questions
See similar questions with these tags.