Attribute rule not working anymore in 3.1

602
7
03-26-2023 11:51 PM
Zoggo
by
New Contributor III

The following code was working fine in 3.0 and 2.9 bot not anymore in 3.1. Can anyone tell me what has changed? I get an "General evaluation error" on line 3:

function getInflowStreamsWithoutConnectionVertex(polyline_) {
    var inflowStreams = [];
    var candidates = Intersects($featureSet, polyline_);
    var objectId = feature_["OBJECTID"];
    for (var inflowStream in Filter(candidates, 'OBJECTID <> @objectId')) {
        var startVertex = getFirstVertexFromPolyline(Geometry(inflowStream));
        if (Intersects(polyline_, startVertex)) {
            var result = nearestPointAlongPolyline(startVertex, polyline_);
            if (!result["isVertex"]) {
                //result['polyline'] = inflowStream;
                result['startVertex'] = startVertex;
                Push(inflowStreams, result);
            }
        }
    }
    return inflowStreams
}
function getFirstVertexFromPolyline(polyline_) {
    var segment = polyline_.paths[0];
    return segment[0]
}
function nearestPointAlongPolyline(point_, polyline_) {
    /*
        finds the closest point on line_feature from point_feature
        Args:
            point_feature: Point Geometry
            line_feature: Line Geometry
        Returns: dictionary
            {distance: number,    // distance from point_feature to closest point
             coordinates: array,  // the coordinate pair of the closest point
             isVertex: bool,      // if the closest point is a vertex of line_feature
             lineSide: text}      // side of the line that point_feature is on based
    */
    var parts = polyline_["paths"]
    var x = point_["x"];
    var y = point_["y"];
    var isVertex = false;
    // Loop through each part of the geometry and each segment, tracking the shortest distance
    var shortest = [1e10];
    for (var i in parts) {
        var vertex = parts[i];
        var previous = vertex[0];
        isVertex = Intersects(point_, previous);
        for (var j = 1; j < Count(vertex); j++) {
            var current = vertex[j];
            isVertex = isVertex || Intersects(point_, current);
            var result = getDistance(x, y, previous["x"], previous["y"], current["x"], current["y"]);
            result[4] = previous["m"];
            result[5] = current["m"];
            if (result[0] < shortest[0]) shortest = result
            previous = current;
        }
    }
    // Couldn't find anything
    if (Count(shortest) == 1) return null
    return {
        "distance": shortest[0],
        "coordinates": shortest[1],
        "isVertex": isVertex,
        "lineSide": shortest[3],
        "mBeforeVertex": shortest[4],
        "mAfterVertetx": shortest[5]
    }
}
function getDistance(x, y, x1, y1, x2, y2) {
    // adopted from https://stackoverflow.com/a/6853926
    var A = x - x1;
    var B = y - y1;
    var C = x2 - x1;
    var D = y2 - y1;
    var dot = A * C + B * D;
    var len_sq = C * C + D * D;
    var param = -1;
    if (len_sq != 0) //in case of 0 length line
        param = dot / len_sq;
    var xx, yy;
    var is_vertex = true;
    if (param < 0) {
        xx = x1;
        yy = y1;
    }
    else if (param > 1) {
        xx = x2;
        yy = y2;
    }
    else {
        is_vertex = false;
        xx = x1 + param * C;
        yy = y1 + param * D;
    }
    var dx = x - xx;
    var dy = y - yy;
    return [Sqrt(dx * dx + dy * dy), [xx, yy], is_vertex, side_of_line(x, y, x1, y1, x2, y2)];
}
function side_of_line(x, y, x1, y1, x2, y2) {
    // get side of line segment that a point (x, y) is on based on the direction of segment [[x1, y1], [x2, y2]]
    // adopted from https://math.stackexchange.com/a/274728
    var d = (x - x1) * (y2 - y1) - (y - y1) * (x2 - x1)
    if (d < 0) {
        return 'left'
    } else if (d > 0) {
        return 'right'
    } else {
        return null
    }
}
function insertVertex(polyline_, point_, mBeforeVertex) {
    var dict = Dictionary(Text(polyline_));
    var parts = dict.paths
    for (var i in parts) {
        var part = parts[i];
        for (var j = 0; j < Count(part); j++) {
            var vertex = part[j];
            if (Round(vertex[2],4) == Round(mBeforeVertex,4)) {
                var m = Round(vertex[2] + Distance(createPoint(vertex, 0, point_["spatialReference"]), point_), 4);
                Insert(dict.paths[i], j + 1, [point_['x'], point_['y'], m]);
            }
        }
    }
    dict["hasM"] = true;
    return Polyline(dict)
};
function createPoint(coordinates, m, spatial_ref) {
    // create point geometry from coordinates [x, y]
    return Point({ "x": coordinates[0], "y": coordinates[1], "m": m, "spatialReference": spatial_ref })
}
/***************************************************************************************/
var feature_ = $feature;
//var feature_ = First(Filter($featureSet, "objectId = 1"));
var inflowStreams = getInflowStreamsWithoutConnectionVertex(Geometry(feature_));
var newPolyline = Geometry(feature_);
var countInsert = 0;
for (var i in inflowStreams) {
    var info = inflowStreams[i];
    newPolyline = insertVertex(newPolyline, info['startVertex'], info['mBeforeVertex']);
    countInsert += 1;
}
/*if (Count(inflowStreams) > 0) {
}*/
return {
        "result": newPolyline,
        'edit': [{
            'className': 'AGIS_410_Dev.GEWIA.arcade_log',
            'adds': [{
                'attributes': {
                    'value': "Count Inserted Vertices: " + countInsert
                }
            }]
        }]
    }

 

0 Kudos
7 Replies
MikeMillerGIS
Esri Frequent Contributor

Could you share a repo dataset?  I am not able to reproduce it on my dataset.

0 Kudos
Zoggo
by
New Contributor III

I put the datasets in fgdb but I use this data in a enterprise geodatabase and do the validation and calculations with a service.

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

I am not sure, the test in a FGDB work fine.  I can stage a EGDB and services later to test.  I think tech support is the best avenue.  

 

MikeMillerGIS_0-1680088353335.png

 

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Can you make a pop up out of the rule and see what that returns?  You will have to swap the $FeatureSet to a FeatureSetByName($datastore,'Hydro..).  I am wondering if there is a time out issue going on.  You said you are in services.  Could that call to build the FS be doing to much.  Can you run fiddler?  Do you have Exclude from application evaluation checked for this rule?

0 Kudos
Zoggo
by
New Contributor III

Hi Mike

I get this error already during code check:

Zoggo_0-1680094558351.png

So I can't ran the validation and check with fiddler.

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

I was able to repo with simpler code, but only a dev machine in postgres.  I cannot repo it on another machine.  I am unsure what is going on.  Tech support would be the best avenue.

MikeMillerGIS_0-1680223779327.png

 

0 Kudos
HusseinNasser2
Esri Contributor

This bug will be addressed in 3.1.2 

Please use BUG-000157390 for tracking. 

0 Kudos