<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Stand alone script fails using spatial analyst tools in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431393#M33899</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've finally resolved this issue. It turns out that the arc modules wouldn't run on the H drive that I was using so I saved everything to the C drive instead and it all ran fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's the code for future reference:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os
import time
import sys
from arcpy import env
from arcpy.sa import *

env.workspace = "C:/temp/testIt"
env.scratchWorkspace = env.workspace
catchmentName = "CatchmentName"
catchmentRaster = catchmentName + ".tif"
catchmentRasterProj = catchmentName + "proj.tif"
catchment100 = catchmentName + "100.tif"
catchment100Fill = catchmentName + "100Fill.tif"
catchment100Flow = catchmentName + "100Flow.tif"
catchment100Acc = catchmentName + "100Acc.tif"
catchment100PP = catchmentName + "100PP.tif"
catchment100WS = catchmentName + "100WS.tif"
folder = "C:/temp/testIt"
folderAdd = "C:/temp/testIt/"
outlet = "outlet.shp"
projection = "C:/Program Files (x86)/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems/National Grids/Europe/British National Grid.prj"
# identify guage
#create pourpoint shapefile
# identify catchment outline
# select appropriate testIt

# have a folder with all of the little ascii testIt for a catchment. This folder will be called *catchment name*
print "checking extensions"

try:
 arcpy.CheckExtension("Spatial") == "Available"
 arcpy.CheckOutExtension("Spatial")
 print "done"
except:
 print "Didn't work!"
 

print "converting the ascii files to raster files"

asciiList = os.listdir(folder)&amp;nbsp;&amp;nbsp;&amp;nbsp; 

for x in range(len(asciiList)-1, -1, -1):
 if not asciiList&lt;X&gt;.endswith(".asc"):
&amp;nbsp;&amp;nbsp; asciiList.pop(x)


for file in asciiList:&amp;nbsp; 
 print folderAdd + file
 print folderAdd + file[:-4]
 
 try:
&amp;nbsp; arcpy.ASCIIToRaster_conversion(folderAdd+ file, folderAdd+ file[:-4] + ".tif", "INTEGER")
 except:
&amp;nbsp; print "Processing " + file + "FAILED"
&amp;nbsp; 
 time.sleep(3)
 
tifList = os.listdir(folder)

print tifList

