[Arcade] Splitting intersecting line with created point feature

772
2
11-09-2022 06:47 AM
StefanAngerer
Regular Contributor

Hi everybody,

I am currently trying to develop an attribute rule that allowes me to split an intersecting line when creating a point feature on that specific line. As I only found a cut function that allows to cut a polyline with another polyline, my initial guess was to just creat a dummy line at the position of the point feature that helps me splitting the line. However that seems quite complicated for a seemingly easy task. Has anybody another approach or idea how i could solve that problem? Perhaps even without using Attribute Rules? 

Thanks in advance

Stefan!

0 Kudos
2 Replies
MikeMillerGIS
Esri Frequent Contributor

An older version of the rule did use cut, if you are interested in the logic, it pasted it below.

 

function cut_line_at_point_cutter(line_feature, point_geometry) {
    var search = Extent(Buffer(point_geometry, .1, "meter"));
    var geo = Geometry(line_feature);
    var segment = Clip(geo, search)["paths"][0];
    // Rotate logic - https://stackoverflow.com/questions/45701615/how-can-i-rotate-a-line-segment-around-its-center-by-90-degrees
    // Start and end points of the line
    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]))
    line_a['paths'] = remove_vertex(line_a['paths'])
    line_b['paths'] = remove_vertex(line_b['paths'])
    return [Polyline(line_a), Polyline(line_b)]
}