I recently upgraded to ArcGIS Pro 3.4.0. I can't say the upgrade is the culprit, but I have two attribute rules that are identical, they just pull different attributes from 2 separate feature classes, but one will not work.
The rule is a modified version of the "Left & Right Municipality" rule in the Address Data Management Solution. Below is the expression and the error. I'm really racking my brain because this rule did work initially, but something has changed that is causing it to fail now, which appears to be in a place that I have not modified the expression (Line 26). Any suggestions would be appreciated!
// This rule will calculate the left and right ESN for a road.
// It determines if the road is completely within a intersectingArea or falls on the edge of a intersectingArea and updates the appropriate values on the road
// Define the Road Centerline fields
var esnleft_field = "esnleft";
var esnright_field = "esnright";
// Define the Emergency Service Boundary fields
var name_field = "esn";
// Return if the geometry did not change
if ($editcontext.editType == "UPDATE" && Equals(Geometry($feature), Geometry($originalFeature))) return;
// Test if the feature has the left and right field, if it is missing either return
if (!HasKey($feature, esnleft_field) || !HasKey($feature, esnright_field)) return;
var esnleft = $feature[esnleft_field];
var esnright = $feature[esnright_field];
// Get the intersecting Emergency Service Boundary
var intersectingAreas = Intersects(FeatureSetByName($datastore, "ESNBoundaries", [name_field], true), $feature)
// This function will convert a polygon geometry to a polyline
function polygonToPolyline(p) {
var json = Dictionary(Text(p));
var polylineJSON = {
"paths": json["rings"],
"spatialReference": json["spatialReference"]
};
return Polyline(polylineJSON)
}
// Test if the road falls completely within a area and does not overlap any of the area's outline
// If it does update the left and right value to be equal to the area's value
var isWithin = false;
var partialOverlap = [];
for (var intersectingArea in intersectingAreas) {
if (Within($feature, intersectingArea)) {
var line = polygonToPolyline(Geometry(intersectingArea));
if (!Overlaps($feature, line)) {
var esnleft = intersectingArea[name_field];
var esnright = intersectingArea[name_field];
isWithin = true;
break;
}
// Store any boundaries the line is partially within (overlaps some of the polygons intersectingArea)
else {
Push(partialOverlap, intersectingArea);
}
}
}
// If the road does not fall within a area, attempt to find any areas that it overlaps the outline
// Then test if the polygon is on the right or left side of the line and update the right or left value
if (!isWithin) {
var isRightValue = false;
var isLeftValue = false;
for (var intersectingArea in intersectingAreas) {
var line = polygonToPolyline(Geometry(intersectingArea));
if (Within($feature, line)) {
// Offset the geometry to the right and test if it intersects the intersectingArea
var offset_geometry = Offset($feature, 20);
if (Intersects(offset_geometry, intersectingArea)) {
var esnright = intersectingArea[name_field];
isRightValue = true;
}
// Offset the geometry to the left and test if it intersects the intersectingArea
offset_geometry = Offset($feature, -20);
if (Intersects(offset_geometry, intersectingArea)) {
var esnleft = intersectingArea[name_field];
isLeftValue = true;
}
}
}
// If either the left or right value is not set we will loop through the partially within
if (!isLeftValue || !isRightValue) {
for (var i in partialOverlap) {
var intersectingArea = partialOverlap[i];
var line = polygonToPolyline(Geometry(intersectingArea));
// Get the portion of the road that overlaps the polygon intersectingArea
var intersection_geometry = Intersection($feature, line);
// Offset this portion of the road to the right and test if it intersects the intersectingArea
var offset_geometry = Offset(intersection_geometry, 20);
if (Intersects(offset_geometry, intersectingArea) && !isRightValue) {
var esnright = intersectingArea[name_field];
}
// Offset this portion of the road to the left and test if it intersects the intersectingArea
offset_geometry = Offset(intersection_geometry, -20);
if (Intersects(offset_geometry, intersectingArea) && !isLeftValue) {
var esnleft = intersectingArea[name_field];
}
}
}
}
return {
"result": {
"attributes":
Dictionary(
esnleft_field, esnleft,
esnright_field, esnright
)
}
}