Python Table Select and Join

3089
13
11-08-2011 06:34 AM
MichellePetersen
New Contributor
Hi All,

I have created a python script that performs first a table select and then attempt to join the selected attributes from the table to a feature class. I have added the script into MyTool Box in ArcCatalog and set all parameter properties; however, I can not get the tool to work.  In fact, the tool can not even run through the table select command.  I am not sure if the fact that you have to choose an already created table for the output table in table select is the reason for the execution failure.  Any suggestions? I have attached the python script below.

Thanks in advance,
Michelle
Tags (2)
0 Kudos
13 Replies
DuncanHornby
MVP Notable Contributor
Michelle,

Can you upload your toolbox that you have linked your python script to so we can check the parameters. Also give us an example of the sql expression you are adding and maybe a sample of your data (in the format that it is stored as)?

Duncan
0 Kudos
MichellePetersen
New Contributor
Duncan,

Thanks for the quick reply. How do you upload the toolbox? I tried to upload the toolbox and it tells me the file is invalid.

The sql expression is "If month = x and year =x"

The table that I want to select by month/year combination is attached below (Wost_Test). This is a sub sample of the data.

I am unable to attach the shapefile that I wish to join with the table above.

Michelle
0 Kudos
DuncanHornby
MVP Notable Contributor
Michelle,

You upload data/toolboxes by zipping them up first...

Your sample of data (Wost_Test) is this originally a text file? Convert it to a dbf first.

Duncan
0 Kudos
MichellePetersen
New Contributor
Duncan,

Here is my zipped toolbox.  You think I should be using a .dbf of my data rather than .txt?  It is originally a .txt file as I output it from SAS.

Thanks,
Michelle
0 Kudos
MichellePetersen
New Contributor
I have also attached the shapefile which will be joined to the data selected from the table select tool if this would be helpful.

Michelle
0 Kudos
DuncanHornby
MVP Notable Contributor
Michelle,

I downloaded your toolbox and had a look at it. In your initial thread you said that it would not even run the table select part of Python. This bit I have tested only. The parameter setting for your "Output selected data" was incorrect. It's direction was set to input this should be an Output. This allowed that section of code to execute correctly even with the text file (my idea of dBase was a red herring). This bit of code now generates a table based upon your sql expression which should join to your featureclass.

Duncan
0 Kudos
MichellePetersen
New Contributor
Duncan,

Thanks for the tips.  Now I have been able to get the table select portion of the code running, but can not get the join section to work.  I am not sure if it is possible to join the selected data from the table select to the feature class because I have designated the selection output as a table.  Because I am running both the table select and join from the same toolbox, the table select has not created the output table I can not join this with the feature class. Do you know of a way I could get around this?

Cheers,
Michelle
0 Kudos
DuncanHornby
MVP Notable Contributor
Michelle,

Well I think your problem is that your Script is taking 7 inputs but your toolbox interface is asking for 8!

You need to set select SRF grid to be of type FeatureLayer and have it loaded in arcmap so you can select it from the drop down.

Delete your 7th parameter which is asking for a table, you don't need this as this is output table from your sql query.

Finally for your input Selected Join Field "CellID1" set Obtained from to nothing and set it's default value to CellID1.

Duncan
0 Kudos
MichellePetersen
New Contributor
Hi Duncan,

I have went through and edited my toolbox and look at my python code and have attached them below. However, I still can not select the "Output Selected Data" table as the input table for "Selected  SRF Data, as this table has not been created because the tool has not run.

Cheers,
Michelle
0 Kudos