Performing field calculation using related table.

1120
4
Jump to solution
10-25-2021 01:55 AM
Labels (1)
byllus001
New Contributor II

Greetings all,

In my database I have a point file of event locations, and another point file showing the position of people during each event. I want to perform a field calculation to record how many people were within a 5m radius of each event. 

I know for one-to-many relationships, you must relate the tables, but I cannot use the field calculator like I would if I could join the table. Is there any way to do this in ArcGIS Pro? I don't mind using Python if need be.

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Regular Contributor

Create a new integer field in your event fc. Do not join the tables. Calculate the new field, switch to Arcade, edit and use this code.

var people_fc = FeatureSetByName($datastore, "PeopleFeatureclass", ["ObjectID"], true)
return Count(Intersects(Buffer($feature, 5), people_fc))

 


Have a great day!
Johannes

View solution in original post

4 Replies
JohannesLindner
MVP Regular Contributor

Create a new integer field in your event fc. Do not join the tables. Calculate the new field, switch to Arcade, edit and use this code.

var people_fc = FeatureSetByName($datastore, "PeopleFeatureclass", ["ObjectID"], true)
return Count(Intersects(Buffer($feature, 5), people_fc))

 


Have a great day!
Johannes
byllus001
New Contributor II

Just ran your code with my variables, and it worked perfectly! Thank you very much, Johannes.

0 Kudos
AdamHart1
New Contributor II

Hello,

I am having a similar issue and am wondering how this code can be modified with my situation. I have a polygon feature class in a FGDB that is related to a table in the same FDGB. In the table, there are multiple rows that need to match up with one polygon in the feature class. I would like to field calculate field attributes from the table to the polygon layer. Can this be done with a variation of this code? Thank you in advance.

0 Kudos
JohannesLindner
MVP Regular Contributor

If you have built a relationship class, you can get the related table entries like this:

var related = FeatureSetByRelationshipName($feature, "NameOfTheRelationshipClass")

 

If not, you have to load and filter the table like this:

var table = FeatureSetByName($datastore, "NameOfTheTable")
var id = $feature.PrimaryKey
var related = Filter(table, "ForeignKey = @ID")

 

And then it depends on what you want to extract from the related table entries. Some examples:

// Return the count
return Count(related)

// return max/min/mean/sum of a field
return Max(related, "FieldName")

Have a great day!
Johannes
0 Kudos