Select to view content in your preferred language

How to return a Error Geometry for a validation rule

635
3
06-07-2022 12:21 AM
Zoggo
by
New Contributor III

I'm writing a validation rule for detecting duplicate vertex in a polyline. When I find a duplicate vertex I like to write the location (point) of the duplicate vertex as an error in the GDB_ValidationPointErrors feature class therefore I can find it afterwards in the Error Inspector. How can I return or write the error point geometry in the validation rule?

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

Disclaimer: I haven't worked with Validation Rules yet, only Calculation.

 

AFAIK, you can't directly write from validation rules. You just return true or false and ArcGIS creates the error feature automatically, in your case that would be a polygon.

Of course, telling your editors that there's a duplicate vertex, but not which of the 1000's of vertices is not really helpful...

You could try adding points to the point error class using a return dictionary:

return {
    "result": false,
    "edit": [
        {
            "className": "GDB_ValidationPointErrors",
            "adds": [
                {"geometry": Geometry($feature).rings[0][0]}
                ]
        }
    ]
}

I don't think that will work though, as these feature classes are special and thus probably protected. You could also try to create a new point feature class and add the duplicate vertices to that fc. That could work, but your editors would have to manually remove the points when they are finished correcting the feature.


Have a great day!
Johannes
0 Kudos
Ranga_Tolapi
Occasional Contributor III

Hi @Zoggo how did you manage this?

0 Kudos
Zoggo
by
New Contributor III

I wrote a calculation rule for fixing this:

function findDuplicateVertex(polyline_geometry) {
    var arr = [];
    var vertices = polyline_geometry.paths[0]
    for (var s = 0; s < Count(vertices) - 1; s++) {
        var p0 = vertices[s];
        var p1 = vertices[s + 1];
        if (Intersects(p0, p1)){
            if (s+1 != Count(vertices)-1){
              Push(arr, s + 1);
            } else {
              Push(arr, s);
            }
        }
    }
    return arr
}
function removeDuplicateVertex(polyline_geometry) {
    var dupVertexIndexArray = findDuplicateVertex(polyline_geometry);
    if (Count(dupVertexIndexArray) > 0) {
        var origVerteces = Dictionary(Text(polyline_geometry)).paths[0];
        var reducedVerteces = [];
        for (var s = 0; s < Count(origVerteces) ; s++) {
            if (Includes(dupVertexIndexArray, s) == false) {
                Push(reducedVerteces, origVerteces[s]);
            }
        }
        var newPolyline_geometry = Dictionary(text(polyline_geometry));
        newPolyline_geometry.paths[0] = reducedVerteces;
        return Polyline(newPolyline_geometry)
    } else {
        return
    }
}
// ************* End Functions Section ******************
var feature = $feature
//var feature = First(Filter($featureSet, 'OBJECTID = 495'));
var newPolyline_geometry = removeDuplicateVertex(Geometry(feature));
if (IsEmpty(newPolyline_geometry)) {
    return Geometry($feature)
}
return newPolyline_geometry
0 Kudos