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
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)
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?
Hi Mike,
I want this to run each time I add or edit a hydrant.
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
}]
}
What's going on in line 4 and what's the purpose of loop within a loop?
@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.
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.
@MikeMillerGIShydrants are connected to only one line.
You can adjust the code to call First then and skip the first loop.