arcpy method to create a relationship between features

3856
4
04-30-2013 01:21 AM
YvoWeidmann
New Contributor II
Dear List

I am using a relationship class (1 : n) between two feature classes (a : B). To relate newly imported features of the feature class B with the individual feature of a I would like to use ArcPy in the same workflow.

Is there an equivalent of the ArcObjects method IRelationshipClass.CreateRelationship(origin, destination)?

Looking forward to any hint.

Best regards,
Yvo
Tags (2)
0 Kudos
4 Replies
JamesCrandall
MVP Frequent Contributor
0 Kudos
RussellBrennan
Esri Contributor
What James provided above is the correct way to create a relationship class using ArcPy. Providing the primary and foreign keys is what establishes the relationship between the features. You can use the arcpy.describe() function for getting access to various properties of the relationship class.

Create Relationship Class:
http://resources.arcgis.com/en/help/main/10.1/index.html#//0017000000mn000000

Describe relationship properties:
http://resources.arcgis.com/en/help/main/10.1/index.html#/RelationshipClass_properties/018v0000002n0...
0 Kudos
RussellBrennan
Esri Contributor
Yvo,

You should be able to use the relationship class describe object to get the primary/foreign keys and use arcpy search or insert cursors to make the updates to the records.

Insert Cursor:
http://resources.arcgis.com/en/help/main/10.1/index.html#/InsertCursor/018w0000000t000000/

Search Cursor:
http://resources.arcgis.com/en/help/main/10.1/index.html#/SearchCursor/018w00000011000000/
0 Kudos
MatejTacer
New Contributor III
What Yvo probably wanted and what I'm trying to do as well is to access data in the destination table related to the origin table via relationship class using arcpy cursors.

If I set the cursor on the origin feature class, I can only retrieve the field values that are physically stored in that table. But I need to access the data from the related record(s) in the destination table as well. Similarly than you can browse the related data in the identify window in ArcMap.

Do I really have to treat the two tables separately and reestablish the connection manually using two cursors and then running the search cursor in a loop to retrieve data from the destination table as Russel suggested?