Query point and distance

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())
```

Splitting a line with a point

Recently I got an email where a colleague was trying to determine the distance a point on a line was from the beginning.  They were spinning their wheels looking at geometry operators and not seeing a solution.

First and foremost arcpy offers a broad broad collection of geoprocessing tools. What is perhaps less obvious is how those tools can be used directly with geometry objects. In the above scenario, using geometry as both input and output offers the solution to the problem. At a functional level, the Split Line at Points tool offers the solution. Being able to use it directly with geometry saves the hassle (and mess) of creating temporary datasets to work with.

```import arcpy

"""Splits a Polyline object with a PointGeometry object. Returns
a list of two Polyline geometries. First line will include the
starting point of the in_line. Curves are supported.

Parameters:
in_line: arcpy.Polyline
in_point: arcpy.PointGeometry
search_radius: string | float | int
Use to split the lines based on its proximity to the point.
Line will be split at the nearest location to the point.
If search_radius is 0, the point must be on the line.
Can be expressed as a number or linear unit.
"""

split_lines = arcpy.management.SplitLineAtPoint(
in_line,
in_point,
arcpy.Geometry(),
```distance = split_line_with_point(line, point)[0].length