for x in range(len(tifList) -1, -1, -1):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not tifList&lt;X&gt;.endswith(".tif"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tifList.pop(x)

print tifList

tifString = ""
for tif in tifList:
 tifString += tif + ";"
 
tifString = tifString[:-1]

print tifString

print "mosaic to new raster"

try:
 arcpy.MosaicToNewRaster_management(tifString, folderAdd, catchmentRaster, "#", "16_BIT_SIGNED", "#", "1" , "MEAN")
except:
 print "Error with mosaic to new raster"
 
time.sleep(3)


print "Giving it the right coordinates"
try:
 arcpy.DefineProjection_management(catchmentRaster, projection)
 arcpy.ProjectRaster_management(catchmentRaster, catchmentRasterProj, projection, "BILINEAR", "#", "#","#",projection)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message


time.sleep(3)
 
print "Changing resolution"

try:
 outAggreg = Aggregate(folderAdd + catchmentRasterProj, 10, "MEDIAN", "TRUNCATE", "DATA")
 outAggreg.save(catchment100)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
time.sleep(3)
 
print "Filling sinks"

try:
 outFill = Fill(catchment100)
 outFill.save(catchment100Fill)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
print "Calculating fow direction"

time.sleep(3)

try:
 outFlowDirection = FlowDirection(catchment100Fill, "NORMAL")
 outFlowDirection.save(catchment100Flow)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
 
print "Calculating flow accumulation"

time.sleep(3)

try:
 outFlowAccumulation = FlowAccumulation(catchment100Flow)
 outFlowAccumulation.save(catchment100Acc)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message

print "Creating pour point snap"

time.sleep(3)

try:
 outSnapPour = SnapPourPoint(outlet, catchment100Acc, 5, "FID")
 outSnapPour.save(catchment100PP)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
time.sleep(3)

print "Creating watershed"

try:
 outWatershed = Watershed(catchment100Flow,catchment100PP)
 outWatershed.save(catchment100WS)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
time.sleep(3)
 
print "Creating files for SHETRAN prepare"

try:
 arcpy.RasterToASCII_conversion(catchment100, catchmentName + "100DEM.txt")
 arcpy.RasterToASCII_conversion(catchment100WS, catchmentName + "100Mask.txt")
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
time.sleep(3)
 
print "Done!"

raw_input("close to exit")
&lt;/X&gt;&lt;/X&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 19:23:26 GMT</pubDate>
    <dc:creator>ElizabethLewis</dc:creator>
    <dc:date>2021-12-11T19:23:26Z</dc:date>
    <item>
      <title>Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431378#M33884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to create a stand alone script to automate watershed analysis. So far it works up until it gets to the spatial analyst &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tools but then fails. Can anyone show me where I have gone wrong please? Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
import os
import time
import sys
from arcpy import env
from arcpy.sa import *

env.workspace = "H:/PhD/PythonLessons/Scripts/testIt"
catchmentName = "CatchmentName"
catchmentRaster = catchmentName + ".tif"
catchmentRasterProj = catchmentName + "proj.tif"
catchment100 = catchmentName + "100.tif"
catchment100Fill = catchmentName + "100Fill.tif"
catchment100Flow = catchmentName + "100Flow.tif"
catchment100Acc = catchmentName + "100Acc.tif"
catchment100PP = catchmentName + "100PP.tif"
catchment100WS = catchmentName + "100WS.tif"
folder = "H:/PhD/PythonLessons/Scripts/testIt"
folderAdd = "H:/PhD/PythonLessons/Scripts/testIt/"
outlet = "outlet.shp"
projection = "C:/Program Files (x86)/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems/National Grids/Europe/British National Grid.prj"
# identify guage
#create pourpoint shapefile
# identify catchment outline
# select appropriate testIt

# have a folder with all of the little ascii testIt for a catchment. This folder will be called *catchment name*
print "checking extensions"

try:
 arcpy.CheckExtension("Spatial") == "Available"
 arcpy.CheckOutExtension("Spatial")
 print "done"
except:
 print "piddle"
 

print "converting the ascii files to raster files"

asciiList = os.listdir(folder)&amp;nbsp;&amp;nbsp;&amp;nbsp; 

for x in range(len(asciiList)-1, -1, -1):
 if not asciiList&lt;X&gt;.endswith(".asc"):
&amp;nbsp;&amp;nbsp; asciiList.pop(x)


for file in asciiList:&amp;nbsp; 
 print folderAdd + file
 print folderAdd + file[:-4]
 
 try:
&amp;nbsp; arcpy.ASCIIToRaster_conversion(folderAdd+ file, folderAdd+ file[:-4] + ".tif", "INTEGER")
 except:
&amp;nbsp; print "Processing " + file + "FAILED"
&amp;nbsp; 
 time.sleep(3)
 
tifList = os.listdir(folder)

print tifList

for x in range(len(tifList) -1, -1, -1):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not tifList&lt;X&gt;.endswith(".tif"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tifList.pop(x)

print tifList

tifString = ""
for tif in tifList:
 tifString += tif + ";"
 
tifString = tifString[:-1]

print tifString

print "mosaic to new raster"

try:
 arcpy.MosaicToNewRaster_management(tifString, folderAdd, catchmentRaster, "#", "16_BIT_SIGNED", "#", "1" , "MEAN")
except:
 print "Error with mosaic to new raster"
 
time.sleep(3)


print "Giving it the right coordinates"
try:
 arcpy.DefineProjection_management(folderAdd + catchmentRaster, projection)
 arcpy.ProjectRaster_management(folderAdd + catchmentRaster, folderAdd + catchmentRasterProj, projection, "BILINEAR", "#", "#","#",projection)
except: 
 print "Error giving it the right coordinates"

time.sleep(3)
 
print "Changing resolution"

try:
 outAggreg = Aggregate(catchmentRasterProj, 10, "MEDIAN", "TRUNCATE", "DATA")
 outAggreg.save(folderAdd + catchment100)
except:
 print "Error changing resolution"
 
time.sleep(3)
 
print "Filling sinks"

try:
 outFill = Fill(catchment100)
 outFill.save(folderAdd + catchment100Fill)
except:
 print "error filling sinks"
 
print "Calculating fow direction"

time.sleep(3)

try:
 outFlowDirection = FlowDirection(catchment100Fill, "NORMAL")
 outFlowDirection.save(folderAdd + catchment100Flow)
except:
 print "Error calculating flow direction"
 
 
print "Calculating flow accumulation"

time.sleep(3)

try:
 outFlowAccumulation = FlowAccumulation(catchment100Flow)
 outFlowAccumulation.save(folderAdd + catchment100Acc)
except:
 print "Error calculating flow accumulation"

print "Creating pour point snap"

time.sleep(3)

try:
 outSnapPour = SnapPourPoint(outlet, catchment100Acc, 5, "FID")
 outSnapPour.save(folderAdd + catchment100PP)
except:
 print "Error snapping pour point"
 
time.sleep(3)

print "Creating watershed"

try:
 outWatershed = Watershed(catchment100Flow, catchment100PP)
 outWatershed.save(folderAdd + catchment100WS)
except:
 print "Error creating watershed"
 
time.sleep(3)
 
print "Creating files for SHETRAN prepare"

try:
 arcpy.RasterToASCII_conversion(catchment100, folderAdd + catchmentName + "100DEM.txt")
 arcpy.RasterToASCII_conversion(catchment100WS, folderAdd + catchmentName + "100Mask.txt")
except:
 print "error creating files for SHETRAN prepare"
 
time.sleep(3)
 
print "Done!"

raw_input("close to exit")&lt;/X&gt;&lt;/X&gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks very much&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 08:18:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431378#M33884</guid>
      <dc:creator>ElizabethLewis</dc:creator>
      <dc:date>2012-03-05T08:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431379#M33885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;have you tried appending _sa to all of the spatial analyst tools as you have done with the _management etc tools?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 10:35:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431379#M33885</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2012-03-05T10:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431380#M33886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Please post the error message.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Appending _sa should not help with your way to import the functions, but try it anyway. Try also to call arcpy.Fill_sa(...) etc.. I think this would be also better readable.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 10:51:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431380#M33886</guid>
      <dc:creator>FabianBlau</dc:creator>
      <dc:date>2012-03-05T10:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431381#M33887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried arcpy.Aggregate_sa(...) but it still doesn't work. I don't get an error message apart from my own:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"Giving it the right coordinates"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Changing resolution"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Error changing resolution"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"error filling sinks"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Calculating fow direction"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Error calculating flow direction"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Calculating flow accumulation"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Error calculating flow accumulation"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Creating pour point snap"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Error snapping pour point"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Creating watershed"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Error creating watershed"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Creating files for SHETRAN prepare"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"error creating files for SHETRAN prepare"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Done!"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any other ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 12:28:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431381#M33887</guid>
      <dc:creator>ElizabethLewis</dc:creator>
      <dc:date>2012-03-05T12:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431382#M33888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It would be better to print the arcgis-errormessages. Dont use try/except in this way. When any error occurs your script dont stop. The following code will crash also (in your case).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have an arcinfo-license? aggregate needs it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 13:05:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431382#M33888</guid>
      <dc:creator>FabianBlau</dc:creator>
      <dc:date>2012-03-05T13:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431383#M33889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've changed the script so that it now looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try:
 outAggreg = arcpy.Aggregate_sa(catchmentRasterProj, 10, "MEDIAN", "TRUNCATE", "DATA")
 arcpy.outAggreg.save_sa(folderAdd + catchment100)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error message is: 'module' object has no attribute 'Aggregate_sa@&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:23:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431383#M33889</guid>
      <dc:creator>ElizabethLewis</dc:creator>
      <dc:date>2021-12-11T19:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431384#M33890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried aggregate in my python window.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This didnt work (also the AttributeError :mad:):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Aggregate_sa('ws', 'Aggrega_ws2')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was ok:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.sa.Aggregate("ws",5,"MAXIMUM","EXPAND","DATA")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Mar 2012 14:08:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431384#M33890</guid>
      <dc:creator>FabianBlau</dc:creator>
      <dc:date>2012-03-06T14:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431385#M33891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;arcpy.sa.Aggregate(...) gave this error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 999999: Error executing function. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;failed to open raster dataset&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute &amp;lt;aggregate&amp;gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I'm trying to do this as a stand alone script and not in the python window.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Mar 2012 14:17:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431385#M33891</guid>
      <dc:creator>ElizabethLewis</dc:creator>
      <dc:date>2012-03-06T14:17:52Z</dc:date>
    </item>
    <item>
      <title>Note: Tool_sa syntax invalid at 10.x</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431386#M33892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;have you tried appending _sa to all of the spatial analyst tools as you have done with the _management etc tools?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dan, this changed at 10.x. The Spatial Analyst licensed functions need to be access the new python-esque way:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.sa.Con(...)
from arcpy.sa import *
out = Con(..) &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you have a 3D license, you can access the raster tools included in 3D using the _3d suffix.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:23:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431386#M33892</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T19:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431387#M33893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'm trying to do this as a stand alone script and not in the python window.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Should not matter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My guess is your raster is getting saved somewhere (scratch workspace) besides where you think it is. Your script seems to imply that your processing results are expected in "H:/PhD/PythonLessons/Scripts/testIt" but you haven't set the scratch workspace to that location. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For best results when using Spatial Analyst tools its best when they are sent to the same folder:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;from arcpy.env import ENV
ENV.workspace = r"E:\work"
ENV.scratchWorkspace = ENV.workspace
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Setting the current and scratch to the same folder allows temporary grids to be renamed instead of copied - this can save a lot of time with big rasters.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:23:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431387#M33893</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T19:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431388#M33894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, I set &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;env.scratchWorkspace = env.workspace&lt;/PRE&gt;&lt;SPAN&gt; and tried this set up &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outAggreg = Aggregate(catchmentRasterProj, 10, "MEDIAN", "TRUNCATE", "DATA")
 outAggreg.save(catchment100)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;for my spatial analyst tools. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It now gives the error 'failed to open raster dataset'. I'm not sure why it won't open it. I checked that it would open in ArcMap 10 and it does that just fine. I've also checked that the file name is right. I checked the license and that I'd imported the right modules. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, when I run the, as well as an error it creates a new folder within the workspace called 'aggrega_catc1' but I thought that setting the scratch workspace to the env workspace would stop this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:23:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431388#M33894</guid>
      <dc:creator>ElizabethLewis</dc:creator>
      <dc:date>2021-12-11T19:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431389#M33895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp; It now gives the error 'failed to open raster dataset'. I'm not sure why it won't open it. &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To see if it's a path issue, make sure it exists. (If you don't specify a full path, it will look in env.workspace for it.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if not arcpy.exists(catchmentRasterProj): 
&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception, "%s does not exist" % catchmentRasterProj&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the same manner, the output is also written to the current workspace, so instead of&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outFill.save(folderAdd + catchment100Fill)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;you can just specify&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outFill.save(catchment100Fill)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;as well as an error it creates a new folder within the workspace called 'aggrega_catc1' but I thought that setting the scratch workspace to the env workspace would stop this?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is a &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/00p6/00p60000000r000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;temporary raster;&lt;/A&gt;&lt;SPAN&gt; all tools write a temporary raster to the scratch workspace when raster tools run. As I said the point of setting the workspaces the same is so when the tool successfully runs this temp raster is renamed (instead of copied) to your output raster when you execute &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;outraster&lt;/SPAN&gt;&lt;SPAN&gt;.save.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:23:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431389#M33895</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T19:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431390#M33896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried arcpy.Exists and it can find the file so it's not my file path that's wrong. Aggregate still won't open the file raising the error 'failed to open raster dataset'. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for explaining the temporary files.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Mar 2012 07:55:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431390#M33896</guid>
      <dc:creator>ElizabethLewis</dc:creator>
      <dc:date>2012-03-08T07:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431391#M33897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I had been trying to do something similar with the SnapPointPoint. I am converting from the gp to arcpy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What I found was I was trying to create a grid and it didn't like it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So I created a filegeodatabase for my results to go into. This seems to have solved my issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;All of my original data is in GRID from arcgis 9.3&amp;nbsp; I plan to convert it, but I wanted to get the python scripts working first.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Mar 2012 20:12:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431391#M33897</guid>
      <dc:creator>DorothyMortenson</dc:creator>
      <dc:date>2012-03-15T20:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431392#M33898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I had been trying to do something similar with the SnapPointPoint. I am converting from the gp to arcpy.&lt;BR /&gt;What I found was I was trying to create a grid and it didn't like it.&lt;BR /&gt;So I created a filegeodatabase for my results to go into. This seems to have solved my issue.&lt;BR /&gt;All of my original data is in GRID from arcgis 9.3&amp;nbsp; I plan to convert it, but I wanted to get the python scripts working first.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The grid data format is very path sensitive - you need to be very careful to avoid long grid names or names that do not follow the very restrictive grid/coverage naming rules. On the plus side, the grid data format is usually faster to process (though this depends on the tool).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Mar 2012 20:46:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431392#M33898</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-03-15T20:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431393#M33899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've finally resolved this issue. It turns out that the arc modules wouldn't run on the H drive that I was using so I saved everything to the C drive instead and it all ran fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's the code for future reference:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os
import time
import sys
from arcpy import env
from arcpy.sa import *

env.workspace = "C:/temp/testIt"
env.scratchWorkspace = env.workspace
catchmentName = "CatchmentName"
catchmentRaster = catchmentName + ".tif"
catchmentRasterProj = catchmentName + "proj.tif"
catchment100 = catchmentName + "100.tif"
catchment100Fill = catchmentName + "100Fill.tif"
catchment100Flow = catchmentName + "100Flow.tif"
catchment100Acc = catchmentName + "100Acc.tif"
catchment100PP = catchmentName + "100PP.tif"
catchment100WS = catchmentName + "100WS.tif"
folder = "C:/temp/testIt"
folderAdd = "C:/temp/testIt/"
outlet = "outlet.shp"
projection = "C:/Program Files (x86)/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems/National Grids/Europe/British National Grid.prj"
# identify guage
#create pourpoint shapefile
# identify catchment outline
# select appropriate testIt

# have a folder with all of the little ascii testIt for a catchment. This folder will be called *catchment name*
print "checking extensions"

try:
 arcpy.CheckExtension("Spatial") == "Available"
 arcpy.CheckOutExtension("Spatial")
 print "done"
except:
 print "Didn't work!"
 

print "converting the ascii files to raster files"

asciiList = os.listdir(folder)&amp;nbsp;&amp;nbsp;&amp;nbsp; 

for x in range(len(asciiList)-1, -1, -1):
 if not asciiList&lt;X&gt;.endswith(".asc"):
&amp;nbsp;&amp;nbsp; asciiList.pop(x)


for file in asciiList:&amp;nbsp; 
 print folderAdd + file
 print folderAdd + file[:-4]
 
 try:
&amp;nbsp; arcpy.ASCIIToRaster_conversion(folderAdd+ file, folderAdd+ file[:-4] + ".tif", "INTEGER")
 except:
&amp;nbsp; print "Processing " + file + "FAILED"
&amp;nbsp; 
 time.sleep(3)
 
tifList = os.listdir(folder)

print tifList

for x in range(len(tifList) -1, -1, -1):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not tifList&lt;X&gt;.endswith(".tif"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tifList.pop(x)

print tifList

tifString = ""
for tif in tifList:
 tifString += tif + ";"
 
tifString = tifString[:-1]

print tifString

print "mosaic to new raster"

try:
 arcpy.MosaicToNewRaster_management(tifString, folderAdd, catchmentRaster, "#", "16_BIT_SIGNED", "#", "1" , "MEAN")
except:
 print "Error with mosaic to new raster"
 
time.sleep(3)


print "Giving it the right coordinates"
try:
 arcpy.DefineProjection_management(catchmentRaster, projection)
 arcpy.ProjectRaster_management(catchmentRaster, catchmentRasterProj, projection, "BILINEAR", "#", "#","#",projection)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message


time.sleep(3)
 
print "Changing resolution"

try:
 outAggreg = Aggregate(folderAdd + catchmentRasterProj, 10, "MEDIAN", "TRUNCATE", "DATA")
 outAggreg.save(catchment100)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
time.sleep(3)
 
print "Filling sinks"

try:
 outFill = Fill(catchment100)
 outFill.save(catchment100Fill)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
print "Calculating fow direction"

time.sleep(3)

try:
 outFlowDirection = FlowDirection(catchment100Fill, "NORMAL")
 outFlowDirection.save(catchment100Flow)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
 
print "Calculating flow accumulation"

time.sleep(3)

try:
 outFlowAccumulation = FlowAccumulation(catchment100Flow)
 outFlowAccumulation.save(catchment100Acc)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message

print "Creating pour point snap"

time.sleep(3)

try:
 outSnapPour = SnapPourPoint(outlet, catchment100Acc, 5, "FID")
 outSnapPour.save(catchment100PP)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
time.sleep(3)

print "Creating watershed"

try:
 outWatershed = Watershed(catchment100Flow,catchment100PP)
 outWatershed.save(catchment100WS)
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
time.sleep(3)
 
print "Creating files for SHETRAN prepare"

try:
 arcpy.RasterToASCII_conversion(catchment100, catchmentName + "100DEM.txt")
 arcpy.RasterToASCII_conversion(catchment100WS, catchmentName + "100Mask.txt")
except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
 
time.sleep(3)
 
print "Done!"

raw_input("close to exit")
&lt;/X&gt;&lt;/X&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:23:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431393#M33899</guid>
      <dc:creator>ElizabethLewis</dc:creator>
      <dc:date>2021-12-11T19:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Stand alone script fails using spatial analyst tools</title>
      <link>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431394#M33900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm having a very similar problem over a year later -- arcpy.sa modules fail with 999999 errors on the S: drive, but run without issue on C:. I'm experiencing this at ArcGIS 10.0 SP 3 and ArcGIS 10.1 SP 1. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This seems like it should really be a bug report.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jun 2013 15:41:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stand-alone-script-fails-using-spatial-analyst/m-p/431394#M33900</guid>
      <dc:creator>MichaelGleason</dc:creator>
      <dc:date>2013-06-21T15:41:36Z</dc:date>
    </item>
  </channel>
</rss>

