<?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: raster created by arcpy.sa.FocalStatistics cannot be deleted in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/raster-created-by-arcpy-sa-focalstatistics-cannot/m-p/392614#M31053</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you tried deleting your smoothed variable?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Jul 2013 18:03:09 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2013-07-23T18:03:09Z</dc:date>
    <item>
      <title>raster created by arcpy.sa.FocalStatistics cannot be deleted</title>
      <link>https://community.esri.com/t5/python-questions/raster-created-by-arcpy-sa-focalstatistics-cannot/m-p/392613#M31052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've successfully created a raster using&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt; FocalStatisitics&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; smoothed = arcpy.sa.FocalStatistics('input', neighborhood, "MEAN","NODATA") &amp;nbsp; smoothed.save('output.tif')&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that when I try to delete the &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;'output.tif'&lt;/SPAN&gt;&lt;SPAN&gt; file within Python, I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'E:/output.tif'&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem also occurs in an interactive Python session - the file cannot be deleted by Windows Explorer until the PythonWin is closed.&amp;nbsp; I assume the problem is that &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;FocalStatistics&lt;/SPAN&gt;&lt;SPAN&gt; did not close the file it created.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I delete &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;'output.tif'&lt;/SPAN&gt;&lt;SPAN&gt; within Python?&amp;nbsp; I am new to arcpy so I may be missing something obvious.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jul 2013 17:58:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-created-by-arcpy-sa-focalstatistics-cannot/m-p/392613#M31052</guid>
      <dc:creator>PKennedy</dc:creator>
      <dc:date>2013-07-23T17:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: raster created by arcpy.sa.FocalStatistics cannot be deleted</title>
      <link>https://community.esri.com/t5/python-questions/raster-created-by-arcpy-sa-focalstatistics-cannot/m-p/392614#M31053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you tried deleting your smoothed variable?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jul 2013 18:03:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-created-by-arcpy-sa-focalstatistics-cannot/m-p/392614#M31053</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-07-23T18:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: raster created by arcpy.sa.FocalStatistics cannot be deleted</title>
      <link>https://community.esri.com/t5/python-questions/raster-created-by-arcpy-sa-focalstatistics-cannot/m-p/392615#M31054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I've successfully created a raster using&lt;SPAN style="font-style:italic;"&gt; FocalStatisitics&lt;/SPAN&gt;:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp; smoothed = arcpy.sa.FocalStatistics('input', neighborhood, "MEAN","NODATA")
&amp;nbsp; smoothed.save('output.tif')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&lt;BR /&gt;The problem is that when I try to delete the &lt;SPAN style="font-style:italic;"&gt;'output.tif'&lt;/SPAN&gt; file within Python, I get the following error:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The problem also occurs in an interactive Python session - the file cannot be deleted by Windows Explorer until the PythonWin is closed.&amp;nbsp; I assume the problem is that &lt;SPAN style="font-style:italic;"&gt;FocalStatistics&lt;/SPAN&gt; did not close the file it created.&lt;BR /&gt;&lt;BR /&gt;How can I delete &lt;SPAN style="font-style:italic;"&gt;'output.tif'&lt;/SPAN&gt; within Python?&amp;nbsp; I am new to arcpy so I may be missing something obvious.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Or I wonder if a with statement would be appropriate?&amp;nbsp; (not sure if this would work, it is NOT tested), but it should handle the termination for you (from what I've read anyway):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;nbsp; with arcpy.sa.FocalStatistics('input', neighborhood, "MEAN","NODATA") as smoothed:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; smoothed.save('output.tif')

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(someone please correct this if it is wrong.&amp;nbsp; Sorry OP for not testing this, just a quick thought that might work as expected).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:59:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-created-by-arcpy-sa-focalstatistics-cannot/m-p/392615#M31054</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T17:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: raster created by arcpy.sa.FocalStatistics cannot be deleted</title>
      <link>https://community.esri.com/t5/python-questions/raster-created-by-arcpy-sa-focalstatistics-cannot/m-p/392616#M31055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Have you tried deleting your smoothed variable?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks! &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Delete_management&lt;/SPAN&gt;&lt;SPAN&gt; is the answer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What works is the following code: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.Delete_management('output.tif')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My mistake was that I tried deleting &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;smoothed&lt;/SPAN&gt;&lt;SPAN&gt; using &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Delete_management&lt;/SPAN&gt;&lt;SPAN&gt; (but obviously that didn't work). &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 17:59:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-created-by-arcpy-sa-focalstatistics-cannot/m-p/392616#M31055</guid>
      <dc:creator>PKennedy</dc:creator>
      <dc:date>2021-12-11T17:59:39Z</dc:date>
    </item>
  </channel>
</rss>

