AnsweredAssumed Answered

How to save a raster with a script tool input?

Question asked by rhowell2 on Feb 21, 2019
Latest reply on Feb 22, 2019 by fallingdog

I'm learning python and have been banging my head on this for hours now and can't figure it out. It's probably something really basic but here it goes...

 

I have a base elevation raster that I'm running some math on to get a basic ruggedness layer. The script works when I run it in the python window, but I'm trying to use it to create a script tool. Here is what I have simplified:

 

outWorkspace = arcpy.GetParameterAsText(0)
baseRaster = arcpy.GetParameterAsText(1)
scale = arcpy.GetParameterAsText(2)
outRaster = arcpy.GetParameterAsText(3)

env.workspace = outWorkspace

 

###lots of math on the baseRaster

 

FinalResult = #more math

 

finalResult.save()

 

When I run it like this, the tool runs but it doesn't appear to save my file in the workspace specified (or anywhere for that matter, I can't find the results of the tool). So I guess that's issue #1.

 

Second question is how do I script this so that the name of FinalResult is whatever the user puts in for outRaster, instead of FinalResult?

 

In case it is needed, my parameters that I have set up in my script tool are as follows:

0 = Workspace (data type), input

1 = Raster Dataset, Input

2 = Long, Input

3 = Raster Dataset, Output

Outcomes