Select to view content in your preferred language

Join one to many issue

420
5
01-08-2024 02:42 PM
CCWeedcontrol
Regular Contributor

I have a feature class and a table that I need to join. The table and feature class share a common field, The table will have duplicate Acc (ID's), and the Feature class will have just one Acc (ID's). Both are in the same file geodatabase, both have objectIds. The following doesn't crate the one to many join, what am I missing?

 

 

arcpy.env.workspace = "C:/Temp/test.gdb"
fc = "C:/Temp/test.gdb/TaxPs"
sourceTB = "C:/Temp/test.gdb/table"

arcpy.MakeFeatureLayer_management(fc, "TaxPs")

arcpy.AddJoin_management("TaxPs", "Acc", sourceTB, "Acc", "KEEP_COMMON")

arcpy.management.CopyFeatures(fc, os.path.join(arcpy.env.workspace, "Taxps_Joined"))

 

 

 

0 Kudos
5 Replies
CCWeedcontrol
Regular Contributor

It is making a duplicate but for example the table will have 4 attributes and the feature class will have one attributes. It it creates a duplicate four times, how can I get it to create new records for keep the attributes from the table?

Table

Table 
AcctField A
14970201MH
14970201SFR
14970201CON
14970201RV

 

Feature class

AcctFieldA
14970201MH

 

After Join.

14970201MH
14970201MH
14970201MH
14970201MH
0 Kudos
VanessaSimps
Occasional Contributor III

Sounds like you need to check out using a relationship class instead of a join. Relate your table with the many to the feature class with the one. 

0 Kudos
CCWeedcontrol
Regular Contributor

When I search for joining one to many, I found that join.management should work, unless it doesn't truly work?

Add Join (Data Management)

 

 

0 Kudos
VanessaSimps
Occasional Contributor III

I think it really depends on what you are trying to get as a result and how you want to use the data once it's joined/related. 

once you have the join created, what are your plans? Remember,  join only exists inside a map project. you can't publish out joined data (I am assuming you are in desktop with this, not web AGO/AGE). 

0 Kudos
CCWeedcontrol
Regular Contributor

Essentially, I need to create point features for every record in the table, which falls within a parcel. I do have CopyFeatures which is suppose to create the features, from what I have read.

What is happening is that, if I run the stand alone script the join.management works but as mentioned I creates duplicates not all the attributes from the table get transferred after doing a copyfeature.

 

Upon incorporating the script into a model, the Join management function behaves differently from the standalone script. It fails to establish a one-to-many join as observed in the script.

 

0 Kudos