Select to view content in your preferred language

Attribute Rule Equivalent for Multi Field Intersect Attribute Assistant rule

323
3
03-19-2025 12:26 PM
ShaundaDevenport
Emerging Contributor

I am trying to find an example Attribute Rule to accomplish something that worked with the Multi-Field-Intersect rule in attribute assistant.

I am looking to populate the Road Names of a point feature (road centreline intersection point) based on which Road lines intersect the point. There are 4 fields in the intersection point (road1, road2, road3, road4) and I would like the Road names of the 4 roads that intersect that point to automatically be populated.

I can see how to do this with start/end nodes on a line, and I can see how to do this to find the "first" intersecting feature, but not sure how to do it when it's one feature class, has multiple features, and doesn't matter if it's the start or the end and I really don't care what order the road names (road1,road2) are populated on to the intersecting point.

The attribute assistant rule was:

TableNameValueMethodValueInfo
trnRoadIntersectionMULTI_FIELD_INTERSECTtrnRoadCentreline|NAME|ROAD1,ROAD2,ROAD3,ROAD4
0 Kudos
3 Replies
AlfredBaldenweck
MVP Regular Contributor

Try something like this?

var rds = FeatureSetByName($datastore, "roads")
var names = [] //Empty array for the valid names

//Get the names of all the roads that intersect
for (var r in rds){
    if (Intersects($feature, r)){
        Push(names, r["Name"])
     }
}
//Sort names
names = Sort(names)
//Concatenate with a comma and a space
return Concatenate(names, ", ")

 

The only issue with this is that it will iterate through every road each time, so performance may suffer.

Someone like @jcarlson or @JohannesLindner might have a suggestion on how to speed it up?

0 Kudos
ShaundaDevenport
Emerging Contributor

Thanks for this.  I've tweaked it slightly,  I'm a total arcade newbie so I know this code is atrocious.

But I think I was able to get it to only query the roads that intersect, not all.  

The bad code part is evaluating the array. capturing how many values are in there and then assigning those values to the correct attributes.

var rds = FeatureSetByName($datastore, "trnRoadCentreline")
var names = [] //Empty array for the valid names


var intersectingRoads = Intersects(rds, Geometry($feature))

//Get the names of all the roads that intersect
for (var r in intersectingRoads){
           Push(names, r["Name"])  
}


//Sort names
names = Sort(names)

var c = Count(names)

If (c > 3){
    return {
    "result": {
        "attributes": {
            "ROAD1": names[0], 
            "ROAD2": names[1],
            "ROAD3": names[2],
            "ROAD4": names[3]
            
                      }
                }

            }  
} else if
   (c==3){
    return {
      "result": {
        "attributes":{
          "ROAD1": names[0],
          "ROAD2": names[1],
          "ROAD3": names[2]
        }
      }
    }
  }
 else if
   (c==2){
    return {
      "result": {
        "attributes":{
          "ROAD1": names[0],
          "ROAD2": names[1]
        }
      }
    }
  }
else if
   (c==1){
    return {
      "result": {
        "attributes":{
          "ROAD1": names[0]
        }
      }
    }
  } else {
     return {
      "result": {
        "attributes":{
          "ROAD1": null
        }
      }
    } 

}

 

 

AlfredBaldenweck
MVP Regular Contributor

Oh solid option.

I missed the part where you were sorting to different fields.

I think you could probably cut out some of the code by doing something like

  1. Push to list
  2. Make sure list length is 4 
  3. If it isn't, add "None" to list until it is
  4. Populate field 1 with list[0], field 2 with list[1], etc.
0 Kudos