Hello,
I am trying to create an attribute rule that split a line in two if a new point is created along this line. My rule works well when I am using it on exported datas, but when I am working with a published feature layer I get an error : object is missing. My rule also doesn't operate if I create my new point on a vertex of a line and I don't know why. I already tried using globalid instead of OBJECT_ID. Any help would be greatly appreciated ! Here is my rule :
// It is a function I found here that cuts with a point instead of a line
function cut_line_at_point_cutter(line_feature, point_geometry) {
var search = Extent(Buffer(point_geometry, .01, "meter"));
var geo = Geometry(line_feature);
var segment = Clip(geo, search)["paths"][0];
var x1 = segment[0]['x']
var y1 = segment[0]['y']
var x2 = segment[-1]['x']
var y2 = segment[-1]['y']
//find the center
var cx = (x1 + x2) / 2;
var cy = (y1 + y2) / 2;
//move the line to center on the origin
x1 -= cx;
y1 -= cy;
x2 -= cx;
y2 -= cy;
//rotate both points
var xtemp = x1;
var ytemp = y1;
x1 = -ytemp;
y1 = xtemp;
xtemp = x2;
ytemp = y2;
x2 = -ytemp;
y2 = xtemp;
//move the center point back to where it was
x1 += cx;
y1 += cy;
x2 += cx;
y2 += cy;
var cutter = Polyline({
"paths": [
[
[x1, y1],
[x2, y2]
]
],
"spatialReference": {
"wkid": geo.spatialReference.wkid
}
});
var new_lines = Cut(line_feature, cutter);
var line_a = Dictionary(Text(new_lines[0]))
var line_b = Dictionary(Text(new_lines[1]))
return [Polyline(line_a), Polyline(line_b)]
}
if ($editcontext.editType == "UPDATE" && !IsEmpty($originalFeature)) {
// Comparer la valeur actuelle de assettype avec la valeur originale
if ($feature.assettype == $originalFeature.assettype)
return ;
}
// Get line layer
var lineLayer = FeatureSetByName($datastore, "RES_EAULine");
// get what line the point intersects
var intersectingLines = Intersects($feature, lineLayer)
var lineToSplit = First(intersectingLines);
// I guess my function stops here when its a vertex, but why ?
if (IsEmpty(lineToSplit)) {
return ;
}
// get point geometry
var lineGeom = Geometry(lineToSplit);
var pointGeom = Geometry($feature);
// use my cutting function (there is no function that cuts with a point and not a line)
var newlines = cut_line_at_point_cutter(lineToSplit, pointGeom)
var newline1 = newlines[0]
var newline2 = newlines[1]
// All the logic to copy attribute, don't take into account
var attributes = {}
var excludeAttributes = ["Global_ID", "shape", "OBJECTID", "shape_Length", "GlobalID_1", "creationdate", "creator", "lastupdate", "updatedby"];var listAttributeToCopy = [];
for (var key in lineToSplit) {
if (IndexOf(excludeAttributes, key) == -1) {
Push(listAttributeToCopy, key);
}
}
for (var i = 0; i < Count(listAttributeToCopy); i++) {
if (HasKey(lineToSplit, listAttributeToCopy[i]))
attributes[listAttributeToCopy[i]] = lineToSplit[listAttributeToCopy[i]];
}
attributes["ident"] = identLine1
var line1 = {
"attributes" : attributes,
"geometry": newline1
};
attributes["ident"] = identLine2
var line2 = {
"attributes" : attributes,
"geometry": newLine2
};
return {
"edit": [{
"className": "RES_EAULine",
"adds": [line1, line2],
"deletes": [{"OBJECTID": lineToSplit["OBJECTID"]}]
}]
};