How to Update Attribute of Intersecting Line when Intersecting Point Attribute is Updated with Attribute Rules

1057
3
02-17-2021 11:11 AM
Labels (1)
MelissaSalich
Occasional Contributor

 

I have a Calculation Attribute Rule set on my line layer that updates with attributes from the intersection with my point feature. The rule works when creating new line features. We are getting stuck if the point attribute changes, the line attribute does not update automatically. 

From Manhole:
var g = Geometry($feature);

var fromPointGeometry = g.paths[0][0];

var fsPoint = FeatureSetByName($datastore, "ssManhole_1", ["FACILITYID"], false);

var fromPoint = First(Intersects(fsPoint, fromPointGeometry ) )

if (fromPoint == null) return -1;

return fromPoint.FACILITYID;

To Manhole:
var g = Geometry($feature);

var toPointGeometry = g.paths[-1][-1];

var fsPoint = FeatureSetByName($datastore, "ssManhole_1", ["FACILITYID"], false);

var toPoint = First(Intersects(fsPoint, toPointGeometry ) )

if (toPoint == null) return -1;

return toPoint.FACILITYID;

 

If anyone is familiar with Desktop's Attribute Assistant, we are trying to migrate our rules to Pro with Attribute Rules but are having difficulty configuring with Arcade.

@HusseinNasser2 thanks for the video that helped us configure the rules so far

Pro v 2.7.1, File geodatabase environment

3 Replies
JoeBorgione
MVP Emeritus

Migrating to Arcade is something you'll get used to. Eventually!  If you could, add your rules code to a code window it will be much easier to read than the images you included.  Click on the three dots to expand the tool bar, and select Insert/Edit code button that looks like this:  </>  For arcade I use the Java Script option.

That should just about do it....
0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Melissa,

  I did not test this, but this should get you started.  I will add it to this repo:

https://github.com/Esri/arcade-expressions/blob/master/Attribute%20Assistant.md

 

 

// Check to to if the ID changed
var orig_assetid = $originalFeature.assetid;
var assetid = $feature.assetid;
if (assetid == orig_assetid) {
    return null;
}
// Get the connected mains to the edited feature
var sewer_mains = FeatureSetByName($datastore, "SewerMain", ["globalid"], true)
var connected_mains = Intersects(sewer_mains, $feature)

// Functions to check if points/vertexes are snapped
function points_snapped(point_a, point_b) {
    // Cant explain it, but need these checks to get past validation
    if (IsEmpty(point_a) || IsEmpty(point_b)) {
        return false
    }
    if (HasKey(Dictionary(Text(point_b)), 'x') == false || HasKey(Dictionary(Text(point_a)), 'x') == false) {
        return false
    }
    return (nearly_equal(point_a.x, point_b.x, 4) &&
        nearly_equal(point_a.y, point_b.y, 4) &&
        nearly_equal(point_a.z, point_b.z, 4))

}

function nearly_equal(a, b, sig_fig) {
    // check if nearly equal to certain significant figure  https://stackoverflow.com/a/558289/12665063
    return (a == b || Round(a * Pow(10, sig_fig), 0) == Round(b * Pow(10, sig_fig), 0))
}

var updates = []
var i = 0
// Get the geometry of the edited feature
var port_geo = Geometry($feature);
// Loop through all mains
for (var sewer_main in connected_mains) {
    // Get the First and Last vertex
    var paths = Geometry($feature)['paths'];
    var from_point = paths[0][0]
    var to_point = paths[-1][-1]
    // Depending on where the edited feature is snapped to main, update different fields
    if (points_snapped(port_geo, from_point)) {
        updates[i++] = {
            'globalid': sewer_main.globalid,
            'attributes': {'fromid': assetid}
        }
    } else {
        updates[i++] = {
            'globalid': sewer_main.globalid,
            'attributes': {'toid': assetid}
        }
    }

}
// Return the edits
return {
    'edit': [{
        'className': 'SewerMain',
        'updates': updates
    }]
}

 

  

MelissaSalich
Occasional Contributor

I did not have success with getting this to work. 

I feel like i need to have an action calling to the point feature class (manholes) or a separate attribute rule to check if the ID has changed?

We're having a hard time trying to learn and configure Arcade, our team does not have a developer background. 

0 Kudos