A very common ask in attribute rules is to capture the merge features events and perform some custom logic. While attribute rules don't have an explicit on merge event, we can simulate that with the Pro editing experience. I authored an example attribute rule to demonstrate how to perform this.
We will be authoring an attribute rule that triggers when a user merges two lines using the Pro merge tool. When the user selects two line features and wants to merge them, the attribute rule will pick the largest line segment and copy the addresstext of that line feature to the new merged feature and then the rule will delete the old two segments.
The challenge with the default option in the merge tool is that it deletes the original features being merged. This prevents attribute rule from easily querying the original features and perform custom logic. To allow for more a flexible behavior, we will need to modify some options.
To achieve more control, we will be using the option to keep the original features in the merge tool, and let the attribute rules do the delete instead. This gives us more control as it turns the operation from a delete, update (delete the original feature, and update the geometry of the merged feature), to an update only. We will write the rule to trigger on update on geometry using the new triggering fields to set the rule to only trigger on shape change.
On the update we will have the control to query the original features (since they won't be deleted) and copy any attribute we want off of it. And then later we can insert the logic to actually delete the original feature from attribute rules.
Following is the attribute rule and a video demonstration.
//When merging with the option "new feature" the rule will be executed on insert, if we enabled keep original features we get access to the original rows , this way we can query the merged lines, pick the largest segment , take the address from it and copy it to the new merged line. after merging we issue a delete to delete the two original segements.
var g = $feature.GlobalID
var fs = contains(filter($featureset, "globalid <> @g"), geometry($feature))
var biggerAddress = null;
var biggerLine = null;
var tobeDeleted = []
for (var g in fs)
{
push(tobeDeleted, {"globalId": g.globalid} )
if (biggerLine == null){
biggerLine = g;
biggerAddress = g.addresstext;
}
if (length(g) >= length(biggerLine)){
biggerLine = g;
biggerAddress = g.addresstext;
}
}
if (biggerLine == null) return;
return {
"result": {"attributes": {"addresstext": biggerAddress}},
"edit": [{
"className": "main.theline",
"deletes": tobeDeleted
}]
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.