Hello,
I have not been able to make a proper code as I am new to Arcade. What I want to do is, split a line feature A by a start point of another line feature B. When I draw a line B from somewhere on the line A, the line A is split at the start point of line B. Also, the feature A has field "ID_A". For example, value of 10, the attribute of the "ID_A" is going to be updated to 11 and 12 respectively when the feature A is split into two features.
Based on a code that I found on web, I managed to prepare a code to split a line by a point feature. This works well that also achieve the update of attribute with using NextSequenceValue. But I am struggling to achieve this using a line feature instead of a point.
Much appreciated if anyone give me hint.
It seems like you have all the ingredients. Just use the first point of your new line B as split feature.
var start_point = Geometry($feature).paths[0][0]
var fs_line_a = FeatureSetByName($datastore, "LineA", ["GlobalID"], true)
var result = {"geometry": Geometry($feature)}
var edit_line_a = {"className": "LineA", "adds": [], "deletes": []}
for(var s in Intersects(fs_line_a, start_point)) {
var path = Geometry(s).paths[0]
// we don't care about intersections with start or end points of LineA features
if(Intersects(path[0], start_point) || Intersects(path[-1], start_point)) {
continue
}
// construct cutter
var clip_path = Clip(Geometry(s), Extent(Buffer(start_point, 0.1))).paths[0]
var a = (Angle(clip_path[0], clip_path[-1]) + 90) * PI/180
var m_geometry = Geometry($feature)
var cutter = Polyline({
"paths": [ [
[start_point.x - 0.1 * cos(a), start_point.y - 0.1 * sin(a)],
[start_point.x + 0.1 * cos(a), start_point.y + 0.1 * sin(a)]
] ],
"spatialReference": Geometry($feature).spatialReference
})
// cut LineA feature
var line_a_cuts = Cut(Geometry(s), cutter)
// delete the intersected LineA feature
Push(edit_line_a .deletes, {"globalID": s.GlobalID})
// add both cut parts
Push(edit_line_a .adds, {"geometry": line_a_cuts[0], "attributes": {"ID_A": NextSequenceValue("ID_A"}})
Push(edit_line_a .adds, {"geometry": line_a_cuts[-1], "attributes": {"ID_A": NextSequenceValue("ID_A"}})
}
// return
return {"result": result, "edit": [edit_line_a ]}