Select to view content in your preferred language

Is there an easy way to populate a new related table with data that is currently stored as an attribute of another feature class?

925
4
Jump to solution
10-25-2023 02:15 PM
Labels (3)
MatthewBeal
Occasional Contributor III

I’m working on modernizing our Planning and Zoning map. The way it is currently set up is that there are attribute fields set up for Rezones, Special Use Permits, and Variances. It has worked well enough, but the problem is that storing them via attribute has meant that we can only have the most recent record. A parcel can be rezoned many times and have multiple different conditional uses applied to it, so this is less than ideal because of that. I created a relationship class to a table that will hold those going forward. The challenge I am facing is migrating our old data to the new relationship class. I can’t seem to find a way to move that data that is currently in the zoning feature class into the related table. The only way I’ve seen so far would be to manually enter that data for all 2000+ records, which would be quite a time sink. Is there a more efficient way to do this? 

0 Kudos
1 Solution

Accepted Solutions
MatthewBeal
Occasional Contributor III

I figured out how to do this. Here are the steps I followed:

1. make sure that your target table has Global IDs enabled. 

2. Set up your related table to have all the fields that will hold the data you are looking to migrate from the old layer. You will also need a field using the "type" GUID. 

3. Create the relationship class using the GlobalID from your main table and the GUID field from the related table as the primary key. 

4. Either export the old table you want to migrate to an excel file or copy it to an excel file. 

5. Rearrange the table in excel to where the format matches your new related table EXACTLY. You should have the same number of columns and all the data types should be the same. (Ensure text items are formated as "text" in excel instead of general. 

6. When your excel table matches the format of your related feature class, you can copy the data from excel and paste it over a blank row of the attribute table. As long as your global IDs were enabled, pasting that data will create the relationship. 

View solution in original post

4 Replies
NiekGoorman1
Occasional Contributor

Just thinking off the top of my head here, but could you perhaps make a copy of your feature class to a table? Then you delete any field you don't need and are left with just your Rezone field and some unique ID you can use for the relationship. Then you delete the Rezone field from your main feature class and you're done.

0 Kudos
Robert_LeClair
Esri Notable Contributor

There is a workflow to add selected records to a relationship class here.  Question - are you using a file geodatabase or an enterprise geodatabase?  If an eGDB, then there's a workflow called archiving that tracks the "life" of a feature over time so you can see the changes (i.e. zoning changes).

0 Kudos
DavidSolari
Occasional Contributor III

 

parent_key = "GlobalID"
child_key = "ParentID"
parent_fields = [parent_key, "fields", "to", "copy"]
child_fields = [child_key, "into", "the", "child"]

# Start an edit session if needed
with arcpy.da.UpdateCursor("parent_table", parent_fields) as update, arcpy.da.InsertCursor("child_table", child_fields) as insert:
    for row in update:
        insert.insertRow(row)
        update.updateRow([row[0]] + [None] * (len(row) - 1))
# Close the edit session if needed

 

Untested, but this should simultaneously create related records with the relevant fields while nulling out the old data to avoid confusion.

0 Kudos
MatthewBeal
Occasional Contributor III

I figured out how to do this. Here are the steps I followed:

1. make sure that your target table has Global IDs enabled. 

2. Set up your related table to have all the fields that will hold the data you are looking to migrate from the old layer. You will also need a field using the "type" GUID. 

3. Create the relationship class using the GlobalID from your main table and the GUID field from the related table as the primary key. 

4. Either export the old table you want to migrate to an excel file or copy it to an excel file. 

5. Rearrange the table in excel to where the format matches your new related table EXACTLY. You should have the same number of columns and all the data types should be the same. (Ensure text items are formated as "text" in excel instead of general. 

6. When your excel table matches the format of your related feature class, you can copy the data from excel and paste it over a blank row of the attribute table. As long as your global IDs were enabled, pasting that data will create the relationship.