<?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: Error looping Zonal Statistics as Table in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-looping-zonal-statistics-as-table/m-p/579497#M45440</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anne, it would be useful to throw in a couple of print statements so people can see the actual names for the zonalstats input/output&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Aug 2019 01:51:57 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2019-08-01T01:51:57Z</dc:date>
    <item>
      <title>Error looping Zonal Statistics as Table</title>
      <link>https://community.esri.com/t5/python-questions/error-looping-zonal-statistics-as-table/m-p/579496#M45439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the bug in this scenario? I have used the following bit of code (last chunk in a long script) 5 times successfully (on 5 different batches of rasters) and now the 6th time it refuses to work, alternately giving me error 000354: "The name contains invalid characters", or 99999: "Something unexpected caused the tool to fail", depending on how I try to fix it.&lt;/P&gt;&lt;P&gt;Aim: Run Zonal Statistics as Table on time series batches of binary threshold rasters to observe growth of plants.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got it to run smoothly following this post:&amp;nbsp;&lt;A href="https://gis.stackexchange.com/questions/206559/python-script-zonal-stats-as-table-loop-question" rel="nofollow noopener noreferrer" target="_blank"&gt;https://gis.stackexchange.com/questions/206559/python-script-zonal-stats-as-table-loop-question&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only change I can see in this latest batch of rasters it that my "zones" shapefile exceeds 36KB. There are no Null values in "Id", the fieldname is not longer than 17 characters, there are only 2 values present in the rasters (binary otsu threshold), and the feature zone dataset is comprised of 276 zones, far less than the 170,000 features at which problems are supposed to present themselves. I tried all the solutions and workarounds found here:&amp;nbsp;&lt;A href="https://support.esri.com/en/technical-article/000012343" rel="nofollow noopener noreferrer" target="_blank"&gt;https://support.esri.com/en/technical-article/000012343&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Any suggestions are more than welcome.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The code snippet:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;os, glob, shutil, arcpy, cv2
&lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;numpy &lt;SPAN style="color: #000080; font-weight: bold;"&gt;as &lt;/SPAN&gt;np
&lt;SPAN style="color: #000080; font-weight: bold;"&gt;from &lt;/SPAN&gt;arcpy &lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;env
&lt;SPAN style="color: #000080; font-weight: bold;"&gt;from &lt;/SPAN&gt;arcpy.sa &lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;*
&lt;SPAN style="color: #000080; font-weight: bold;"&gt;from &lt;/SPAN&gt;arcpy &lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;UpdateCursor
env.overwriteOutput = &lt;SPAN style="color: #000080; font-weight: bold;"&gt;True&lt;/SPAN&gt;

&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808080;"&gt;#Create table of stats for each threshold using vectorized tray zones
&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;try&lt;/SPAN&gt;:
    env.workspace = &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"O:/NeilsonJ/Image_Processing/Working/150719/6.Scaled"
&lt;/SPAN&gt;&lt;SPAN style="color: #008080; font-weight: bold;"&gt;    &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;raster &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;arcpy.ListRasters():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print (raster)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;run9_1_2019-15-28-10-52_dist_NXG_OTSU_scaled.tif
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run9_1_2019-15-28-11-52_dist_NXG_OTSU_scaled.tif
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;run9_1_2019-15-28-12-52_dist_NXG_OTSU_scaled.tif
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;run9_1_2019-15-28-13-52_dist_NXG_OTSU_scaled.tif
        outDir = &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"O:/NeilsonJ/Image_Processing/Working/150719/7.Tables"
&lt;/SPAN&gt;&lt;SPAN style="color: #008080; font-weight: bold;"&gt;        &lt;/SPAN&gt;inZoneData = &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"O:/NeilsonJ/Image_Processing/Working/150719/150719_tray.shp"
&lt;/SPAN&gt;&lt;SPAN style="color: #008080; font-weight: bold;"&gt;        &lt;/SPAN&gt;raster_name = os.path.basename(raster).rstrip(os.path.splitext(raster)[&lt;SPAN style="color: #0000ff;"&gt;1&lt;/SPAN&gt;])
        outTable = os.path.join(outDir, raster_name +&lt;SPAN style="color: #008080; font-weight: bold;"&gt;".dbf"&lt;/SPAN&gt;)
        arcpy.gp.ZonalStatisticsAsTable(inZoneData, &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"Id"&lt;/SPAN&gt;, raster, outTable, &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"NODATA"&lt;/SPAN&gt;, &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"ALL"&lt;/SPAN&gt;)
&lt;SPAN style="color: #000080; font-weight: bold;"&gt;except&lt;/SPAN&gt;:
    &lt;SPAN style="color: #000080;"&gt;print &lt;/SPAN&gt;(&lt;SPAN style="color: #008080; font-weight: bold;"&gt;"Script failed to complete"&lt;/SPAN&gt;)
    &lt;SPAN style="color: #000080;"&gt;print &lt;/SPAN&gt;(arcpy.GetMessages(&lt;SPAN style="color: #0000ff;"&gt;2&lt;/SPAN&gt;))

Script failed to complete
ERROR 000354: The name contains invalid characters
Failed to execute (ZonalStatisticsAsTable).

&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;##WHEN IT WORKS (19513_195514 has already been completed)
&lt;/SPAN&gt;env.workspace = &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"O:/NeilsonJ/Image_Processing/Working/19513_19514/7.Tables"
&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;table &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;arcpy.ListTables():
    &lt;SPAN style="color: #000080;"&gt;print &lt;/SPAN&gt;(table)
run7_27__dist_NXG_OTSU_scaled.dbf
run7_21__dist_NXG_OTSU_scaled.dbf
run7_7__dist_NXG_OTSU_scaled.dbf
run7_33__dist_NXG_OTSU_scaled.dbf&lt;/PRE&gt;&lt;/PRE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:55:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-looping-zonal-statistics-as-table/m-p/579496#M45439</guid>
      <dc:creator>AnneFarineau1</dc:creator>
      <dc:date>2021-12-12T00:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Error looping Zonal Statistics as Table</title>
      <link>https://community.esri.com/t5/python-questions/error-looping-zonal-statistics-as-table/m-p/579497#M45440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anne, it would be useful to throw in a couple of print statements so people can see the actual names for the zonalstats input/output&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Aug 2019 01:51:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-looping-zonal-statistics-as-table/m-p/579497#M45440</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-08-01T01:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Error looping Zonal Statistics as Table</title>
      <link>https://community.esri.com/t5/python-questions/error-looping-zonal-statistics-as-table/m-p/579498#M45441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan, good idea, put them in there. Just noticed - none of the completed projects have dashes in the file names but the new one does. I just tried replacing all the hyphens with underscore and it worked like a charm. Thanks for pointing me in the right direction!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Aug 2019 16:30:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-looping-zonal-statistics-as-table/m-p/579498#M45441</guid>
      <dc:creator>AnneFarineau1</dc:creator>
      <dc:date>2019-08-01T16:30:42Z</dc:date>
    </item>
  </channel>
</rss>

