champaganeca

FeatureLayer/Feature class definition in script

Discussion created by champaganeca on May 20, 2011
Latest reply on May 20, 2011 by bruce.nielsen
Hello,

I am struggling with a very simple script to join a dbf table to a shapefile, export the table and remove the join (I would like to iterate this - but I can't seem to get the basic functions working). I am getting various errors that seem to be related to defining my inputs as feature layers - it seems I need to define my input shapefile as a feature layer, but then this layer seems to persist in memory even though it is virtual (ie if I run the script more than once, I get an error that my new feature layer already exists). My second problem is that when I get to the point of adding the join, I get an error indicating that the feature layer I've created is undefined. I would appreciate any help. Here is my basic script:

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")


# Local variables...
Canola_AllShapes = "C:\\Temp\\Canola_AllShapes.shp"
Output = "C:\\Temp\\Output"
testdbf = "C:\\Temp\\Output\\testdbf.dbf"
inputtable = "C:\\Temp\\zstats.dbf"


gp.MakeFeatureLayer_management (Canola_AllShapes, "CanolaAllShapesFL")


# Process: Add Join...
gp.AddJoin_management("Canola_AllShapesFL", "CSD", inputtable, "VALUE", "KEEP_ALL")

# Process: Table to Table...
#gp.TableToTable_conversion("Canola_AllShapes", Output, "testdbf", "", "CSD_Ha 'CSD_Ha' true true false 19 Double 4 18 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.CSD_Ha,-1,-1;yearCSD 'yearCSD' true true false 17 Text 0 0 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.yearCSD,-1,-1;CSD 'CSD' true true false 7 Long 0 7 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.CSD,-1,-1;PR 'PR' true true false 2 Short 0 2 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.PR,-1,-1;PRV 'PRV' true true false 6 Long 0 6 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.PRV,-1,-1;CD 'CD' true true false 6 Long 0 6 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.CD,-1,-1;CSD_1 'CSD_1' true true false 6 Long 0 6 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.CSD_1,-1,-1;YEAR 'YEAR' true true false 6 Long 0 6 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.YEAR,-1,-1;FREQ 'FREQ' true true false 6 Long 0 6 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.FREQ,-1,-1;CV_YLD 'CV_YLD' true true false 13 Double 2 12 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.CV_YLD,-1,-1;SKW_YLD 'SKW_YLD' true true false 13 Double 2 12 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.SKW_YLD,-1,-1;KRT_YLD 'KRT_YLD' true true false 13 Double 2 12 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.KRT_YLD,-1,-1;WMEAN_YLD 'WMEAN_YLD' true true false 13 Double 2 12 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.WMEAN_YLD,-1,-1;CSD_t 'CSD_t' true true false 12 Text 0 0 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.CSD_t,-1,-1;yearCSD_1 'yearCSD_1' true true false 17 Text 0 0 ,First,#,C:\Temp\Canola_AllShapes.shp,Canola_AllShapes.yearCSD_1,-1,-1;inputtable' true true false 9 Long 0 9 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.VALUE,-1,-1;inputtable_1 'inputtable_1' true true false 9 Long 0 9 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.COUNT,-1,-1;inputtable_2 'inputtable_2' true true false 13 Float 0 0 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.AREA,-1,-1;inputtable_3 'inputtable_3' true true false 9 Long 0 9 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.MIN,-1,-1;inputtable_4 'inputtable_4' true true false 9 Long 0 9 ,First,#,C:\Temp\Canola_AllShapes.shp,inuttable.MAX,-1,-1;zstats_null_CL_5 'zstats_null_CL_5' true true false 9 Long 0 9 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.RANGE,-1,-1;inputtable_6 'inputtable_6' true true false 13 Float 0 0 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.MEAN,-1,-1;inputtable_7 'inputtable_7' true true false 13 Float 0 0 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.STD,-1,-1;inputtable_8 'inputtable_8' true true false 13 Float 0 0 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.SUM,-1,-1;inputtable_9 'zstats_null_CL_9' true true false 9 Long 0 9 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.VARIETY,-1,-1;inputtable_10 'inputtable_10' true true false 9 Long 0 9 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.MAJORITY,-1,-1;inpututable_11 'inputtable_11' true true false 9 Long 0 9 ,First,#,C:\Temp\Canola_AllShapes.shp,inputtable.MINORITY,-1,-1;inputtable_12 'inputtable_12' true true false 9 Long 0 9 ,First,#,C:\Temp\Canola_AllShapes.shp,inputttable.MEDIAN,-1,-1", "")

# Process: Remove Join...
#gp.RemoveJoin("CanolaAllShapesFL", "inputtable")


Thanks - I would greatly appreciate any help.

Outcomes