<?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 when using iteration in Zonal table as Statistics in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682893#M52910</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, what does the value of your variable "raster" look like in each of the loops.&lt;/P&gt;&lt;P&gt;Perhaps examine this more carefully.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Jun 2015 09:21:53 GMT</pubDate>
    <dc:creator>NeilAyres</dc:creator>
    <dc:date>2015-06-15T09:21:53Z</dc:date>
    <item>
      <title>Error when using iteration in Zonal table as Statistics</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682889#M52906</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am pretty new in ArcGIS, however I was able to create my script accept the last step.&lt;/P&gt;&lt;P&gt;I am using night lights to get my data. I light data for several years, i want to get my data for each year. I was able to generate iterations and it is working accept last step.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Here is my code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&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 *

arcpy.env.workspace = r"D:\Research-NightLights\yeni"
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Local variables:
Tur_pro_09 = "D:\\Turkey09\\admin\\Turpro09.shp"
Tur_lyr = "D:\\Turkey09\\admin\\Turkey"

Tur_dist_09 = "D:\\Turkey2009\\admin\\Turdist09.shp"

arcpy.MakeFeatureLayer_management(Tur_pro_09, Turkey_lyr)
print "makefeature"

# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management(Tur_lyr, "NEW_SELECTION", "\"ID\" = '01'")
print "attribute"

rasterList = arcpy.ListRasters("f*")
for raster in rasterList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "list"

# Process: Clip (1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_management(raster, "25.665181 35.812875 44.826408 42.104629", "y1"+str(raster[1:]), Tur_lyr, "255", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
print "clip1"

rasterList1 = arcpy.ListRasters("y1*")
for raster in rasterList1:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "list (2)"
&amp;nbsp;&amp;nbsp; 
# Process: Raster to Polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RasterToPolygon_conversion(raster,"y2"+str(raster[1:]), "NO_SIMPLIFY", "Value")
print "polygon"

fcs = arcpy.ListFeatureClasses("y2*", "polygon")
for raster in fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "poly_clip"
&amp;nbsp;&amp;nbsp; 
# Process: Clip (2)
arcpy.Clip_analysis(Tur_dist_09, raster, "y3"+str(raster[1:]), "")
print "clip2"

rasterList3 = arcpy.ListRasters("y1*")
for raster in rasterList3:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "list (3)"

