This recipe shows how to find the point on a specified line nearest the input point and the distance between those points.

Finding only the distance can be done using the geometry’s distanceTo() method.

distance = point.distanceTo(line)

If you need to find the distance and the closest point on the line, use the Generate Near Table tool. As shown in the previous recipe, geometry objects can be inputs to Geoprocessing tools.

# Find the closest point on a line. Also, return the location of that closest point.
near_result = arcpy.analysis.GenerateNearTable(
point,
line,
r'in_memory\neartable',
'',
'LOCATION',
'NO_ANGLE',
'CLOSEST')
with arcpy.da.SearchCursor(near_result, ['NEAR_DIST', 'NEAR_X', 'NEAR_Y']) as rows:
row = rows.next()
distance = row[0]
x = row[1]
y = row[2]

Our previous recipe demonstrates how to split a line with a point. In this case, if you needed to split the line, you can either do two things:

1. Use the distance as search radius for the Split Line at Point tool:

split_lines = arcpy.management.SplitLineAtPoint(
in_line,
in_point,
arcpy.Geometry(),
distance)

2. Construct a point geometry and use it as the input points for the Split Line At Point tool.

pnt_on_line = arcpy.PointGeometry(arcpy.Point(x, y), point.spatialReference)
split_lines = arcpy.management.SplitLineAtPoint(
in_line,
pnt_on_line,
arcpy.Geometry())

### Like this:

Like Loading...

*Related*