ESRI.ArcGIS.Mobile
GetNearestVertex(Point,Coordinate,Int32,Int32,Double) Method
See Also  Example Send Feedback
ESRI.ArcGIS.Mobile.Geometries Namespace > Geometry Class > GetNearestVertex Method : GetNearestVertex(Point,Coordinate,Int32,Int32,Double) Method

inputPoint
Input point to compare to.
nearestVertex
Returns the nearest vertex coordinate.
partIndex
Returns the part index of the nearest coordinate.
vertexIndex
Returns the vertex index in the part.
squareDistanceFound
Returns the square distance to the closest vertex.
Finds a vertex on the geometry which is the closet one to the input point location.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub GetNearestVertex( _
   ByVal inputPoint As Point, _
   ByVal nearestVertex As Coordinate, _
   ByRef partIndex As Integer, _
   ByRef vertexIndex As Integer, _
   ByRef squareDistanceFound As Double _
) 
C# 
public void GetNearestVertex( 
   Point inputPoint,
   Coordinate nearestVertex,
   ref int partIndex,
   ref int vertexIndex,
   ref double squareDistanceFound
)

Parameters

inputPoint
Input point to compare to.
nearestVertex
Returns the nearest vertex coordinate.
partIndex
Returns the part index of the nearest coordinate.
vertexIndex
Returns the vertex index in the part.
squareDistanceFound
Returns the square distance to the closest vertex.

Exceptions

ExceptionDescription
ArgumentNullExceptionNull point.

Example

C#Copy Code
private Coordinate FindSnapCoordinate(ESRI.ArcGIS.Mobile.MapMouseEventArgs e) 

System.Drawing.Rectangle rec = new Rectangle(e.X, e.Y, 100, 100); 
Envelope envelope = map1.ToMap(rec); 
 
QueryFilter queryFilter = new QueryFilter(envelope, esriGeometricRelationship.Intersect); 
MapLayerCollection mapLayerCollection = map1.MapLayers; 
MapLayer mapLayer = mapLayerCollection["Tax Parcels"]; 
FeatureLayer featLayer = mapLayer.Layer as FeatureLayer; 
 
FeatureDataReader dataReader = featLayer.GetDataReader(queryFilter); 
 
double dist = 0; 
double minDist = double.MaxValue; 
Coordinate nearest = null; 
 
while (dataReader.Read()) 

    Geometry geometry = dataReader.GetGeometry(); 
   Coordinate c = geometry.GetNearestVertex(e.MapCoordinate, ref dist); 
   if (dist < minDist) 
   { 
     minDist = dist; 
     nearest = c; 
  } 
 } 
return nearest; 
}

Remarks

You can use GetNearestVertex to determine which coordinate on the geometry is closest to a particular point location. For example, you might be interested in determining how close the current mouse location is to a particular geometry, and further what coordinate on that geometry is the closest. You must supply a reference for a returned distance. This distance will be in map units. Use the return distance to determine if the return coordinate is the closet coordinate to the mouse location.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.