2

I have a list of tables (1,2,3) and would like to join the tables, tables by table, to a list of feature classes (1X,2X,3X). So that table 1 combines with feature class 1X, table 2 with feature class 2X and so on. The first table of the correspondent workspace should combine with the first feature class of the correspondent workspace, the second with the second and so forth.

I think it is similar to this problem where a solution is provided but in arcpy which I am not yet into! (https://community.esri.com/t5/python-questions/join-multiple-tables-to-multiple-feature-classes-arcpy/td-p/181549/page/2) I experimented with lists, batch function and iterators but could not find a solution. The batch function seemed suitable, but it seems only to work with one list and the counterpart must be a single feature class/table as far as I could see. I will show pictures of what from my point of view might be the closest solution but isn't working anyways. I thought I might iterate through the tables and the feature classes (one iteration in a submodel).

Or will this model try to combine every table with every feature class in my workspaces?

what I tried ...

Edit: I tried a solution in arcpy. I runned it in ArcMap 10.7 python console. So I think it is using Python 2.7. (this is why I changed the f' strings from the solution in the link above [only available from Pyhton 3?] to "%" for inline variable substitution).The script runs but joins all tables to the last feature class in the list:

import arcpy

#Define Geodatabase Path
featureGDB = r"C:\C_M2\arcpy\list\list_Events_SBA_wp.gdb"
tableGDB = r"C:\C_M2\arcpy\list\list_distance.gdb"

#Create Feature List Variable
arcpy.env.workspace = featureGDB
featureList = arcpy.ListFeatureClasses()

#Create Table List Variable
arcpy.env.workspace = tableGDB
tableList = arcpy.ListTables()

#Set table Names to featureList Names equivalent
for table in tableList:
    tableNum = table [0:-5]
    #Find Table and Feature from Lists with same Name and join them   
    for feature in featureList:
        if feature == "%tableNum%":
            inData = featureGDB + "%\feature%"
            inField = "OBJECTID"
            joinTable = tableGDB + "%\table%"
            joinField = "OBJECTID"
            arcpy.JoinField(inData, inField, joinTable, joinField)

The table names are "WP_20200723_001_dist" till "WP_20201010_005_dist". The feature class names are the same less the "_dist" anex: "WP_20200723_001" till "WP_20201010_005". Both lists have the same number of items.

1

I find ModelBuilder not suitable for this type of processing and is done much easier with a Python script. That said and as you appear to be seeking a ModelBuilder solution, you say you have a 1 to 1 numeric match between table and featureclass.

Explore using a single model driven by a FOR iterator this will create your 1,2,3... and using inline variable substitution you can build the paths to you tables\featureclasses and join them.

1
  • Thanks a lot for the hint! I will explore that and report here – Jörn Feb 20 at 9:28
0

I got it finally in arcpy: (see also: https://community.esri.com/t5/python-questions/join-multiple-tables-to-multiple-feature-classes-arcpy/m-p/1031637#M60171)

import arcpy

#Define Geodatabase Path
featureGDB = r"C:\C_M2\arcpy\list\list_Events_SBA_wp.gdb"
tableGDB = r"C:\C_M2\arcpy\list\list_distance.gdb"

#Create Feature List Variable
arcpy.env.workspace = featureGDB
featureList = arcpy.ListFeatureClasses()

#Create Table List Variable
arcpy.env.workspace = tableGDB
tableList = arcpy.ListTables()

#Set table Names to featureList Names equivalent
for table in tableList:
    tableNum = table [0:-5]
#Finde Table and Feature from Lists with same Name and join them   
    for feature in featureList:
        if feature == tableNum:
            in_data = featureGDB + "\\" + feature
            in_field = "OBJECTID"
            join_table = tableGDB + "\\" + table
            join_field = "OBJECTID"
            fields = ["DISTANCE"]
            arcpy.JoinField_management(in_data, in_field, join_table, join_field, fields)

Thank You!

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.