Select to view content in your preferred language

Address Data Management- "Arcade error: Field not found"

297
2
Jump to solution
01-24-2025 10:02 AM
bbaker_tngeo
Regular Contributor

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!

 

bbaker_tngeo_0-1737741586166.png

 

 

 

// 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
            )
    }
}

 

 

 

0 Kudos
1 Solution

Accepted Solutions
bbaker_tngeo
Regular Contributor

Thank you for the response, Hussein. I requested a case with Tech Support and was fortunate to get a quick resolution. The issue arises when the the feature class contains curved segments which requires an additional condition in the function. I believe the "curveRings" geometry type issue began starting in ArcGIS Pro 3.3.

Here is the summary of the resolution:

We discussed the rule is failing as the feature class has "rings" as well as "curveRings" geometry. We modified the function polygonToPolyline to include rings and the curveRings geometry using an else-if conditional statement and the rule started working as expected.

    • The modified code for the function is mentioned below:
      • function polygonToPolyline(p) {
            var json = Dictionary(Text(p));
            var l = []
            for(var i in json){
              Insert(l0i)
            }
            if(Includes(l"curveRings")){     
              var polylineJSON = {
                "paths"json["curveRings"],
                "spatialReference"json["spatialReference"]
              }
            }

            else if(Includes(l"rings")){     
              var polylineJSON = {
                "paths"json["rings"],
                "spatialReference"json["spatialReference"]
              }
            }
            return Polyline(polylineJSON)
        }

Geometry objects | ArcGIS REST APIs | ArcGIS Developers

View solution in original post

2 Replies
HusseinNasser2
Esri Contributor

My guess is you might need to account for empty geometries , line 26 points to this 

      "paths": json["rings"],

 

which essentially means it couldn't find the "rings" property in the geometry object you sent to the function. So either you are sending something else (which your code doesn't look like it) or one of your features have an empty geometry that was recently added that broke your script.. 

 

try updating this function with this 

function polygonToPolyline(p) {
    var json = Dictionary(Text(p));
    if (!haskey(json, "rings")) return;
    if (!haskey(json, "spatialReference")) return;

    var polylineJSON = {
      "paths": json["rings"],
      "spatialReference": json["spatialReference"]
    };
    return Polyline(polylineJSON)
}

 

Now this script may cause other downstream failures so you might want to handle the empty geometry across the rest of the script. 

0 Kudos
bbaker_tngeo
Regular Contributor

Thank you for the response, Hussein. I requested a case with Tech Support and was fortunate to get a quick resolution. The issue arises when the the feature class contains curved segments which requires an additional condition in the function. I believe the "curveRings" geometry type issue began starting in ArcGIS Pro 3.3.

Here is the summary of the resolution:

We discussed the rule is failing as the feature class has "rings" as well as "curveRings" geometry. We modified the function polygonToPolyline to include rings and the curveRings geometry using an else-if conditional statement and the rule started working as expected.

    • The modified code for the function is mentioned below:
      • function polygonToPolyline(p) {
            var json = Dictionary(Text(p));
            var l = []
            for(var i in json){
              Insert(l0i)
            }
            if(Includes(l"curveRings")){     
              var polylineJSON = {
                "paths"json["curveRings"],
                "spatialReference"json["spatialReference"]
              }
            }

            else if(Includes(l"rings")){     
              var polylineJSON = {
                "paths"json["rings"],
                "spatialReference"json["spatialReference"]
              }
            }
            return Polyline(polylineJSON)
        }

Geometry objects | ArcGIS REST APIs | ArcGIS Developers