I am working on a tool to convert point to line using ArcObjects in C#. I can understand the arcpy function but is there an example to show how to convert a point layer into a line feature and save as a new line layer? Any code snippet will help.#PointsToLine
You could call the existing geo-processing tool, that would be easiest. One way to do this is to be using the IGeoProcessor object and call the tool.
Search the API help there are numerous examples of tools being run using this approach.
This is a portion of the code I used in a tool that converted points (pPointFLayer) to a line (pLineFLayer)
Dim pPointFLayer As ESRI.ArcGIS.Carto.IFeatureLayer
Dim pFCursor As ESRI.ArcGIS.Geodatabase.IFeatureCursor
Dim pFeature As ESRI.ArcGIS.Geodatabase.IFeature
Dim pFirstPointShape As ESRI.ArcGIS.Geometry.IGeometry
Dim pFirstPoint As ESRI.ArcGIS.Geometry.IPoint
Dim pSecondPointShape As ESRI.ArcGIS.Geometry.IGeometry
Dim pSecondPoint As ESRI.ArcGIS.Geometry.IPoint
Dim pLine As ESRI.ArcGIS.Geometry.ILine
Dim pSegColl As ESRI.ArcGIS.Geometry.ISegmentCollection
Dim pGeomColl As ESRI.ArcGIS.Geometry.IGeometryCollection
Dim pPolyline As ESRI.ArcGIS.Geometry.IPolyline
Dim pIFBuffer As ESRI.ArcGIS.Geodatabase.IFeatureBuffer
Dim pIFCursor As ESRI.ArcGIS.Geodatabase.IFeatureCursor
pIFCursor = pLineFLayer.FeatureClass.Insert(True)
pIFBuffer = pLineFLayer.FeatureClass.CreateFeatureBuffer
pFCursor = pPointFLayer.Search(Nothing, False)
pFeature = pFCursor.NextFeature
Do Until pFeature Is Nothing
FirstGroupID = pFeature.Value(pFeature.Fields.FindField(cboField.Text))
pFirstPointShape = pFeature.Shape
pFirstPoint = pFirstPointShape
pFeature = pFCursor.NextFeature
If pFeature Is Nothing Then Exit Do
pSecondPointShape = pFeature.Shape
pSecondPoint = pSecondPointShape
pLine = CreateLn(pFirstPoint, pSecondPoint)
pSegColl = New ESRI.ArcGIS.Geometry.Path
pSegColl.AddSegment(pLine)
pGeomColl = New ESRI.ArcGIS.Geometry.Polyline
pGeomColl.AddGeometry(pSegColl)
pPolyline = pGeomColl
pIFBuffer.Shape = pPolyline
pIFCursor.InsertFeature(pIFBuffer)
Loop
Private Function CreateLn(ByRef pPointFrom As ESRI.ArcGIS.Geometry.IPoint, ByVal pPointTo As ESRI.ArcGIS.Geometry.IPoint) As ESRI.ArcGIS.Geometry.ILine
CreateLn = New ESRI.ArcGIS.Geometry.Line
CreateLn.PutCoords(pPointFrom, pPointTo)
End Function