1

arcpy: I would like to join a .xls table to a .shp table using two common fields, instead of one common field.

Is this possible in ArcGIS using python?

  • 2
    I don't believe this is possible, but you could easily create a new field in each table and populate it with a concatenation of the two fields you are interested in... would that accomplish what you need? – mr.adam Dec 4 '15 at 17:27
  • The only way to join on two fields is using the Make Query Table tool. resources.arcgis.com/en/help/main/10.1/index.html#//… However, that tool generally does not work well with tables that do not support ObjectIDs, like xls tables. You may have to convert the xls table into a dbf or geodatabase table to make it work. The concatenation suggestion mr. adam gave may work the best if you want to stay with an .xls file. – Richard Fairhurst Dec 4 '15 at 17:39
  • These are both great ideas. I will try both – William Dec 4 '15 at 18:17
  • mr.adam Your concatenation solution worked, and will be an easy addition to my enterprise join script. Thank you! Richard Fairhurst, I am now going to try and work your solution. – William Dec 4 '15 at 18:45
  • ok, for good measure I'll add it as an answer. – mr.adam Dec 4 '15 at 21:10
2

I don't believe this is possible, but you could easily create a new field in each table, populate it with a concatenation of the two fields you are interested in, and then use that new field for the join.

1

One possible solution would be to create a concatenated field in both the spreadsheet and the feature class, then use the Excel to Table function to get your spreadsheet into a table, then use Add Join function to finish the join. Python would go a little something like this:

import arcpy
env.workspace = "path to workspace"

excel_file = r"path to file"
input_fc = r"path to shapefile"
output_table = r"path to output table"

converted_table = arcpy.ExcelToTable_coversion(excel_file, output_table, "Sheet1")

arcpy.MakeFeatureLayer_management(input_fc, "temp_layer")
acrpy.AddJoin_management("temp_layer", "IN_FIELD", converted_table, "JOIN_FIELD", "KEEP_COMMON")
arcpy.CopyFeatures_management("temp_layer, "path and name for output")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.