<?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: &amp;quot;Failed to open raster dataset&amp;quot; in zonal statistics in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9704#M835</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This what I got when I used &lt;/SPAN&gt;&lt;PRE&gt;arcpy.sa.ZonalStatistics(ZoneShapefile, "FID", inRaster, outRaster, "MEAN", "DATA")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "S:/Work/Risa/Python codes/zonalStats_test.py", line 38, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.sa.ZonalStatistics(ZoneShapefile, "FID", inRaster, outRaster, "MEAN", "DATA")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: ZonalStatistics() takes at most 5 arguments (6 given)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, i can see what you mean by those temporary raster files. That is now a minor problem. The major problem is (I think), the program can't read the raster files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Risa&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Jul 2012 15:29:05 GMT</pubDate>
    <dc:creator>RPatarasuk</dc:creator>
    <dc:date>2012-07-11T15:29:05Z</dc:date>
    <item>
      <title>&amp;quot;Failed to open raster dataset&amp;quot; in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9701#M832</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 am trying to use zonal statistics to calculate the average amount of rainfall for each county. Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Input data source
arcpy.env.workspace = "S:/Work/Risa/Trials_Errors/InputFiles02"
arcpy.env.overwriteOutput = True

ZoneShapefile = "S:/Work/Risa/USA Boundary_AlbersNAD83/PINEMAP_Counties_USCensus.shp"

# Output File
OutputFolder = "S:/Work/Risa/Trials_Errors/ZonalStats"

# Loop through a list of files in the workspace
RasterFiles = arcpy.ListRasters()

# Local variables:
for filename in RasterFiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Processing: " + filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; inRaster = arcpy.env.workspace + "/" + filename
&amp;nbsp;&amp;nbsp;&amp;nbsp; fileroot = filename
&amp;nbsp;&amp;nbsp;&amp;nbsp; outRaster = OutputFolder + "/" + "Avg_" + fileroot + ".tif"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Zonal Statistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.ZonalStatistics_sa(ZoneShapefile, "FID", inRaster, outRaster, "MEAN", "DATA")

print " "
print ":o) End Processing :)"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that when I run it, it creates this error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Processing: ppt_1970_01.tif&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "S:/Work/Risa/Python codes/zonalStats_test.py", line 36, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.gp.ZonalStatistics_sa(ZoneShapefile, "FID", inRaster, outRaster, "MEAN", "DATA")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in &amp;lt;lambda&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; return lambda *args: val(*gp_fixargs(args))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: 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 (ZonalStatistics).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is weird is that every time when I run the program, it creates a raster file in the input folder, which I didn't specify. e.g. "t_t126". If I hit run again, will create another file and so on. These files don't give me the average value by the county either. It gave me a weird number. If the program runs properly, it should create "Avg_ppt_1970_01.tif" in the output folder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, if I run one file at a time (exported from Model Builder), it works fine. Here's the code that works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
PINEMAP_Counties_USCensus = "S:/Work/Risa/USA Boundary_AlbersNAD83/PINEMAP_Counties_USCensus.shp"
arcpy.env.overwriteOutput = True
ppt_1970_01_tif = "S:/Work/Risa/Trials_Errors/InputFiles02/ppt_1970_01.tif"
ZonalSt_shp2 = "S:/Work/Risa/Trials_Errors/ZonalStats/ZonalSt_shp.tif"

# Process: Zonal Statistics
arcpy.gp.ZonalStatistics_sa(PINEMAP_Counties_USCensus, "FID", ppt_1970_01_tif, ZonalSt_shp2, "MEAN", "DATA")

