Select to view content in your preferred language

"Join Data" in Python Script

684
2
05-02-2011 10:42 AM
TiernanErickson
New Contributor
I would like to use the "Join Data" function that is available when you right-click a feature class in the Table of Contents. But I need to call it from Python. Does anyone know how to access this function from Python? I am trying to join fields from a DBF to the attribute table of a shapefile. I want to use "Join Data" because it's quick and it doesn't change the field names.

Can't Use:
-"Add Join" because it changes all of the field names to append the name of the file it came from. (Ex.: "landuse.FieldA", "landuse.FieldB", "lookup_tab.FieldC", and "lookup_tab.FieldD".) The "Join Data" tool doesn't change the field names. I would have to find an automated way to change the field names back, stripping the file names off of the fields.
-"Join Field" because it takes *hours* to join the table (instead of just seconds with "Join Data" or "Add Join").

Does anyone know how to access the "Join Data" function in Python?

I've gotten several suggestions saying that I should just use "Add Join" and then change all of my field names, and several others saying that I should just manually right-click to use "Join Data", then run the script for the rest of the processing I need to do. I would rather use the best tool for the job.

Thanks!

Regards,

-T.
Tags (2)
0 Kudos
2 Replies
TerrySilveus
Frequent Contributor
Interesting because when I use the join option by right clicking on the layer and selecting the join option from the context menu it put the filename.fieldname on the headers in the attribute file.
0 Kudos
MathewCoyle
Honored Contributor
For joining tables you need to have unqualified field names to stop the changing of the field names.
arcpy.QualifiedFieldNames = "UNQUALIFIED"

Generally when I join I use the below code.
arcpy.JoinField_management(table1, field1, table2, field2)

This makes the join permanent, if you just want temporary joins then use the AddJoin.

*Edit: When you join tables with unqualified names, any duplicate names will have "_1" added to the end to make them unique. This usually comes up in the fields the join is based on, which usually have the same name. At least in my environment. Also, using field mappings may solve your problems as they give specific field names as the output, but I find them more trouble than the time they save.

*Edit2: Oh sorry, see http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001w00000008000000.htm
Syntax is
arcpy.env.qualifiedFieldNames = qualified_field_names

unless you have
from arcpy import env
0 Kudos