Customer Service | Training | Contact Us
You are here: Home > User Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Geoprocessing Scripting (Python, JavaScript, VB) forum

Python - Spatial analyst / Raster issue   sam evans Nov 03, 2009
Re: Python - Spatial analyst / Raster issue   Gerry Gabrisch Nov 09, 2009
Re: Python - Spatial analyst / Raster issue   sam evans Nov 10, 2009
Report Inappropriate Content • Top • Print • Reply    
Subject Python - Spatial analyst / Raster issue 
Author sam evans 
Date Nov 03, 2009 
Message I'm having an issue where if I call any spatial analyst tool in a script involving a raster, it fails. Until I restart ArcGIS, ANY Spatial Analyst function will fail involving a raster.

If, however, I first call a spatial analyst tool by itself, let it complete, and THEN run my script, it will work no matter the number of times that I run it afterwards.

Whenever I relaunch ArcGIS, everything resets itself, so that I have to re-run a stock tool before running my tool.

I have looked at the environments under the "Results tab" or ArcToolbox, and the environments are exactly the same. Same everything, except one failed and the other completed successfully.

My function call looks like this, 
 
tempShape = "E:\\dbitw\\shape.shp"
tempRaster = "E:\\dbitw\\iwdr"

#my workspace is "E:\\scratch", but I've tried it as "E:\\dbitw" as well.
#I've also tried using / instead of \\
gp.IWD_sa(tempShape, "In_", tempRaster, "3.95575", "2", "VARIABLE 12", "")
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Python - Spatial analyst / Raster issue 
Author Gerry Gabrisch 
Date Nov 09, 2009 
Message Did you load the toolbox before calling the IDW function?

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Python - Spatial analyst / Raster issue 
Author sam evans 
Date Nov 10, 2009 
Message Yeah, adding the toolbox is one of the first things I do in my code.
I added the line at the bottom as the very first bit of actual processing that my code does (the IDW call is one of the last things I do), and the code now executes flawlessly.

Except for the fact that now I create a useless random raster every time that I run the code. Not too pricey considering it makes everything else work, though.

At this point, since it works, I'm really just curious as to why it didn't work before. 
 
gp.CreateRandomRaster_sa(rastdir + "\\randrast", "", "1", "0 0 250 250")
#rastdir is just = "E:\\dbitw", the same directory I use later on in my code, just thrown in here so I can change it if I need to.