print "Done!"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I don't get it why it says "Failed to open raster dataset".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here are the sample files (see the attachments)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thoughts and help would be pretty much appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 15:54:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9701#M832</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2021-12-12T15:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9702#M833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd imagine those rasters you are seeing are intermediate data that isn't cleaned up when it crashes since you specified your input directory as your working directory, all intermediate data will be created there. Also, I am not sure how you are accessing your ZonalStatistics tool since it isn't under the gp, it is under sa. The tool call should look like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.sa.ZonalStatistics(...)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you running this from inside an Arc session or stand alone?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 15:00:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9702#M833</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-07-11T15:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9703#M834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for the suggestion. Let me try that. I am running it as a stand alone script. I exported the script ("arcpy.gp.ZonalStatistics_sa") from the Model Maker. So, you are saying that I should have a scratch workspace folder, right?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 15:13:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9703#M834</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2012-07-11T15:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9704#M835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This what I got when I used &lt;/SPAN&gt;&lt;PRE&gt;arcpy.sa.ZonalStatistics(ZoneShapefile, "FID", inRaster, outRaster, "MEAN", "DATA")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "S:/Work/Risa/Python codes/zonalStats_test.py", line 38, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.sa.ZonalStatistics(ZoneShapefile, "FID", inRaster, outRaster, "MEAN", "DATA")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: ZonalStatistics() takes at most 5 arguments (6 given)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, i can see what you mean by those temporary raster files. That is now a minor problem. The major problem is (I think), the program can't read the raster files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Risa&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 15:29:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9704#M835</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2012-07-11T15:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9705#M836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Dear Matt,&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;This what I got when I used&amp;nbsp;&amp;nbsp; &lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.sa.ZonalStatistics(ZoneShapefile, "FID", inRaster, outRaster, "MEAN", "DATA")&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;Traceback (most recent call last):&lt;BR /&gt; File "S:/Work/Risa/Python codes/zonalStats_test.py", line 38, in &amp;lt;module&amp;gt;&lt;BR /&gt; arcpy.sa.ZonalStatistics(ZoneShapefile, "FID", inRaster, outRaster, "MEAN", "DATA")&lt;BR /&gt;TypeError: ZonalStatistics() takes at most 5 arguments (6 given)&lt;/SPAN&gt; &lt;BR /&gt; &lt;BR /&gt;Now, i can see what you mean by those temporary raster files. That is now a minor problem. The major problem is (I think), the program can't read the raster files.&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;Risa&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Oh right you are using the wrong syntax. ZonalStats returns a raster that you have to then save.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z000000w7000000.htm" rel="nofollow"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z000000w7000000.htm&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 15:31:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9705#M836</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-07-11T15:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9706#M837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Well, how come arcpy.gp.ZonalStatistics_sa(...) works? in a simple program like this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
PINEMAP_Counties_USCensus = "S:/Work/Risa/USA Boundary_AlbersNAD83/PINEMAP_Counties_USCensus.shp"
arcpy.env.overwriteOutput = True
ppt_1970_01_tif = "S:/Work/Risa/Trials_Errors/InputFiles02/ppt_1970_01.tif"
ZonalSt_shp2 = "S:/Work/Risa/Trials_Errors/ZonalStats/ZonalSt_shp.tif"

print "reading file"

# Process: Zonal Statistics
arcpy.gp.ZonalStatistics_sa(PINEMAP_Counties_USCensus, "ZoneField", ppt_1970_01_tif, ZonalSt_shp2, "MEAN", "DATA")

print "Done!"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so, how come when I set a loop through the files, it doesn't work?!?!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my modify code which doesn't work. I had three types of zonalstats commands and none of them works. I put "#" at the front for the time being.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Input data source
arcpy.env.workspace = "S:/Work/Risa/Trials_Errors/InputFiles02"
arcpy.env.scratchWorkspace = "S:/Work/Risa/Trials_Errors/ScratchWorkSpace"
arcpy.env.overwriteOutput = True

ZoneData = "S:/Work/Risa/USA Boundary_AlbersNAD83/PINEMAP_Counties_USCensus.shp"

# Output File
OutputFolder = "S:/Work/Risa/Trials_Errors/ZonalStats"

# Loop through a list of files in the workspace
RasterFiles = arcpy.ListRasters()
print RasterFiles

