Attach existing line endpoints to existing points

237
1
04-11-2023 08:31 AM
ShawnKraft1
New Contributor

I have stormwater laterals(lines) and inlets(points). I need to connect the laterals endpoints to the inlets. Snap doesn't seem to work as it would move the points to the lines. 

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

 

Backup your data, this will change the geometries!

 

Use the Field Calculator on the Shape field, switch to Arcade, use this script (change the first line to your point fc name)

// load your points, define the snap radius
var inlets = FeaturesetByName($datastore, "TestPoints")
var snap_radius = 5

// get the current geometry and create a copy
var geom = Geometry($feature)
var new_geom = Dictionary(Text(geom))

// we want to edit the first and last vertex -> indices 0 and -1
var vertex_indices = [0, -1]

// loop over those indices
for(var v in vertex_indices) {
    var i = vertex_indices[v]
    // get the vertex
    var p = geom.paths[i][i]
    // create a buffer around the vertex
    var p_buffer = Buffer(p, snap_Radius)
    // get the first point that is within the buffer
    var p_snap = First(Intersects(p_buffer, inlets))
    // no point found? -> skip
    if(p_snap == null) { continue }
    // change the vertex coordinates to those of the snap point
    new_geom.paths[i][i][0] = Geometry(p_snap).X
    new_geom.paths[i][i][1] = Geometry(p_snap).Y
//    new_geom.paths[i][i][3] = Geometry(p_snap).Z
}

return Polyline(new_geom)

 

Before:

JohannesLindner_0-1681229696972.png

 

After:

JohannesLindner_1-1681229755707.png

 


Have a great day!
Johannes