create attribute rules to copy a field value from intersecting polygon

888
4
Jump to solution
11-09-2022 12:12 PM
kazzie
by
New Contributor II

I'm trying to create an arcade intersect expression for attribute rule in arcgis pro which will populate the attribute field 'Habitat_SiteName' in my Habitat_Patches layer when I create new polygons. The underlying polygon field name in the Habitat_Polygons layer is 'SiteName', within a file geodatabase.

Feature class 1: Habitat_Patches

Feature class 2: Habitat_Polygons

Triggers I would like to use are Insert and update. 

0 Kudos
2 Solutions

Accepted Solutions
JohannesLindner
MVP Frequent Contributor
// load the habitat polygons
var habitats = FeaturesetByName($datastore, "Habitat_Polygons")
// get the first intersecting habitat
var habitat = First(Intersects(habitats, $feature))
// no intersecting habitat? -> abort
if(habitat == null) { return null }
// else return the habitat's site name
return habitat.SiteName

Have a great day!
Johannes

View solution in original post

0 Kudos
JohannesLindner
MVP Frequent Contributor

 In that case, you would leave the field parameter empty and return a dictionary instead of a value.

var habitats = FeaturesetByName($datastore, "Habitat_Polygons")
var habitat = First(Intersects(habitats, $feature))
if(habitat == null) { return null }

return {
    "result": { "attributes": {
        "Field1": habitat.Field1,
        "Field2": habitat.Field2
    }}
}

Have a great day!
Johannes

View solution in original post

0 Kudos
4 Replies
JohannesLindner
MVP Frequent Contributor
// load the habitat polygons
var habitats = FeaturesetByName($datastore, "Habitat_Polygons")
// get the first intersecting habitat
var habitat = First(Intersects(habitats, $feature))
// no intersecting habitat? -> abort
if(habitat == null) { return null }
// else return the habitat's site name
return habitat.SiteName

Have a great day!
Johannes
0 Kudos
kazzie
by
New Contributor II

Thanks Johannes, that worked a treat. sorry another question im trying to get my head around arcade. How would it work if you had multiple fields to copy.  

0 Kudos
JohannesLindner
MVP Frequent Contributor

 In that case, you would leave the field parameter empty and return a dictionary instead of a value.

var habitats = FeaturesetByName($datastore, "Habitat_Polygons")
var habitat = First(Intersects(habitats, $feature))
if(habitat == null) { return null }

return {
    "result": { "attributes": {
        "Field1": habitat.Field1,
        "Field2": habitat.Field2
    }}
}

Have a great day!
Johannes
0 Kudos
kazzie
by
New Contributor II

Thanks again Johannes, the link was really helpful and will have a play with the other options.

Have a great day too

Kazzie

0 Kudos