Select to view content in your preferred language

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

13108
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
JamieKass
Regular Contributor
Thank you very much, Chris. I apologize for the false accusation! Your method worked perfectly, but I wonder what caused the gdb to compress itself, as I never ran code to specifically do that. All I did was open a search cursor, make some selections, and export new fcs. Can compression occur as a side-effect of another process?
0 Kudos
ChrisSnyder
Honored Contributor
Can compression occur as a side-effect of another process?


Not that I know of.
0 Kudos
JamieKass
Regular Contributor
Spoke too soon... The uncompress method worked like a charm the first time, but as other users found earlier, the loop fails midway at a random step and calls the "Workspace or data source is read only" error. I made sure to delete my row and cursor objects, which make the workspace read-only, and haven't had this issue with any tool besides Zonal Statistics as Table. Any ESRI folks know what the issue is?
0 Kudos
JoelThomas
Emerging Contributor
I'm having this problem also (doing a zonal stats as table process). It errors out (the same error as posted above) in the MXD; the workaround for me is doing it out of catalog. Works like a charm there. Still, its frustrating not knowing what is causing it to bomb in the MXD.
0 Kudos