I have two datasets that I am trying to form into a network, one representing pedestrian and bike paths, the other representing roads.

The lines do not connect together (as seen in the picture below) and I would like to know if there are any automated ways to connect the end-points of each line segment from the two layers together?

Screen shot

  • Do actually want to do that? If you run these data through the Dissolve tool the geometries will be combined into a single line as in your example above, but you'll loose any attribution. – Hornbydd Jun 14 '18 at 18:03
  • I do need to keep attribution, yes. I am modeling bike travel. i just need to connect these lines together so a person on a bike can move between roads and paths. – Alex Jun 14 '18 at 18:12

You can use ArcPy. A new polyline feature class will be created with the connection lines. You can execute the code in the Python window of ArcMap after changing input data names and maxdistance (the max distance between ends for a connection line to be created)

import arcpy

#Change these four lines to match your data (whats on the right side of the equal to signs)
arcpy.env.workspace = r'C:\Users\bera\Documents\ArcGIS\Projects\MyProject\MyProject.gdb'
bike = 'Bike'
walking = 'Walking'
connect = 'Connect' #Name of the new feature class to be created

maxdistance = 100

#List all start and endpoints as pointgeometries
bike_ends =  [arcpy.PointGeometry(j) for k in [[i[0].firstPoint, i[0].lastPoint] for i in arcpy.da.SearchCursor(bike,'SHAPE@')] for j in k]
walking_ends = [arcpy.PointGeometry(j) for k in [[i[0].firstPoint, i[0].lastPoint] for i in arcpy.da.SearchCursor(walking,'SHAPE@')] for j in k]

#Find and list the pairs within maxdistance
ends_to_connect = []
for b in bike_ends:
    for w in walking_ends:
        if b.distanceTo(w) <= maxdistance:

#Create polylines from point pairs
polylines = [arcpy.Polyline(arcpy.Array(pair)) for pair in ends_to_connect]
arcpy.CopyFeatures_management(in_features=polylines, out_feature_class=connect)

Result: enter image description here


If you have an advanced license you can select each line type separately and extract the end points of the lines into two new feature classes using the Feature Vertices to Points tool. (If you do not have an advanced license you can still extract the end points by calculating the X and Y of the ends into fields of the line feature, exporting the output to a table, and using the Make XY Layer tool to create point features for the next step). Then you can use the Near Tool with the Location and Angle Options checked to get one of the points to have attributes needed to create a line. Open the table view of the Near features and export them to a table. Then you can use the Bearing Distance to Line tool to create a line feature from the distance and angle of the Near output. Then append those lines to your feature class and attribute them with the end point data you extracted in the first step.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.