# Local variables:
for filename in RasterFiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Processing: " + filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; inRaster = arcpy.env.workspace + "/" + filename
&amp;nbsp;&amp;nbsp;&amp;nbsp; fileroot = filename
&amp;nbsp;&amp;nbsp;&amp;nbsp; outRaster = OutputFolder + "/" + "Avg_" + fileroot + ".tif"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Zonal Statistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.gp.ZonalStatistics_sa(ZoneData, "ZoneField", inRaster, outRaster, "MEAN", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.sa.ZonalStatistics(ZoneData, "ZoneField", inRaster, "MEAN", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outZonalStatistics = ZonalStatistics(ZoneData, "ZoneField", inRaster, "MEAN", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Copy Raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outZonalStatistics.save(OutputFolder + outRaster)

&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print " "
print ":o) End Processing :)"
print arcpy.GetMessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:24:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9706#M837</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2021-12-10T20:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9707#M838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you getting the same error?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this as your loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for filename in RasterFiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing: {0}".format(filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; inRaster = os.path.join(input_dir,filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; outRaster = os.path.join(OutputFolder,"Avg_" + filename)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Zonal Statistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; saveRaster = arcpy.sa.ZonalStatistics(ZoneShapefile, "FID", inRaster, "MEAN", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; saveRaster.save(outRaster)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:24:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9707#M838</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-10T20:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9708#M839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry, I am new to Python. I tried the loop that you gave me but it still gives me the same errors. Here is the code that I put together: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy, os
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Input data source
arcpy.env.workspace = "S:/Work/Risa/Trials_Errors/InputFiles02"
arcpy.env.scratchWorkspace = "S:/Work/Risa/Trials_Errors/ScratchWorkSpace"
arcpy.env.overwriteOutput = True

ZoneData = "S:/Work/Risa/USA Boundary_AlbersNAD83/PINEMAP_Counties_USCensus.shp"

# Output File
OutputFolder = "S:/Work/Risa/Trials_Errors/ZonalStats"

# Loop through a list of files in the workspace
RasterFiles = arcpy.ListRasters()
print RasterFiles
print " "

# Local variables:
for filename in RasterFiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing: {0}".format(filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; input_dir = arcpy.env.workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; inRaster = os.path.join(input_dir,filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; outRaster = os.path.join(OutputFolder,"Avg_" + filename)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Zonal Statistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; saveRaster = arcpy.sa.ZonalStatistics(ZoneData, "ZoneField", inRaster, "MEAN", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; saveRaster.save(outRaster)

print " "
print ":o) End Processing :)"
print arcpy.GetMessages()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is the error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;[u'ppt_1970_03.tif', u'ppt_1970_04.tif', u'ppt_1970_05.tif']
 
Processing: ppt_1970_03.tif

Traceback (most recent call last):
&amp;nbsp; File "S:/Work/Risa/Python codes/zonalStats_test02.py", line 39, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; saveRaster = arcpy.sa.ZonalStatistics(ZoneData, "ZoneField", inRaster, "MEAN", "DATA")
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 5787, in ZonalStatistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; ignore_nodata)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Utils.py", line 47, in swapper
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = wrapper(*args, **kwargs)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 5780, in wrapper
&amp;nbsp;&amp;nbsp;&amp;nbsp; ignore_nodata)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in &amp;lt;lambda&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lambda *args: val(*gp_fixargs(args))
ExecuteError: ERROR 999999: Error executing function.
Failed to open raster dataset
Failed to execute (ZonalStatistics).&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thank you very much for your help. I will post the previous code and error message shortly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Risa&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:24:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9708#M839</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2021-12-10T20:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9709#M840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;so for this code&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Input data source
arcpy.env.workspace = "S:/Work/Risa/Trials_Errors/InputFiles02"
arcpy.env.scratchWorkspace = "S:/Work/Risa/Trials_Errors/ScratchWorkSpace"
arcpy.env.overwriteOutput = True

ZoneData = "S:/Work/Risa/USA Boundary_AlbersNAD83/PINEMAP_Counties_USCensus.shp"

# Output File
OutputFolder = "S:/Work/Risa/Trials_Errors/ZonalStats"

# Loop through a list of files in the workspace
RasterFiles = arcpy.ListRasters()
print RasterFiles
print " "

# Local variables:
for filename in RasterFiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Processing: " + filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; inRaster = arcpy.env.workspace + "/" + filename
&amp;nbsp;&amp;nbsp;&amp;nbsp; fileroot = filename
&amp;nbsp;&amp;nbsp;&amp;nbsp; outRaster = OutputFolder + "/" + "Avg_" + fileroot + ".tif"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Zonal Statistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; outZonalStatistics = arcpy.sa.ZonalStatistics(ZoneData, "ZoneField", inRaster, "MEAN", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Copy Raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; outZonalStatistics.save(outRaster)

print " "
print ":o) End Processing :)"
print arcpy.GetMessages()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it gives me this error, which is pretty much the same as before:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; ================================ RESTART ================================
&amp;gt;&amp;gt;&amp;gt; 
[u'ppt_1970_03.tif', u'ppt_1970_04.tif', u'ppt_1970_05.tif']
 
Processing: ppt_1970_03.tif

Traceback (most recent call last):
&amp;nbsp; File "S:\Work\Risa\Python codes\zonalStats_test.py", line 39, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; outZonalStatistics = arcpy.sa.ZonalStatistics(ZoneData, "ZoneField", inRaster, "MEAN", "DATA")
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 5787, in ZonalStatistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; ignore_nodata)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Utils.py", line 47, in swapper
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = wrapper(*args, **kwargs)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 5780, in wrapper
&amp;nbsp;&amp;nbsp;&amp;nbsp; ignore_nodata)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in &amp;lt;lambda&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lambda *args: val(*gp_fixargs(args))
ExecuteError: ERROR 999999: Error executing function.
Failed to open raster dataset
Failed to execute (ZonalStatistics).

