Arcade expression to populate a field from one point layer to another that are on the same line

768
13
01-17-2024 09:33 AM
GIS_geek
New Contributor III

Hello,

My organization is moving from Geometric Network to Utility Network and that means we have to move all of our Attribute Assistant methods to Attribute Rules. I was hoping to get assistance on one of them.

We number fire hydrants based on the corresponding valve. Both points are on the same line and that is the only relationship between them.  All three features (hydrant, valve, and line) are in the same geodatabase.  The attached code I am running comes up with an error  mentioning "Invalid expression. Error on line 5. Wrong number of arguments." Hoping to get some help on this.

 

var valves = FeatureSetByName($datastore, "dwSystemValve");
var hydrants = FeatureSetByName($datastore, "dwHydrant");
var fireLines = FeatureSetByName($datastore, "dwLateralLine");

var intersectingValve = Intersects(valves, fireLines, true);
var intersectingHydrant = Intersects(hydrants, fireLines, true);

var commonFireLine = Filter(intersectingValve, intersectingHydrant);

var valveField = "NUM";
var hydrantField = "NUM";

var result = {};

for (var i in commonFireLine) {
    var valveValue = commonFireLine[i].attributes[valveField];
    var hydrantValue = commonFireLine[i].attributes[hydrantField];

    result[valveValue] = hydrantValue;
}

result

 

 

13 Replies
MikeMillerGIS
Esri Frequent Contributor

Vavles is a featureset, sort like the path to the class on disk.  You cannot intersect a featureSet with a featureSet.  You need to loop over the features, such as for (var feat in valves)

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Bigger question, what and when do you want this rule to fire?  Is this something you want run on the entire database?  Do you want it to run each time you edit a hydrant, or valve, etc?  

GIS_geek
New Contributor III

Hi Mike,

I want this to run each time I add or edit a hydrant.

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Hopefully this gets you closer

 

var valves = FeatureSetByName($datastore, "dwSystemValve");
var fireLines = FeatureSetByName($datastore, "dwLateralLine");

var intersecting_lines = Intersects(fireLines, $feature);

valves_to_update = [];
for (var lat_line in intersecting_lines)
{
    var intersecting_valves = Intersects(valves, lat_line);
    for(var valve in intersecting_valves){
        push(valves_to_update, {'globalID':valve.globalid,
            'attributes': {
                'num': lat_line.num
            }})
    }
}

return {
    'edit': [{
        'className': 'valve',
        'updates': valves_to_update
    }]
}

 

Ed_
by MVP Regular Contributor
MVP Regular Contributor

What's going on in line 4 and what's the purpose of loop within a loop?

Question | Analyze | Visualize
0 Kudos
GIS_geek
New Contributor III

@Ed_  A lot of this was from other code I found in other forums. I thought applied to what I am trying to accomplish so I was testing it out.

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

If you are referring to my post, line 4 intersects the hydrant with the lateral lines.  As the OP said they want this to run on the hydrant.  Is every hydrant connected to only one line?  I have no idea, I do not have access to his data, so without that knowledge, the only safe way to code it is loop over all results and find the valves that are connected to each lateral line.  Now in reality, hydrants connect to one line, so I could have called First() on the result, but that info was not provided.

0 Kudos
GIS_geek
New Contributor III

@MikeMillerGIShydrants are connected to only one line.

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

You can adjust the code to call First then and skip the first loop. 

0 Kudos