Select to view content in your preferred language

ERROR 999999: Error executing function. A column was specified that does not exist.

12384
13
05-19-2011 02:26 PM
kristinavucic
Emerging Contributor
I have the following script. Sometimes it runs and sometimes it does not. I think it might be the search cursor causing problems, but I am not sure. Other people, who do not have  GIS background knowledge will be running this scipt so I need it to work all the time, not just some of the time. The script works fine as long as I run my scripts one after another and don't touch anything. If I remove everything from the table of contents and add it again, the error occurs.

Does anyone have any suggestions how to fix it or what to do so that it always runs?

I really appriciate the help. Sorry the script is a little long:

 
# ---------------------------------------------------------------------------
# NeighbourhoodSelect.py
# Created on: 2011-04-21 12:32:34.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: This script asks the user to input the geodatabase, Neighbourhood feature class
# and the CalcPop feature class. A GUI appears which asks the user to select a
# neighbourhood. Once the neighbbourhood is selected, the attributes from the CalcPop feature
# class are joined to the selected neighbourhood and a new feature class, containing only the
# the information for that neighbourhood is created.
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy, sys, os

from Tkinter import *

Title = "Neighbourhoods"

arcpy.env.workspace = sys.argv[1]

# Local variables:
Layer = sys.argv[2]
out_select = "selection"
Parcel_fc = sys.argv[3]

SelField = "NeighbourhoodName"
arcpy.env.overwriteOutput = True

