private void btnConstructMultiPolyline_Click(object sender, EventArgs e) { if (gfactory == null) gfactory = new GeometryFactory(); multiPolyline = gfactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolyline, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolyline; if (multiPolyline == null) return; // 添加两条Polyline point = gfactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); polyline = gfactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; int length = 100; for (int i = 0; i < length; i++) { point.SetCoords(i, 2 * i, 0, 0, i + 1); polyline.AppendPoint(point); } IPolyline polylineClone = polyline.Clone() as IPolyline; polylineClone.RemovePoints(50, 50); multiPolyline.AddPolyline(polyline); multiPolyline.AddPolyline(polylineClone); MultiCurve geo = new MultiCurve(); // Geometry属性 geo.Dimension = multiPolyline.Dimension; if (multiPolyline.Envelope != null) { geo.MaxX = multiPolyline.Envelope.MaxX; geo.MaxY = multiPolyline.Envelope.MaxY; geo.MaxZ = multiPolyline.Envelope.MaxZ; geo.MinX = multiPolyline.Envelope.MinX; geo.MinY = multiPolyline.Envelope.MinY; geo.MinZ = multiPolyline.Envelope.MinZ; } geo.GeometryType = multiPolyline.GeometryType; geo.IsEmpty = multiPolyline.IsEmpty; geo.IsValid = multiPolyline.IsValid; geo.VertexAttribute = multiPolyline.VertexAttribute; geo.HasId = multiPolyline.HasId(); geo.HasM = multiPolyline.HasM(); geo.HasZ = multiPolyline.HasZ(); // GeometryCollection属性 geo.GeometryCount = multiPolyline.GeometryCount; geo.IsOverlap = multiPolyline.IsOverlap; // MultiCurve属性 geo.Length = multiPolyline.Length; this.propertyGrid1.SelectedObject = geo; }
private void ReversePolyline(ref IPolyline ply) { if ((ply != null) && (ply.PointCount != 0)) { Stack <IPoint> stack = null; stack = new Stack <IPoint>(); for (int i = 0; i < ply.PointCount; i++) { stack.Push(ply.GetPoint(i)); } ply.RemovePoints(0, ply.PointCount); while (stack.Count > 0) { ply.AppendPoint(stack.Pop()); } } }
// Shap数据中含各顶点高程数据 private bool GetPipeLineVertexs(IGeometry geo, double sHeight, double eHeight, out IPolyline route) { route = null; try { IPolyline polyline = null; if ((geo == null) || ((polyline = geo as IPolyline) == null)) { return(false); } IPoint pointValue = null; route = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; if (polyline.PointCount == 2) { pointValue = polyline.StartPoint.Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint; pointValue.Z = sHeight; route.AppendPoint(pointValue); pointValue = polyline.EndPoint.Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint; pointValue.Z = eHeight; route.AppendPoint(pointValue); } else { IPoint point; Stack <int> stack = new Stack <int>(); double num4 = eHeight - sHeight; if (Math.Abs(num4) < 0.0015) { point = null; for (int i = 0; i < polyline.PointCount; i++) { pointValue = polyline.GetPoint(i).Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint; if (i < 1) { pointValue.Z = sHeight; route.AppendPoint(pointValue); point = pointValue; } else if (Math.Sqrt(((pointValue.X - point.X) * (pointValue.X - point.X)) + ((pointValue.Y - point.Y) * (pointValue.Y - point.Y))) < (this._dia1 * 1.5)) { stack.Push(i); } else { pointValue.Z = sHeight; route.AppendPoint(pointValue); point = pointValue; } } } else { double num3 = sHeight; IPolyline o = polyline.Clone2(gviVertexAttribute.gviVertexAttributeNone) as IPolyline; double length = o.Length; Marshal.ReleaseComObject(o); point = null; for (int j = 0; j < polyline.PointCount; j++) { pointValue = polyline.GetPoint(j).Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint; if (j < 1) { pointValue.Z = sHeight; route.AppendPoint(pointValue); point = pointValue; } else { double num2; if ((num2 = Math.Sqrt(((pointValue.X - point.X) * (pointValue.X - point.X)) + ((pointValue.Y - point.Y) * (pointValue.Y - point.Y)))) < (this._dia1 * 1.5)) { stack.Push(j); } else { num3 += (num2 / length) * num4; pointValue.Z = num3; route.AppendPoint(pointValue); point = pointValue; } } } } while (stack.Count > 0) { polyline.RemovePoints(stack.Pop(), 1); } } return(true); } catch (Exception exception) { return(false); } }