2

enter image description here

So I have a script that calculates a diameter of a crater of an asteroid with user input parameters. what i need help with is creating a buffer that brings in the diameter as the distance value and creates a buffer around different point locations. I can't seem to find a way to bring the value into the buffer tool. I have also tried to find a way to just add the distance to layer i want to do a buffer around as an attribute.

def main():
 import arcpy
 velocity = arcpy.GetParameter(0)
 mass = arcpy.GetParameter(1)
 component = GetParameterAsText(2)
 dct_mat = {'ice' : 1.8, 'iron' : 7.3, 'rock' : 2.3}
 comp = dct_mat[component]
 grav = (0.16667)
 const = (0.007)
 colrt = (1.3)
 soil = (2.65)
 power = (1.0/3.4)
 vel = (velocity * 1000.0)
 kilotons = (4184000000000.0)
 kinetic = (0.5 * mass * (vel ** 2))
 energy = (kinetic * kilotons)
 part1 = (const * colrt * grav)
 part2 = (comp / soil)
 part3 = (energy * part2)
 part4 = (part3 ** power)
 crater = (part1 * part4)
 final = (crater / int(1000))
 arcpy.SetParameter(3, final)
 arcpy.AddMessage("final: {}".format(final))
if __name__ == '_main_':
 main()

here is the script i'm using. also i cant get the message to work but that isn't as important right now.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 15, 2017 at 22:04
8
  • Is it buffer or multiple ring buffer. The buffer tool has 'buffer field or value', just add a field, populate with the crater distance and put in the field name and the linear unit is used from there (must be numeric and in the units of the spatial reference of the data). Can you include some of this script for us to see what you're up to and where you're stuck. Commented Nov 15, 2017 at 22:11
  • the script i'm using outputs a long value but the buffer tool only allows you to input a table of points lines or polygons to create a buffer around and the field input only accepts field from that table Commented Nov 15, 2017 at 22:18
  • From a question I answered yesterday, gis.stackexchange.com/questions/261861/… your SetParameter may be incorrect. Where are you implementing buffer resources.arcgis.com/en/help/main/10.2/index.html#//…? The 3rd parameter is buffer_distance_or_field, assuming your 'final' value is in metres '{} meters'.format(final) should work (meters is American spelling, the British/Australian spelling doesn't work). If you're using later SetParameterAsText(2,'{} meters'.format(final)) Commented Nov 15, 2017 at 22:42
  • And in your script tool define the output parameters' type as 'linear unit' so it can be ingested by the buffer tool, or do the buffer in this tool just after the AddMessage line; of course you'd need to add another input parameter to specify the buffer location/name. Commented Nov 15, 2017 at 22:46
  • how would i define my output parameter as a linear unit? Commented Nov 15, 2017 at 22:52

1 Answer 1

1

Inserting the buffer into the script is fairly easy:

import arcpy,os
velocity = arcpy.GetParameter(0)
mass = arcpy.GetParameter(1)
component = GetParameterAsText(2)
ImpactLoc = GetParameterAsText(3) # add this input parameter to the script tool
dct_mat = {'ice' : 1.8, 'iron' : 7.3, 'rock' : 2.3}
comp = dct_mat[component]
grav = (0.16667)
const = (0.007)
colrt = (1.3)
soil = (2.65)
power = (1.0/3.4)
vel = (velocity * 1000.0)
kilotons = (4184000000000.0)
kinetic = (0.5 * mass * (vel ** 2))
energy = (kinetic * kilotons)
part1 = (const * colrt * grav)
part2 = (comp / soil)
part3 = (energy * part2)
part4 = (part3 ** power)
crater = (part1 * part4)
final = (crater / int(1000))
arcpy.AddMessage("final: {}".format(final))
ILname, ILext = os.path.splitext(ImpactLoc) # break up the impact location to "name" and ".ext"
BufferName = ILname + '_Buffer' + ILext # name as impact location with _buffer in the name
# perform the buffer
arcpy.Buffer_analysis(ImpactLoc,BufferName,'{} meters'.format(final)) # change the 'meters' to 'feet', 'kilometers' etc if your final units are different
# set the buffer as output, perhaps SetParameterAsText might be more suitable
arcpy.SetParameter(4, BufferName) # Change this output parameter to feature class

But you need to make some changes to the script tool used in the model, add a parameter of type feature class for your impact locations then move your output down one line and change the type also to feature class in order for the tool to work in model builder.

answered Nov 16, 2017 at 1:17
5
  • Traceback (most recent call last): File "S:\Courses304円\bbrewe1\Asteroid_project\ie with buff.py", line 30, in <module> arcpy.Buffer_analysis(impactloc,BufferName,'{} kilometers'.format(final)) # change the 'meters' to 'feet', 'kilometers' etc if your final units are different File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\analysis.py", line 692, in Buffer raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000735: Input Features: Value is required Failed to execute (Buffer). i got this error when i tried to run the script Commented Nov 16, 2017 at 2:21
  • Have you modified the script tool properties (in its toolbox) to add the new parameter and have you populated the new parameter with your Impact Locations.shp ? It's telling you that the buffer 'from' features isn't populated. Commented Nov 16, 2017 at 3:29
  • I believe that I have but I will take a look again. I know I added the new parameter; I am guessing that the problem is the population of the feature. Commented Nov 20, 2017 at 20:02
  • so i cant seem to get ILname, ILext to popuate Commented Nov 27, 2017 at 17:18
  • What is the value of ImpactLoc? Have you imported os? Commented Nov 27, 2017 at 20:58

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.