/// <summary> /// 通过点集创建线段(IPolyline对象) /// </summary> /// <param name="pts"></param> /// <returns></returns> public static IPolyline CreatePolyline(IPoint[] pts) { var segments = new List <ISegment>();//存放单条线的每一段(Line对象) for (int i = 0; i < pts.Length - 1; i++) { Line line = new LineClass(); line.PutCoords(pts[i], pts[i + 1]); segments.Add((ISegment)line); } ISegment[] segmentArray = segments.ToArray();//存放单条线的每一段(Line对象) ISegmentCollection segmentCollection = new PolylineClass(); IGeometryBridge geometryBridge = new GeometryEnvironmentClass(); geometryBridge.AddSegments(segmentCollection, ref segmentArray); IPolyline polyLine = segmentCollection as IPolyline; return(polyLine); }
//查询Segment private void querySegmentsToolStripMenuItem_Click(object sender, EventArgs e) { ISegment[] segmentArray = new ISegment[10]; for (int i = 0; i < 10; i++) { ILine line = new LineClass(); IPoint fromPoint = new PointClass(); fromPoint.PutCoords(i * 10, i * 10); IPoint toPoint = new PointClass(); toPoint.PutCoords(i * 15, i * 15); line.PutCoords(fromPoint, toPoint); segmentArray[i] = line as ISegment; } ISegmentCollection segmentCollection = new PolylineClass(); IGeometryBridge geometryBridge = new GeometryEnvironmentClass(); geometryBridge.AddSegments(segmentCollection, ref segmentArray); int index = 0; ISegment[] outputSegmentArray = new ISegment[segmentCollection.SegmentCount - index]; for (int i = 0; i < outputSegmentArray.Length; i++) { outputSegmentArray[i] = new LineClass(); } //查询Segment geometryBridge.QuerySegments(segmentCollection, index, ref outputSegmentArray); String report = ""; for (int i = 0; i < outputSegmentArray.Length; i++) { ISegment currentSegment = outputSegmentArray[i]; ILine currentLine = currentSegment as ILine; report = report + "index = " + i + " , FromPoint X = " + currentLine.FromPoint.X + " , FromPoint Y = " + currentLine.FromPoint.X; report = report + " , ToPoint X = " + currentLine.ToPoint.X + " , ToPoint Y = " + currentLine.ToPoint.X + "\n"; } System.Windows.Forms.MessageBox.Show(report); }
//创建线对象 private void CreatePolyline() { ISegment[] segmentArray = new ISegment[10]; IPolyline polyline = new PolylineClass(); for (int i = 0; i < 10; i++) { ILine line = new LineClass(); IPoint fromPoint = new PointClass(); fromPoint.PutCoords(i * 10, i * 10); IPoint toPoint = new PointClass(); toPoint.PutCoords(i * 15, i * 15); line.PutCoords(fromPoint, toPoint); segmentArray[i] = line as ISegment; } ISegmentCollection segmentCollection = new PolylineClass(); IGeometryBridge geometryBridge = new GeometryEnvironmentClass(); geometryBridge.AddSegments(segmentCollection, ref segmentArray); polyline = segmentCollection as IPolyline; addFeature("polyline", polyline as IGeometry); this.axMapControl1.Extent = polyline.Envelope; this.axMapControl1.Refresh(); }
private IGeometry BufferBoundary(IRing currentRing, double bufferDistance, bool draw) { ISegmentCollection polyline = new PolylineClass() as ISegmentCollection; ISegmentCollection ringSegmentCollection = currentRing as ISegmentCollection; List <ISegment> ringSegments = new List <ISegment>(); for (int i = 0; i < ringSegmentCollection.SegmentCount; i++) { ringSegments.Add(ringSegmentCollection.get_Segment(i)); } ISegment[] ringSegmentsArray = ringSegments.ToArray(); IGeometryBridge geometryBridge = new GeometryEnvironmentClass(); geometryBridge.AddSegments(polyline, ref ringSegmentsArray); ITopologicalOperator topoBndBuffer = polyline as ITopologicalOperator; IGeometry bndBuffer = topoBndBuffer.Buffer(bufferDistance); if (draw) { DrawGraphics(bndBuffer); } return(bndBuffer); }