//获取将输入点最近点,该线段分割成两段 public static IPolyline[] GetSubLine(IPoint point, IFeature pFeature) { try { IPolyline pLine = pFeature.Shape as IPolyline; IPolyline[] pLines = new IPolyline[2]; IPolyline StarttoPointLine = new PolylineClass(); IPolyline EndtoPointLine = new PolylineClass(); bool splithappened; int partindex, segmentindex; object pObject = Type.Missing; //IPoint IPoint = GetNearestPoint(point); pLine.SplitAtPoint(point, false, false, out splithappened, out partindex, out segmentindex); ISegmentCollection lineSegCol = (ISegmentCollection)pLine; ISegmentCollection newSegCol = (ISegmentCollection)StarttoPointLine; ISegmentCollection endSegCol = EndtoPointLine as ISegmentCollection; for (int i = 0; i < segmentindex; i++) { newSegCol.AddSegment(lineSegCol.get_Segment(i), ref pObject, ref pObject); } for (int j = segmentindex; j < lineSegCol.SegmentCount; j++) { endSegCol.AddSegment(lineSegCol.get_Segment(j), ref pObject, ref pObject); } lineSegCol.RemoveSegments(0, segmentindex, true); pLines[0] = newSegCol as IPolyline; pLines[1] = endSegCol as IPolyline; return(pLines); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "异常"); return(null); } }