#Create a GUI containing a listbox and buttons
class Application (Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.grid()
        self.createWidgets(master)
        
    def createWidgets(self, master):
        self.yScroll1 = Scrollbar ( self, orient=VERTICAL )
        self.yScroll1.grid ( row=0, column=1, sticky=N+S )
        self.stList = Listbox (self, yscrollcommand=self.yScroll1.set)
        self.stList.grid(row=0, column=0, sticky=EW)
        self.yScroll1["command"] = self.stList.yview
        #Populate list with choices in ascending order
        mxd=arcpy.mapping.MapDocument("C:\\Users\\me\\Desktop\\Project\\TEST\\POP.mxd")
        for lyr in arcpy.mapping.ListLayers(mxd):
            if lyr.name == Layer:
                break
        SelTable = lyr.dataSource
        rows = arcpy.SearchCursor(SelTable, "", "", SelField, SelField + " A")
        oldVal = ""
        for row in rows:
            newVal = row.getValue(SelField)
            #only add value to Listbox if it is not a duplicate
            if newVal <> oldVal:
                self.stList.insert( END, row.getValue(SelField) )
            oldVal = newVal

        #add selection and quit buttons
        self.selButton1=Button(self,text='Submit', command=self.selectNeighbourhood)
        self.selButton1.grid(row=0,column=2, sticky=N+ EW)
        self.quitButton = Button(self, text='Exit', command=master.destroy)
        self.quitButton.grid(row=0,column=2, sticky= S+EW)


    def selectNeighbourhood(self):
        sel = self.stList.curselection()

        
        try:
            myFeature = self.stList.get(sel[0])
            
            where_clause = "\"" + SelField + "\" = " + "'" + str(myFeature) + "'" 
            arcpy.Select_analysis(Layer, out_select, where_clause)
            print where_clause
            myFeature = myFeature.replace(' ', '_')
            
            # Process: Intersect
            inFeatures = [out_select, Parcel_fc]
            neighbourhoods_Intersect = myFeature                
            arcpy.Intersect_analysis(inFeatures, neighbourhoods_Intersect, "ALL", "", "INPUT")
            arcpy.AddMessage("Intersect Complete")
            NI_lyr = '"' + neighbourhoods_Intersect + '"'
            arcpy.MakeFeatureLayer_management(neighbourhoods_Intersect, NI_lyr)
            arcpy.AddMessage("layer created")
            arcpy.Delete_management(out_select)
            arcpy.env.overwriteOutput = True

            #stats = myFeature
            unique_name = arcpy.CreateUniqueName(neighbourhoods_Intersect)

            # Process: Summary Statistics
            arcpy.Statistics_analysis(neighbourhoods_Intersect, unique_name, "CurrentPop SUM", "CurrentPop")

            # Process: Add Field
            arcpy.AddField_management(unique_name, "Total_Population", "DOUBLE", "", "", "", "", "NULLABLE", "REQUIRED", "")
            arcpy.AddMessage("Field is Added")

            rows = arcpy.SearchCursor(unique_name, "", "", "SUM_CurrentPop")
            NewList= []
            for row in rows:
                row = row.getValue("SUM_CurrentPop")
                if row != None:
                    print row
                    NewList.append(row)
            total = sum(NewList)
            print total

            arcpy.CalculateField_management(unique_name, "Total_Population", total, "PYTHON")
            arcpy.AddMessage("All processes are completed. Please close GUI")

        except Exception, e:
            tb = sys.exc_info()[2]
            print "Line %i" % tb.tb_lineno
            print e.message

root = Tk()
app = Application(master=root)
app.master.title(Title)
app.mainloop()
Tags (2)
0 Kudos
13 Replies
DanPatterson_Retired
MVP Emeritus
Is there any way you could edit your post and enclose the code in a code (the # symbol in the html editor) to make it easier to read?
0 Kudos
kristinavucic
Emerging Contributor
Sorry! here it is.
0 Kudos
MathewCoyle
Honored Contributor
You might have some issues in your SQL formatting for your SelField between different data types. Differences between shapefile, personal or file GDB for example.

See this for more info on it http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s500000033000000.htm

Edit: But you don't really have any SQL in there so that probably isn't it. Does it only bomb out when you remove and readd the same layer? Under what other conditions does it not work? Have you tried running it as a stand-alone script with hard coded values and use a debugger to trace the problem?
0 Kudos
percyrojas
Deactivated User
Hi, i´m peruvian, i have a posible solution:

1. Remove any special caracter of SHP file name [.][,][other] example: name.1.3.shp --> name.shp
2. Export to Data, Single GDB, etc.
3. enjoy!!
0 Kudos
DagnachewLegesse
Emerging Contributor
I am having this exact problem while using an arcscript to do Zonal Statistics or resampling of large raster datasets. Sometimes it works without a hitch and sometimes it fails with the message:
ERROR 999999: Error executing function.
Workspace or data source is read only.
Workspace or data source is read only. [The C:\Data2011\DATA\CRU3\hru\ workspace is read only.]
ERROR 010067: Error in executing grid expression. Zonal statistics program failed
Failed to execute (ZonalStatisticsAsTable).
It is really weird. I modify the code so that it restarts from where it failed in the RasterLists and it works without any problem again until another random same error.
It stops randomly. When rerun, it stops at another file location...

Any help is appreciated as it is really frustratin.
0 Kudos
JoannaWhittier
Regular Contributor
Did you ever resolve this issue?  I am fighting the same problem.
0 Kudos
ChrisSnyder
Honored Contributor
This issue can happen if you create a feature layer (MakeFeatureLayer tool) from a a featureclass, add and populate a field to the featureclass, and then **for example** attempt to use the featurelayer as input to the Dissolve tool specifying the newly added field as the Dissolve field.

The basic issue is that the feature layer is sort of like an in-memory snapshot reference to the featureclass. If the featureclass grows a soul patch and dyes its hair green, the feature layer (being a snapshot of sorts) is not aware of the change.

To refresh the feature layer, just create it again (overwrite the old one) after you have added the field... or better yet, don't create it until your table schema is in it's final state.

BTW: The issue can happen with a table/table view just the same.
0 Kudos
JamieKass
Regular Contributor
Yes, but that does not answer the question for the problem with Zonal Stats. I got the same error, running a script with zstats as table in a loop. I tried it with feature classes as inputs, and then with rasters, and both times I received:

Workspace or data source is read only.
Workspace or data source is read only. [The C:\Users\Jamie\Documents\ArcGIS\zstats.gdb workspace is read only.]
ERROR 010067: Error in executing grid expression. Zonal statistics program failed
Failed to execute (ZonalStatisticsAsTable).

Any idea why this might occur? Thank you.
0 Kudos
ChrisSnyder
Honored Contributor
Yes, but that does not answer the question for the problem with Zonal Stats.


Actually, for the original question posted, I did offer a plausable explaination for the error message (ERROR 999999: A column was specified that does not exist).

For your error message, which is different than the error message in the original post, I speculate that you might have compressed your FGDB. Running the Compress FGDB tool (instead of a Compact) makes the FGDB read only. Try running the Uncompress FGDB tool on your .gdb, and see if you are then able to run the Zonal Stats tool.
0 Kudos