# Process: Zonal Statistics as Table
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.ZonalStatisticsAsTable_sa(Turdist_09, "Name", raster,"j"+str(raster[5:])+".dbf", "DATA", "MEAN")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(raster)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Got zonal stats for "&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Here is the Error I get: (it works perfect until Zonal Statistics as Table step)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; File "C:/Users/Bilalce/Desktop/fully working12.py", line 64, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.ZonalStatisticsAsTable_sa(Turkey_districts_2009, "Name", raster,"j"+str(raster[5:])+".dbf", "DATA", "MEAN")&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in &amp;lt;lambda&amp;gt;&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return lambda *args: val(*gp_fixargs(args, True))&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier;"&gt;ExecuteError: ERROR 999999: Error executing function.&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier;"&gt;Create output table failed&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier;"&gt;Failed to execute (ZonalStatisticsAsTable).&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(Curtis Price added &lt;A href="https://community.esri.com/migration-blogpost/1070" target="_blank"&gt;formatting&lt;/A&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:44:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682889#M52906</guid>
      <dc:creator>bilalcelik1</dc:creator>
      <dc:date>2021-12-12T04:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using iteration in Zonal table as Statistics</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682890#M52907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks to me like the expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14343392314002908" data-renderedposition="50_8_912_16" jivemacro_uid="_14343392314002908"&gt;&lt;P&gt;"j"+str(raster[5:])+".dbf"&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;may be creating an invalid pathname (a common cause of 999999 errors).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, why aren't you simply using this syntax?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14343393826578447 jive_text_macro" data-renderedposition="171_8_912_16" jivemacro_uid="_14343393826578447"&gt;&lt;P&gt;arcpy.sa.ZonalStatisticsAsTable(args)&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 03:36:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682890#M52907</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2015-06-15T03:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using iteration in Zonal table as Statistics</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682891#M52908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I also think it is because of expression&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;"j"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;+str(raster[&lt;/SPAN&gt;&lt;SPAN class="number" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: green;"&gt;5&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;:])+&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;".dbf"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;Like I said I am pretty new. I created my script using model builder. model builder is using &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt; arcpy.gp.ZonalStatisticsAsTable_sa() syntax&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also used help from the script in &lt;A href="http://economics.mit.edu/files/8955" title="http://economics.mit.edu/files/8955"&gt;http://economics.mit.edu/files/8955&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;He is also using&amp;nbsp; &lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;arcpy.gp.ZonalStatisticsAsTable_sa() syntax. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;and I got expression of &lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;"j"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;+str(raster[&lt;/SPAN&gt;&lt;SPAN class="number" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: green;"&gt;5&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;:])+&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;".dbf" &lt;/SPAN&gt;from this the webpage above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't know how to correct the output expression so I can get output for each year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is appreciated. &lt;/P&gt;&lt;P&gt;Thanks in advance. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 04:08:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682891#M52908</guid>
      <dc:creator>bilalcelik1</dc:creator>
      <dc:date>2015-06-15T04:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using iteration in Zonal table as Statistics</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682892#M52909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Moved the thread to the Python space...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 04:36:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682892#M52909</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-06-15T04:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using iteration in Zonal table as Statistics</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682893#M52910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, what does the value of your variable "raster" look like in each of the loops.&lt;/P&gt;&lt;P&gt;Perhaps examine this more carefully.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 09:21:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682893#M52910</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2015-06-15T09:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using iteration in Zonal table as Statistics</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682894#M52911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for your requests. I don't think there are any problem value of the raster in each loop. Here if I don't make any loop in the last step, script works perfectly. Here is the changes that I made to get rid off loop in the last step.&lt;/P&gt;&lt;P&gt;I added two local variable:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;y1121998&lt;/STRONG&gt;="D:\\Research-NightLights\\yeni\\y1121998.tif"&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;zonalst_shp23&lt;/STRONG&gt;="C:\\Users\\Bilalce\\Documents\\ArcGIS\\Default.gdb\\ZonalSt_shp23"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then changed last Zonal Statistics as table step as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Zonal Statistics as Table, and got rid of the loop before zonal statistics as table step.&lt;/P&gt;&lt;P&gt;arcpy.gp.ZonalStatisticsAsTable_sa(Turkey_districts_2009, "Name", &lt;STRONG&gt;y1121998&lt;/STRONG&gt;,&lt;STRONG&gt;zonalst_shp23&lt;/STRONG&gt;, "DATA", "ALL")&lt;/P&gt;&lt;P&gt;arcpy.Delete_management(raster)&lt;/P&gt;&lt;P&gt;print "Got zonal stats for "&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works perfectly. Thus i am thinking, problem is related to expression of &lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;"j"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;+str(raster[&lt;/SPAN&gt;&lt;SPAN class="number" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: green;"&gt;5&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;:])+&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;".dbf".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;But I don't know how to change this expression so I can get output for every year.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 14:27:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682894#M52911</guid>
      <dc:creator>bilalcelik1</dc:creator>
      <dc:date>2015-06-15T14:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using iteration in Zonal table as Statistics</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682895#M52912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, I solved problem. I changed the code in last part as Curtis advice. I used&lt;/P&gt;&lt;P&gt;arcpy.sa.ZonalStatisticsAsTable(Tur_dist_09, "Name", raster,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "j"+str(raster[5:]), "DATA", "ALL")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now it is all good.&lt;/P&gt;&lt;P&gt;Thank you so much&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 15:16:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-iteration-in-zonal-table-as/m-p/682895#M52912</guid>
      <dc:creator>bilalcelik1</dc:creator>
      <dc:date>2015-06-15T15:16:49Z</dc:date>
    </item>
  </channel>
</rss>

