ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.Geometry Namespace / IGeometryEngine Interface / NearestPoint Method
The geometry.
The point to which the returned point will be nearest.
Example

In This Topic
    NearestPoint Method (IGeometryEngine)
    In This Topic
    Finds the nearest point in the geometry to a specified point.
    Syntax
    Function NearestPoint( _
       ByVal geometry As Geometry, _
       ByVal point As MapPoint _
    ) As ProximityResult

    Parameters

    geometry
    The geometry.
    point
    The point to which the returned point will be nearest.

    Return Value

    ProximityResult.

    If the input geometry is a Point, then ProximityResult.PointIndex = 0, ProximityResult.PartIndex = 0, and ProximityResult.SegmentIndex is null.

    If the input geometry is a Multipoint, ProximityResult.PointIndex is the index of the nearest point in the Multipoint, ProximityResult.PartIndex = ProximityResult.PointIndex, and ProximityResult.SegmentIndex is null.

    Otherwise, ProximityResult.PointIndex is null and ProximityResult.SegmentIndex is the segment which contains the nearest point. The segment index is relative to the ProximityResult.PartIndex. For example, if the segment index = 0 and the part index = 2, then the segment containing the nearest point is segment 0 of part 2. In other words, the segment is the first segment of the third part.

    Proximity.RightSide specifies if the input query point is on the right side of the input geometry or not.

    Exceptions
    ExceptionDescription
    Either geometry or point or both are null or empty.
    The method is not implemented for GeometryBag.
    This function is not implemented for envelopes.
    Remarks
    The nearest point does not have to be a vertex of the input geometry. It can be any point on the geometry. If the geometry is a Polygon, then the nearest point will be a point on the boundary of the Polygon.

    GeometryEngine NearestPoint

    Example
    Nearest Point versus Nearest Vertex
    SpatialReference sr = SpatialReferences.WGS84;
    MapPoint pt = MapPointBuilderEx.CreateMapPoint(5, 5, sr);
    
    List<Coordinate2D> coords = new List<Coordinate2D>()
    {
      new Coordinate2D(10, 1),
      new Coordinate2D(10, -4),
      new Coordinate2D(0, -4),
      new Coordinate2D(0, 1),
      new Coordinate2D(10, 1)
    };
    
    Polygon polygon = PolygonBuilderEx.CreatePolygon(coords);
    
    // find the nearest point in the polygon geomtry to the pt
    ProximityResult result = GeometryEngine.Instance.NearestPoint(polygon, pt);
    // result.Point = 5, 1
    // result.SegmentIndex = 3
    // result.PartIndex = 0
    // result.PointIndex = null
    //result.Distance = 4
    //result.RightSide = false
    
    // find the nearest vertex in the polgyon geometry to the pt
    result = GeometryEngine.Instance.NearestVertex(polygon, pt);
    // result.Point = 10, 1
    // result.PointIndex = 0
    // result.SegmentIndex = null
    // result.PartIndex = 0
    // result.Distance = Math.Sqrt(41)
    // result.RightSide = false
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also