3

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.

7
  • You referenced the AddRelate tool. All tools are accessible in arcpy. the arcpy code is at the bottom of that link
    – KHibma
    Commented Dec 7, 2015 at 2:26
  • Are you using ArcPy from ArcGIS Pro in Python 3.4? Or ArcPy from ArcGIS for Desktop in Python 2.7?
    – PolyGeo
    Commented Dec 7, 2015 at 2:26
  • @KHibma While you're here - what is the best way to describe the two ArcPy flavours so as to avoid any confusion about which is being used?
    – PolyGeo
    Commented Dec 7, 2015 at 2:27
  • They're the same. They're just a wrapper or entry into 10.x or Pro. The only difference is where a function or tool doesn't exist in the other product
    – KHibma
    Commented Dec 7, 2015 at 4:02
  • @KHibma Without a ping to me I've only just seen this comment but it makes sense to have done it that way.
    – PolyGeo
    Commented Dec 7, 2015 at 5:41

1 Answer 1

1

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.

2
  • I have actually considered the AddJoin tool but abandoned it because I couldn't get remove join to work correctly. I figured that using a relate would be more straight forward, but apparently not. Thanks for helping
    – JMVDA
    Commented Dec 14, 2015 at 18:33
  • @JMVDA try to create a "in_memory" layer from your source, then use the AddJoin tool on it. You wont have to remove the join because is would not be added to your source but only to a temporary copy of it. Commented Dec 14, 2017 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.