<?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: ZonalStatistics Generates temporary files in scratch workspace and not memory? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/zonalstatistics-generates-temporary-files-in/m-p/270207#M20831</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Michalis,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should be able to specify the output raster parameter if you call the 'arcpy.gp.ZonalStatistics' function.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Local variables:
int_example1 = "C:\\DATA\\RASTER\\DEM\\int_example1"
example = "C:\\temp\\python\\zones.tif"
ZonalSt_int_1 = "C:\\temp\\python\\zonal_stats.tif"

# Process: Zonal Statistics
arcpy.gp.ZonalStatistics_sa(int_example1, "VALUE", example, &lt;STRONG&gt;ZonalSt_int_1&lt;/STRONG&gt;, "MEAN", "DATA")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, if you call the 'arcpy.sa.ZonalStatistics' function the raster will be written to a scratch workspace.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Local variables:
int_example1 = "C:\\DATA\\RASTER\\DEM\\int_example1"
example = "C:\\temp\\python\\zones.tif"
ZonalSt_int_1 = "C:\\temp\\python\\zonal_stats.tif"

# Process: Zonal Statistics
stats = arcpy.sa.ZonalStatistics(int_example1, "VALUE", example, "MEAN", "NODATA")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The raster will be removed from the scratch workspace if you save a hard copy.&amp;nbsp; For example you would add the following at the end:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
stats.save(r"C:\temp\python\Zonal_Stats.tif")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would recommend setting 'arcpy.env.overwriteOutput = True' and using the 'arcpy.gp.ZonalStatistics_sa' function.&amp;nbsp; With this function you can easily specify where you want the raster written to, and you can overwrite the output raster each time.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 13:12:55 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-11T13:12:55Z</dc:date>
    <item>
      <title>ZonalStatistics Generates temporary files in scratch workspace and not memory?</title>
      <link>https://community.esri.com/t5/python-questions/zonalstatistics-generates-temporary-files-in/m-p/270206#M20830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am attempting to run ZonalStatistics on a number of generated buffers (around 100,000) and record my results in a table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have managed to restrict myself to memory mostly, meaning the buffer files are generated in memory, passed on to ZonalStatistics as a memory feature class and it runs great. My problem is that zonal statistics, while it returns a variable to use in Python, also generates files in the scratch workspace. This is a big problem, as I run multiple zonal statistics per buffer (multiple source rasters) and with 100,000 buffers, this becomes a very big bottleneck for me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any way to set the output of Zonal Statistics to be completely in memory? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or to set the whole scratch workspace in memory? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know that the arcpy.gp.ZonalStatistics_sa that is called when you call zonal statistics has an out_raster parameter, but it is hard coded to "#" so i can't change it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you in advance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michalis&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Dec 2011 15:06:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonalstatistics-generates-temporary-files-in/m-p/270206#M20830</guid>
      <dc:creator>MichalisAvraam</dc:creator>
      <dc:date>2011-12-30T15:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: ZonalStatistics Generates temporary files in scratch workspace and not memory?</title>
      <link>https://community.esri.com/t5/python-questions/zonalstatistics-generates-temporary-files-in/m-p/270207#M20831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Michalis,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should be able to specify the output raster parameter if you call the 'arcpy.gp.ZonalStatistics' function.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Local variables:
int_example1 = "C:\\DATA\\RASTER\\DEM\\int_example1"
example = "C:\\temp\\python\\zones.tif"
ZonalSt_int_1 = "C:\\temp\\python\\zonal_stats.tif"

# Process: Zonal Statistics
arcpy.gp.ZonalStatistics_sa(int_example1, "VALUE", example, &lt;STRONG&gt;ZonalSt_int_1&lt;/STRONG&gt;, "MEAN", "DATA")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, if you call the 'arcpy.sa.ZonalStatistics' function the raster will be written to a scratch workspace.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Local variables:
int_example1 = "C:\\DATA\\RASTER\\DEM\\int_example1"
example = "C:\\temp\\python\\zones.tif"
ZonalSt_int_1 = "C:\\temp\\python\\zonal_stats.tif"

# Process: Zonal Statistics
stats = arcpy.sa.ZonalStatistics(int_example1, "VALUE", example, "MEAN", "NODATA")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The raster will be removed from the scratch workspace if you save a hard copy.&amp;nbsp; For example you would add the following at the end:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
stats.save(r"C:\temp\python\Zonal_Stats.tif")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would recommend setting 'arcpy.env.overwriteOutput = True' and using the 'arcpy.gp.ZonalStatistics_sa' function.&amp;nbsp; With this function you can easily specify where you want the raster written to, and you can overwrite the output raster each time.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:12:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zonalstatistics-generates-temporary-files-in/m-p/270207#M20831</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T13:12:55Z</dc:date>
    </item>
  </channel>
</rss>

