ArcObjects Library Reference  (Geometry)    

ICurve_QueryPoint(s)_Example

[Visual Basic 6.0]
 ' The example shows how to query the from and to points of a curve.
 ' Run the script from an ArcMap edit session. Start editing, select
 ' a feature and run the script.
 
 Public Sub t_ICurve_QueryPoints()
   Dim pID As New UID
   pID = "esriEditor.editor"
   Dim pEditor As IEditor
   Dim pApp As IApplication
   Set pApp = MxApplication
   Set pEditor = pApp.FindExtensionByCLSID(pID)
   
   If   pEditor.SelectionCount <> 1 Then
     MsgBox "select one Curve"
     Exit Sub
   End If
   
   Dim pEnumFeat As IEnumFeature
   Dim pFeature As IFeature
 
   Set pEnumFeat = pEditor.EditSelection
 
   Dim pCurve As ICurve
   Dim pPointFrom As IPoint
   Dim pPointTo As IPoint
   
   Set pPointFrom = New Point
   Set pPointTo = New Point
 
   Set pFeature = pEnumFeat.Next
 
   While Not pFeature Is Nothing
     If pFeature.Shape.GeometryType = esriGeometryPolyline Or _
     esriGeometryPolyline Or esriGeometryLine Then
       Set pCurve = pFeature.Shape
       pCurve.QueryFromPoint pPointFrom
       pCurve.QueryToPoint pPointTo
       MsgBox "+++ICurve properties..." & vbCrLf _
         & "Curve.QueryFromPoint (x,y) = " & pPointFrom.X & "," & pPointFrom.Y & vbCrLf _
         & "Curve.QueryToPoint (x,y) = " & pPointTo.X & "," & pPointTo.Y & vbCrLf
     End If
     Set pFeature = pEnumFeat.Next
   Wend
 End Sub

[C#]
//The example shows how to query the from and to points of a curve.
//Run the script from an ArcMap edit session. Start editing, select
//a feature and run the script.
public void QueryPoints()
{
  UID editorUID = new UIDClass();
  editorUID.Value = "esriEditor.editor";
  IEditor editor = m_application.FindExtensionByCLSID(editorUID) as IEditor;
  if (editor.SelectionCount != 1)
  {
    System.Windows.Forms.MessageBox.Show("Start editing and select exactly one polygon or polyline");
    return;
  }
  IEnumFeature featureEnumeration = editor.EditSelection;
  IFeature currentFeature = featureEnumeration.Next();
  while (currentFeature != null)
  {
    if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline ||
        currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryLine)
    {
        ICurve curve = currentFeature.Shape as ICurve;
        IPoint fromPoint = new PointClass();   
        IPoint toPoint = new PointClass();
        curve.QueryFromPoint(fromPoint);
        curve.QueryToPoint(toPoint);
        System.Windows.Forms.MessageBox.Show("ICurve properties..." + "\n" +
                        "Curve.QueryFromPoint (x,y) = " + fromPoint.X + "," + fromPoint.Y + "\n" +
                        "Curve.QueryToPoint (x,y) = " + toPoint.X + "," + toPoint.Y); 
    }
    
    currentFeature = featureEnumeration.Next();
    
  }
}

[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.