4

I am trying to run a buffer tool as part of script that I will both use as a standalone script and import into ArcToolbox.

If I use GetParameterAsText for the buffer distance, how do I set the linear units?

For example, I want it preset so they only have to type 300 and the script takes that to be meters.

Here is what I have so far:

# Buffer the Thames feature class to create the Flood Risk Area
in_features = "Thames"
out_feature_class = "Flood_R_A"
# Run the Buffer Tool
arcpy.Buffer_analysis (in_features, out_feature_class, arcpy.GetParameterAsText(5),    "FULL", "ROUND", "ALL", "")
0

2 Answers 2

3

If you want the user to specify both a distance and units, as can be found in the Buffer tool (and most other tools that specify a distance), you can use the Linear Unit parameter. You can pass this whole parameter value to the tool

The distance passed to buffer can be numeric (in which case it's in the units of the feature class) or as numeric with units (meters, feet, degrees, etc).

0
2

This is untested but should work:

arcpy.Buffer_analysis (in_features, out_feature_class, arcpy.GetParameterAsText(5) + " Meters",    "FULL", "ROUND", "ALL", "")

To avoid confusion between whether you are asking for a number or a "number with units", I also advise structuring your code more like this:

bufDistAsStringWithNoUnits = arcpy.GetParameterAsText(5)

arcpy.Buffer_analysis (in_features,out_feature_class,bufDistAsStringWithNoUnits + " Meters","FULL","ROUND","ALL","")

However, I think @Pauls answer which recommends using the Linear Unit parameter instead is sage advice.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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