&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:24:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9709#M840</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2021-12-10T20:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9710#M841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;and for this&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it gives me&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Input data source
arcpy.env.workspace = "S:/Work/Risa/Trials_Errors/InputFiles02"
arcpy.env.scratchWorkspace = "S:/Work/Risa/Trials_Errors/ScratchWorkSpace"
arcpy.env.overwriteOutput = True

ZoneData = "S:/Work/Risa/USA Boundary_AlbersNAD83/PINEMAP_Counties_USCensus.shp"

# Output File
OutputFolder = "S:/Work/Risa/Trials_Errors/ZonalStats"

# Loop through a list of files in the workspace
RasterFiles = arcpy.ListRasters()
print RasterFiles
print " "

# Local variables:
for filename in RasterFiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Processing: " + filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; inRaster = arcpy.env.workspace + "/" + filename
&amp;nbsp;&amp;nbsp;&amp;nbsp; fileroot = filename
&amp;nbsp;&amp;nbsp;&amp;nbsp; outRaster = OutputFolder + "/" + "Avg_" + fileroot + ".tif"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Zonal Statistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.ZonalStatistics_sa(ZoneData, "ZoneField", inRaster, outRaster, "MEAN", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print " "
print ":o) End Processing :)"
print arcpy.GetMessages()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; ================================ RESTART ================================
&amp;gt;&amp;gt;&amp;gt; 
[u'ppt_1970_03.tif', u'ppt_1970_04.tif', u'ppt_1970_05.tif']
 
Processing: ppt_1970_03.tif

Traceback (most recent call last):
&amp;nbsp; File "S:\Work\Risa\Python codes\zonalStats_test.py", line 39, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.ZonalStatistics_sa(ZoneData, "ZoneField", inRaster, outRaster, "MEAN", "DATA")
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in &amp;lt;lambda&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lambda *args: val(*gp_fixargs(args))
ExecuteError: ERROR 999999: Error executing function.
Failed to open raster dataset
Failed to execute (ZonalStatistics).

&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:24:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9710#M841</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2021-12-10T20:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9711#M842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not sure what your issue would be here. This method works for me. I came across this old forum thread with a similar issue, could it be related?&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=995&amp;amp;t=283135"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=995&amp;amp;t=283135&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2012 15:11:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9711#M842</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-07-12T15:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9712#M843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yep, I saw that post. I will change the computer and see if it works. Wow..ESRI bugging problems are a waste of time!! I will let you know if it works or not. Thank you so much.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Risa&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2012 15:32:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9712#M843</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2012-07-12T15:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9713#M844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;HI Matt, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;yeah...i changed the computer and it is still gives me the same error. Hopefully, someone else will&amp;nbsp; comment on my post.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to specify the individual filename and it doesn't read the file name, it reads as 'band 1', which is weird. I changed this line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.env.workspace = "S:/Work/Risa/Trials_Errors/InputFiles02/ppt_1971_07.tif"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and the output is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;[u'Band_1']
 
Processing: Band_1

Traceback (most recent call last):
&amp;nbsp; File "S:\Work\Risa\Python codes\zonalStats_test02.py", line 39, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; saveRaster = arcpy.sa.ZonalStatistics(ZoneData, "ZoneField", inRaster, "MEAN", "DATA")
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 5787, in ZonalStatistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; ignore_nodata)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Utils.py", line 47, in swapper
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = wrapper(*args, **kwargs)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 5780, in wrapper
&amp;nbsp;&amp;nbsp;&amp;nbsp; ignore_nodata)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in &amp;lt;lambda&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lambda *args: val(*gp_fixargs(args))
ExecuteError: ERROR 999999: Error executing function.
Failed to open raster dataset
Failed to execute (ZonalStatistics).&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:24:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9713#M844</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2021-12-10T20:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: "Failed to open raster dataset" in zonal statistics</title>
      <link>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9714#M845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code works but I had to move the files to the local drive. I think there might be something wrong with the program reading from our server. Thank you very much for your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Risa&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2012 18:02:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/amp-quot-failed-to-open-raster-dataset-amp-quot-in/m-p/9714#M845</guid>
      <dc:creator>RPatarasuk</dc:creator>
      <dc:date>2012-07-13T18:02:26Z</dc:date>
    </item>
  </channel>
</rss>

