ArcPy Relates – Add/Remove Relate Using ArcPy Without ArcGIS Pro

arcgis-10.3arcmaparcpyrelates

I am trying to add a relate between 2 feature classes so that I can use the area of the related table to update a field in the original table.

I found that ArcGIS Pro (http://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-relate.htm) can do this, but a similar feature is not available to ArcPy when used with the ArcGIS 10.3 environment i.e. I am not using ArcGIS Pro.

I followed the script at the bottom of the ArcGIS Pro help page for Add Relate (believing that they would be the same), but get the error that the module has no attribute 'AddRelate'. This confirms the result seen in Terminology for distinguishing ArcPy installed with ArcGIS 10.x for Desktop from that which comes with ArcGIS Pro?

I am aware of the CreateRelationshipClass_management tool, but don't know if this the same thing and if it is, how to call a related field after establishing the relationship.

Can anyone either explain the CreateRelationshipClass tool better (I can't seem to understand the help documents) or explain how to better relate two tables so that I can access another column?

I did try joining the tables, but I can't get them to unjoin afterwards and I don't want the additional fields actually in my table.

Best Answer

In the absence of the Add Relate tool, that has been added to ArcGIS Pro, and not to the ArcGIS 10.x architecture that you are using the pseudo code for how I would do this is:

  1. Use a Search Cursor to read and load all the values from the second table (the one you want to add the relate to) into a Python dictionary. Use the same field as your key that you would if using a relate.
  2. Use an Update Cursor to run through the first table and use the same field as your key that you would if using a relate to look up the values to write in from your Python dictionary.

You may also want to investigate the Add Join tool because I am not reading anything in your question that indicates that you have considered it, nor any requirement that it would not meet:

Joins a layer to another layer or table (where layer is a feature layer, table view, or raster layer with a raster attribute table) based on a common field.

The records in the Join Table are matched to the records in the input Layer Name. A match is made when the input join field and output join field values are equal. This join is temporary.

Related Question