Select to view content in your preferred language

Arcade: Intersect or Filter Two Feature Classes to Populate a Related Table

472
2
12-04-2023 08:33 AM
ArmstKP
Frequent Contributor

I have a table that is related (one to one) to my parks feature class.  It has park amenity fields (benches, pool, kayak_rental, etc.) with a yes or no value.

Intersect option: I want to be able to intersect the parks feature class with our benches feature class and if there is an intersection, write yes or no to the benches field in the related table for that park.

Filter option:  If the park_name field of the parks fc equals the park_name field of the benches fc, return yes to benches field in the related table for that park.

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor
// Calculation Attribute Rule in the point fc
// field: empty
// triggers: insert
// exclude from application evaluation

var parks_fc = FeaturesetByName($datastore, "ParksFC")
var parks_table = FeaturesetByName($datastore, "ParksTable")

var park_polygon
// get the park polygon
// by filtering for the park_name attribute
if(!IsEmpty($feature.park_name)) {
    var p_name = $feature.park_name 
    park_polygon = First(Filter(parks_fc, "park_name = @p_name"))
}
// or by intersecting the bench with the parks fc
if(park_polygon == null) {
    park_polygon = First(Intersects($feature, parks_fc))
}
if(park_polygon == null) { return }  // we couldn't find a corresponding park polygon, abort

// get the related table row
var key = park_polygon.KeyField
var park_row = First(Filter(parks_table, "KeyField = @Key"))
if(park_row == null) { return }  // the polygon doesn't have a corresponding table row, abort


// return a dictionary to instruct ArcGIS to update the park table
return {
//    result: attributes: {park_name: park_polygon.park_name}},  // set the bench's park_name field
    edit: [{
        className: "ParksTable",
        updates: [{
            objectID: park_row.OBJECTID,
            attributes: {HasBenches: "Yes"}
        }]
    }]
}

 

Edit lines 6, 7, 12-14, 23, 24, 32, 35 to fit your table and field names.

Further reading for the return dictionary: https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-k...

 


Have a great day!
Johannes
0 Kudos
ArmstKP
Frequent Contributor

@JohannesLindner Thank you, but I am a little lost on this one.  I am not so clear from the example given what field names go where.

Parks FC polygon:  prod_geodb1.DATAOWNER.ASM_LocationsMPRB_190325  park name field: Name_Primary

Benches FC:  prod_geodb1.DATAOWNER.ASM_Benches_180824  park name field: Name_Primary

Related table:  prod_geodb1.DATAOWNER.ASM_ParkAmenities  park name field: PARK_NAME

 

Also, we currently do not employ attribute rules.

0 Kudos