Relationship Class Using Python

1056
3
12-08-2021 03:27 AM
Labels (1)
AbidHiraSaath
New Contributor III

I want to create Relationship Class using python (notebook) between two hostel feature layer with UID.

I created a project on ArcGIS Pro which has a series of relation classes between different polygons and tables

This has been uploaded to ArcGIS online so that we can collect data using Field Maps.

Unfortunately, we forgot to add an inspection table in ArcGIS pro. Now that the  feature layer is online and our team are collecting data we can't re-upload after making changes in ArcGIS Pro. So, we are searching for at way to create a relationship class with table between a new table created in ArcGIS online and the feature layer that we already uploaded.

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

The only access points are in the data management toolset, for instance

Create Relationship Class (Data Management)—ArcGIS Pro | Documentation

but you can use arcpy to determine relationship class properties, eg

RelationshipClass properties—ArcGIS Pro | Documentation

 


... sort of retired...
0 Kudos
jcarlson
MVP Esteemed Contributor

Unfortunately, there's no way that I'm aware of to add a relationship across two different hosted feature services. Even if you had the table added to the same service, adding the relationship is still tricky, though some users claim to have done it by editing the JSON of the service layers.

A relationship in AGOL looks like this:

 

"relationships": [
    {
      "keyField": "name",
      "role": "esriRelRoleOrigin",
      "composite": false,
      "name": "sanitary_retired",
      "relatedTableId": 3,
      "id": 0,
      "cardinality": "esriRelCardinalityOneToMany"
    }
]

 

There's simply nowhere in the relationship definition to look for an outside service; it has to be in the same service.

There are plenty of posts on here about "can I add a layer to a service without republishing?", and some interesting suggestions in response to them. In my experience however, the only reliable way to add or remove a layer from an existing service is to republish.

Any chance you could schedule something like this to happen overnight?

  1. Pause editing on the service
  2. Download entire service to local files in ArcGIS Pro
  3. Make sure inspection table is added to the layer list
  4. Republish and overwrite

If you add a service, make sure you only add it to the bottom of the list, otherwise your layer index will get messed up, and existing maps using the service will probably edit the wrong layers.

- Josh Carlson
Kendall County GIS
0 Kudos
AustinDoezema
New Contributor II

After you create your relationship dictionary, you can add that to the layer definition. You need to add a relationship to both the layer and the table.

lyr.manager.add_to_definition({"relationships": [lyr_rel_dict]})
tbl.manager.add_to_definition({"relationships": [tbl_rel_dict]})

 

0 Kudos