Select to view content in your preferred language

Iterator to join tables based on similar names

818
4
12-09-2022 06:28 AM
ThomasGillespie
New Contributor

Hi guys,

I have 54 point files named T1-T54. I have 54 polygons called T__1_ExportFeatures1-54.

I want to join a field from the point file to its corresponding polygon file table. So the field in T1 joins to the table in T__1_ExportFeatures1, the field in T2 joins to the table in T__1_ExportFeatures2, etc. All files are in the same geodatabase folder.

Doing it one by one would be time consuming. I presume its a job for iterate feature classes in model builder, but Im not sure how exactly. I can iterate over all of the polygon feature classes, but I don't know how to pull the corresponding point table for the join.

Any suggestions?

Thanks! Tom

0 Kudos
4 Replies
curtvprice
MVP Esteemed Contributor

You are correct to look at the Iterate Feature Classes tool. One of its outputs is the file name. You can then use a python expression of function (Calculate Value tool) to generate the corresponding path and then do the join. Join Field may be a better approach than add join / copy features, depending on what you're doing. Here's an example of the calculation to generate the second file name, 

 

# this is an example what you get from the iterator Name output variable
# (data used below in variable reference %Name%)
"T1"  
# here is an example of what expression you could 
# use with the Calculate Value tool
# this would evaluate to :"T__1_ExportFeatures1"
"T__1_ExportFeatures{}".format("%Name%".replace("T",""))

 

 

You then use the output variable from Calculate Value for tools used down the chain, like Join Field.

A tip: if needed, use preconditions, for example, make sure the iterator "Name" variable is set as a precondition to the Calculate Value to make sure you are working with the value from the current iteration.

Hope this is helpful to you!

0 Kudos
ShitijMehta
Esri Regular Contributor

try this. pls let me know if this works

ShitijMehta_0-1687420619725.png

 

0 Kudos
ThomasGillespie
New Contributor

Thanks ShitijMehta,

 

Could you post a higher resolution image please?

 

 

0 Kudos
ShitijMehta
Esri Regular Contributor

ShitijMehta_0-1687991900686.png

try now.. U might be able to make the image larger by hovering over the image and clicking once... pls can u check? ty

 

0 Kudos