public void CanTest2SegmentCircle() { IFeatureClass fc = CreateLineClass(_testWs, "CanTest2SegmentCircle"); IFeature row1 = fc.CreateFeature(); IConstructCircularArc arc = new CircularArcClass(); arc.ConstructCircle(GeometryFactory.CreatePoint(0, 0, 0), 3, false); IPolyline polyline = CreatePolyLine((ISegment)arc); int segmentIndex; int newPartIndex; bool splitHappened; polyline.SplitAtDistance(0.5, true, false, out splitHappened, out newPartIndex, out segmentIndex); Assert.True(splitHappened); row1.Shape = polyline; row1.Store(); var test = new QaMinSegAngle(fc, 0.1, true); var runner = new QaContainerTestRunner(1000, test); runner.Execute(); // assert that two segment closed curve does not always report two // errors when using linearized segments Assert.AreEqual(0, runner.Errors.Count); }
//三点法构造弧段的Segment private ISegment MadeArcSeg_3Point(IPoint pPoint1, IPoint pPoint2, IPoint pPoint3) { IConstructCircularArc pArc = new CircularArcClass(); pArc.ConstructThreePoints(pPoint1, pPoint2, pPoint3, true); return((ISegment)pArc); }
//构造圆弧点 private void button1_Click(object sender, EventArgs e) { delFeature("point"); //构造一段圆弧 IPoint centerPoint = new PointClass(); centerPoint.PutCoords(10, 0); IPoint fromPoint = new PointClass(); fromPoint.PutCoords(0, 0); IPoint toPoint = new PointClass(); toPoint.PutCoords(0, 20); IConstructCircularArc circularArcConstruction = new CircularArcClass(); circularArcConstruction.ConstructThreePoints(fromPoint, centerPoint, toPoint, false); //构造圆弧点 IConstructMultipoint constructMultipoint = new MultipointClass(); constructMultipoint.ConstructArcPoints(circularArcConstruction as ICircularArc); IPointCollection pointCollection = constructMultipoint as IPointCollection; for (int i = 0; i < pointCollection.PointCount; i++) { addFeature("point", pointCollection.get_Point(i)); } axMapControl1.Refresh(); }
//构造等长点 private void button3_Click(object sender, EventArgs e) { delFeature("point"); IPoint centerPoint = new PointClass(); centerPoint.PutCoords(10, 0); IPoint fromPoint = new PointClass(); fromPoint.PutCoords(0, 0); IPoint toPoint = new PointClass(); toPoint.PutCoords(0, 20); ICircularArc circularArcConstruction = new CircularArcClass(); circularArcConstruction.PutCoords(centerPoint, fromPoint, toPoint, esriArcOrientation.esriArcClockwise); IConstructMultipoint constructMultipoint = new MultipointClass(); constructMultipoint.ConstructDivideLength(circularArcConstruction as ICurve, 10); IPointCollection pointCollection = constructMultipoint as IPointCollection; for (int i = 0; i < pointCollection.PointCount; i++) { addFeature("point", pointCollection.get_Point(i)); } axMapControl1.Refresh(); }
private void btnOK_Click(object sender, EventArgs e) { double num = double.Parse(this.txtXCoor.Text); double num2 = double.Parse(this.txtYCoor.Text); double radius = double.Parse(this.txtRadio.Text); if (this.imap_0.MapUnits != esriUnits.esriKilometers) { num *= 1000.0; num2 *= 1000.0; radius *= 1000.0; } IPoint centerPoint = new PointClass { X = num, Y = num2 }; ICircularArc arc = new CircularArcClass(); (arc as IConstructCircularArc).ConstructCircle(centerPoint, radius, false); ISegmentCollection segments = new PolygonClass(); object before = Missing.Value; segments.AddSegment(arc as ISegment, ref before, ref before); this.igeometry_0 = segments as IGeometry; base.DialogResult = DialogResult.OK; }
private ICircularArc CreateCircleArc(IPoint point, double radius, bool isCounterCW) { ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc2 constructCircularArc = circularArc as IConstructCircularArc2; constructCircularArc.ConstructCircle(point, radius, isCounterCW); return(circularArc); }
//点+半径转圆几何 public static IGeometry GetCircleGeometry(IPoint pPoint, double radius) { ICircularArc pCircularArc = new CircularArcClass(); IConstructCircularArc pConstructCircularArc = pCircularArc as IConstructCircularArc; pConstructCircularArc.ConstructCircle(pPoint, radius, true); return GetCircleGeometry(pCircularArc); }
public static ICircularArc ConstructCircle(IPoint centerPoint, double radius) { ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc constructCircluarArc = circularArc as IConstructCircularArc; constructCircluarArc.ConstructCircle(centerPoint, radius, true); return(circularArc); }
public static ICircularArc ConstructCircularArc(IPoint centerPoint, IPoint fromPoint, bool isCCW, double arcDistance) { ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc constructCircluarArc = circularArc as IConstructCircularArc; constructCircluarArc.ConstructArcDistance(centerPoint, fromPoint, isCCW, arcDistance); return(circularArc); }
/// <summary> /// 构造圆形对象 /// </summary> /// <param name="point"></param> /// <param name="radius"></param> /// <param name="isCCW"></param> /// <returns></returns> public ICircularArc CreateCircleArc(IPoint point, double radius, bool isCCW) { ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc construtionCircularArc = circularArc as IConstructCircularArc; construtionCircularArc.ConstructCircle(point, radius, isCCW); return(circularArc); }
/// <summary> /// 通过开始点和结束点创建半圆弧片段 /// </summary> /// <param name="fromPoint">开始点</param> /// <param name="toPoint">结束点</param> /// <returns>半圆弧片段</returns> public static ISegment CreateHalfCircularArcByTwoPoints(IPoint fromPoint, IPoint toPoint) { ILine line = CreateLineByTwoPoints(fromPoint, toPoint); ILine normal = new LineClass(); line.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, (double)(line.Length / 2.0), normal); IConstructCircularArc Constructor = new CircularArcClass(); Constructor.ConstructThreePoints(fromPoint, normal.ToPoint, toPoint, true); return((ISegment)Constructor); }
//构造交点 private void button4_Click(object sender, EventArgs e) { delFeature("point"); IPoint[] points = new IPoint[4]; for (int i = 0; i < 4; i++) { points[i] = new PointClass(); } points[0].PutCoords(15, 10); points[1].PutCoords(20, 60); points[2].PutCoords(40, 60); points[3].PutCoords(45, 10); addFeature("point", points[0]); addFeature("point", points[1]); addFeature("point", points[2]); addFeature("point", points[3]); //构造Bezier曲线 IBezierCurveGEN bezierCurve = new BezierCurveClass(); bezierCurve.PutCoords(ref points); IPoint centerPoint = new PointClass(); centerPoint.PutCoords(30, 30); IPoint fromPoint = new PointClass(); fromPoint.PutCoords(10, 10); IPoint toPoint = new PointClass(); toPoint.PutCoords(50, 10); //构造圆弧 IConstructCircularArc circularArcConstruction = new CircularArcClass(); circularArcConstruction.ConstructThreePoints(fromPoint, centerPoint, toPoint, false); object param0; object param1; object isTangentPoint; IConstructMultipoint constructMultipoint = new MultipointClass(); constructMultipoint.ConstructIntersection(circularArcConstruction as ISegment, esriSegmentExtension.esriNoExtension, bezierCurve as ISegment, esriSegmentExtension.esriNoExtension, out param0, out param1, out isTangentPoint); IMultipoint multipoint = constructMultipoint as IMultipoint; IPointCollection pointCollection = multipoint as IPointCollection; for (int i = 0; i < pointCollection.PointCount; i++) { addFeature("point", pointCollection.get_Point(i)); } axMapControl1.Extent = multipoint.Envelope; axMapControl1.Refresh(); }
public CurveConstruction CircleTo([NotNull] IPoint point) { var segments = (ISegmentCollection)Curve; ISegment lastSeg = segments.get_Segment(segments.SegmentCount - 1); IConstructCircularArc arc = new CircularArcClass(); const bool atFrom = false; arc.ConstructTangentAndPoint(lastSeg, atFrom, point); object missing = Type.Missing; ((ISegmentCollection)Curve).AddSegment((ISegment)arc, ref missing, ref missing); return(this); }
// 创建弧线 private IPolyline CreateCirculeArc(IPoint fromPoint, IPoint toPoint, double chordCoef) { // 如果起点和终点相等,返回一个直线 if (fromPoint.X == toPoint.X && fromPoint.Y == toPoint.Y) { object missing = Type.Missing; IPolyline polyline = new PolylineClass(); var pointCol = (IPointCollection)polyline; pointCol.AddPoint(fromPoint, missing, missing); pointCol.AddPoint(toPoint, missing, missing); return(polyline); } // 根据起止点建立直线A方程, // 利用A线上的中点建立与A线垂直的线方程, // 利用与中点的距离确定直线A两侧对称点 double midX = (fromPoint.X + toPoint.X) / 2; double midY = (fromPoint.Y + toPoint.Y) / 2; double k = (fromPoint.Y - toPoint.Y) / (fromPoint.X - toPoint.X); // 直线斜率 double h = Math.Pow(Math.Pow((fromPoint.Y - toPoint.Y), 2.0) + Math.Pow((fromPoint.X - toPoint.X), 2.0), 0.5); // 直线长 double h2 = h * chordCoef; // 获得0.1, 0.2, 0.3...倍的直线长 //double sign = Math.Pow(-1, offsetCount - 1); // 左右对称点符号 double sign = 1; // 表示正负号 if (fromPoint.X > toPoint.X) { sign = -1; } else if (fromPoint.X == toPoint.X && fromPoint.Y > toPoint.Y) { sign = -1; } double x = midX + sign * (-1) * chordCoef * h2 * k / Math.Pow(1 + k * k, 0.5); // 求解后的x double y = midY + sign * chordCoef * h2 / Math.Pow(1 + k * k, 0.5); // 求解后的y IPoint arcPoint = new PointClass(); arcPoint.PutCoords(x, y); IConstructCircularArc2 circularArc = new CircularArcClass(); circularArc.ConstructThreePoints(fromPoint, arcPoint, toPoint, true); IPolyline circularPolyline = new PolylineClass(); var segementColl = (ISegmentCollection)circularPolyline; var segment = (ISegment)circularArc; segementColl.AddSegment(segment); return(circularPolyline); }
private int AddCepGraphic(IPoint point, IList <double> circleRadii) { //Create a new center point graphic IMarkerSymbol symbol = new SimpleMarkerSymbolClass(); symbol.Color = EsriColor(Defaults.CepCenterPointColor); symbol.Size = Defaults.CepCenterPointSize; IElement centerPoint = new MarkerElementClass(); ((IMarkerElement)centerPoint).Symbol = symbol; centerPoint.Geometry = point; //Create a graphic group and add the center point graphic IGroupElement group = new GroupElementClass(); group.AddElement(centerPoint); //Add the circles to the group for (int i = 0; i < circleRadii.Count; i++) { IConstructCircularArc arc = new CircularArcClass(); arc.ConstructCircle(point, circleRadii[i], false); IGeometry polygon = new PolygonClass(); ((ISegmentCollection)polygon).AddSegment((ISegment)arc); IElement circle = new CircleElementClass(); circle.Geometry = polygon; Color circleColor = Defaults.CepCircleOutlineColors.Length > i ? Defaults.CepCircleOutlineColors[i] : Defaults.CepCircleOutlineColors[Defaults.CepCircleOutlineColors.Length - 1]; double circleWidth = Defaults.CepCircleOutlineWidths.Length > i ? Defaults.CepCircleOutlineWidths[i] : Defaults.CepCircleOutlineWidths[Defaults.CepCircleOutlineWidths.Length - 1]; ((IFillShapeElement)circle).Symbol = GetCircleSymbol(circleColor, circleWidth); group.AddElement(circle); } //Give it the group an id number and add it to the graphics layer _elementId++; ((IElementProperties)group).CustomProperty = _elementId; ((IGraphicsContainer)GraphicsLayer).AddElement((IElement)group, 0); return(_elementId); }
//将数组里的坐标构造SegmentCollection private ISegmentCollection MadeSegmentCollection(ref IArray PointArray) { ISegment pSegment; ISegmentCollection pSegmentCollection = new PolylineClass(); IPoint fromPoint; IPoint toPoint; IPoint middlePoint; object a = System.Reflection.Missing.Value; object b = System.Reflection.Missing.Value; for (int i = 0; i < PointArray.Count; i++) { PointStruct pointStruct; pointStruct = (PointStruct)PointArray.get_Element(i); if (pointStruct.Type == 1) { //获取线起点和端点 fromPoint = ((PointStruct)PointArray.get_Element(i)).Point; toPoint = ((PointStruct)PointArray.get_Element(i + 1)).Point; pSegment = new LineClass(); pSegment = MadeLineSeg_2Point(fromPoint, toPoint); pSegmentCollection.AddSegment(pSegment, ref a, ref b); i = i + 1; } else if (pointStruct.Type == 2) { //获取弧起点、中点、端点 fromPoint = ((PointStruct)PointArray.get_Element(i)).Point; middlePoint = ((PointStruct)PointArray.get_Element(i + 1)).Point; toPoint = ((PointStruct)PointArray.get_Element(i + 2)).Point; pSegment = new CircularArcClass(); pSegment = MadeArcSeg_3Point(fromPoint, middlePoint, toPoint); pSegmentCollection.AddSegment(pSegment, ref a, ref b); i = i + 2; } } // end for return(pSegmentCollection); }
public void CanTestCircle() { IFeatureClass fc = CreateLineClass(_testWs, "CanTestCircle"); IFeature row1 = fc.CreateFeature(); IConstructCircularArc arc = new CircularArcClass(); arc.ConstructCircle(GeometryFactory.CreatePoint(0, 0, 0), 3, false); row1.Shape = CreatePolyLine((ISegment)arc); row1.Store(); var test = new QaMinSegAngle(fc, 0.1, true); var runner = new QaContainerTestRunner(1000, test); runner.Execute(); Assert.AreEqual(0, runner.Errors.Count); }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { IPoint pMovePt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pMovePt = GIS.GraphicEdit.SnapSetting.getSnapPoint(pMovePt); if (m_lMouseDownCount == 1) { m_pLineFeedback.MoveTo(pMovePt); } else if (m_lMouseDownCount == 2) { m_bCreated = false; IEnvelope pEnv = new EnvelopeClass(); pEnv.UpperLeft = m_pFirstPoint; pEnv.LowerRight = m_pSecondPoint; IConstructCircularArc pEllipArc = new CircularArcClass(); pEllipArc.ConstructThreePoints(m_pFirstPoint, m_pSecondPoint, pMovePt, true); m_pCircleArc = pEllipArc as ICircularArc; m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null); } DataEditCommon.g_pAxMapControl.Focus(); }
private static bool CutCurveCircle([NotNull] SegmentProxy segmentProxy, [NotNull] IPnt circleCenter, double r2, [NotNull] out IList <double[]> limits) { double radius = Math.Sqrt(r2); IPoint center = new Point(); center.PutCoords(circleCenter.X, circleCenter.Y); ICircularArc arc = new CircularArcClass(); arc.PutCoordsByAngle(center, 0, 2 * Math.PI, radius); object emptyRef = Type.Missing; IPolygon circle = new PolygonClass(); ((ISegmentCollection)circle).AddSegment(((ISegment)arc), ref emptyRef, ref emptyRef); limits = GetLimits(segmentProxy, circle); return(limits.Count > 0); }
private void EndDrawArc3P(IPoint pPoint, int shift) { IGeometry pGeom = null; IPolyline pPolyline; IPolygon pPolygon; pLineArray.Add(pPoint); m_pLineFeed = (INewLineFeedback)m_pFeedback; if (m_pLineFeed != null) { m_pLineFeed.Stop(); } IPoint pFromPoint = (IPoint)pLineArray.get_Element(0); IPoint pTempPoint = ( IPoint)pLineArray.get_Element(2); IPoint pToPoint = (IPoint)pLineArray.get_Element(pLineArray.Count - 1); IPoint pCenterPoint = CommonFunction.GetCenter_P123(pFromPoint, pTempPoint, pToPoint); m_pPoint1 = pFromPoint; m_pPoint2 = pTempPoint; m_pPoint3 = pToPoint; ICircularArc pArc = new CircularArcClass(); pArc.PutCoords(pCenterPoint, pFromPoint, pToPoint, esriArcOrientation.esriArcMajor); if (m_bInUse) { if (shift == 1) //若果按住shift健就弹出对话框,让用户修改圆周上的坐标值 { frmCircle3P formCircle3P = new frmCircle3P(); formCircle3P.ShowDialog(); if (m_bModify) //修改坐标值了 { pFromPoint = m_pPoint1; pToPoint = m_pPoint3; pCenterPoint = CommonFunction.GetCenter_P123(m_pPoint1, m_pPoint2, m_pPoint3); m_bModify = false; } } if (m_Ca < Math.PI) //圆心角小于π { pPolyline = CommonFunction.ArcToPolyline(pFromPoint, pCenterPoint, pToPoint, esriArcOrientation.esriArcMinor); } else //圆心角大于π { pPolyline = CommonFunction.ArcToPolyline(pFromPoint, pCenterPoint, pToPoint, esriArcOrientation.esriArcMajor); } switch (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolyline: pGeom = (IGeometry)pPolyline; break; case esriGeometryType.esriGeometryPolygon: ILine pCenterToFormPointLine = new LineClass(); pCenterToFormPointLine.PutCoords(pCenterPoint, pToPoint); ILine pToPointToCenterLine = new LineClass(); pToPointToCenterLine.PutCoords(pFromPoint, pCenterPoint); ISegmentCollection pSegsPolyline; pSegsPolyline = (ISegmentCollection)pPolyline; object a = System.Reflection.Missing.Value; object b = System.Reflection.Missing.Value; pSegsPolyline.AddSegment((ISegment)pCenterToFormPointLine, ref a, ref b); pSegsPolyline.AddSegment((ISegment)pToPointToCenterLine, ref a, ref b); pPolygon = CommonFunction.PolylineToPolygon((IPolyline)pSegsPolyline); pGeom = (IGeometry)pPolygon; break; } //end switch m_pEnvelope = pGeom.Envelope; m_pEnvelope.Union(m_pCenterPoint.Envelope); if (m_pEnvelope != null && !m_pEnvelope.IsEmpty) { m_pEnvelope.Expand(10, 10, false); } ; CommonFunction.CreateFeature(m_App.Workbench, pGeom, m_FocusMap, m_CurrentLayer); Reset(); pLineArray.RemoveAll(); m_bInUse = false; } //end else if (m_bInUse) }
private IElement DrawCircle(double radius, double x, double y) { IPoint centralPoint = new PointClass(); centralPoint.PutCoords(x, y); // 创建园 ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc construtionCircularArc = circularArc as IConstructCircularArc; construtionCircularArc.ConstructCircle(centralPoint, radius, true); ISegment pSegment1 = circularArc as ISegment; //通过ISegmentCollection构建Ring对象 ISegmentCollection pSegCollection = new RingClass(); object o = Type.Missing; //添加Segement对象即圆 pSegCollection.AddSegment(pSegment1, ref o, ref o); //QI到IRing接口封闭Ring对象,使其有效 IRing pRing = pSegCollection as IRing; pRing.Close(); //通过Ring对象使用IGeometryCollection构建Polygon对象 IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); //构建一个CircleElement对象 IElement pElement = new CircleElementClass(); pElement.Geometry = pGeometryColl as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass(); //pFillSymbol.Color = pCircleColor; ILineSymbol pLineSymbol = new SimpleLineSymbolClass(); // pLineSymbol.Color = DefineColor(0, 255, 0); pFillSymbol.Outline = pLineSymbol; pFillShapeElement.Symbol = pFillSymbol; IFillShapeElement circleElement = pElement as IFillShapeElement; circleElement.Symbol = pFillSymbol; IGraphicsContainer pGC = this.axMapControl.ActiveView.GraphicsContainer; pGC.AddElement(pElement, 0); axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); return pElement; }
private ISegmentCollection createSegments(Cell cell, BoostVoronoi bv, ArcConstructionMethods method, ISpatialReference spatialReference) { List <Cell> cells = bv.Cells; List <Edge> edges = bv.Edges; List <Vertex> vertices = bv.Vertices; IPoint previousEndPoint = null; ISegmentCollection segmentCollection = new PolygonClass() { SpatialReference = spatialReference }; // As per boost documentation, edges are returned in counter clockwise (CCW) rotation. // voronoi_edge_type* next() Returns the pointer to the CCW next edge within the corresponding Voronoi cell. Edges not necessarily share a common vertex (e.g. infinite edges). for (int i = cell.EdgesIndex.Count - 1; i >= 0; i--) { Edge edge = edges[cell.EdgesIndex[i]]; //If the vertex index equals -1, it means the edge is infinite. It is impossible to print the coordinates. if (!edge.IsFinite && edge.End < 0) { // this is the ending portion of a pair of infinite edges, file the previous edge with Start >= 0 Edge previous = null; for (int k = i + 1; k < cell.EdgesIndex.Count; k++) { previous = edges[cell.EdgesIndex[k]]; if (previous.End >= 0) { break; } previous = null; } if (previous == null) { for (int k = 0; k < i; k++) { previous = edges[cell.EdgesIndex[k]]; if (previous.End >= 0) { break; } previous = null; } } if (previous == null) { throw new Exception("No outbound infinite edge could be found"); } //Add a straight line segment Vertex start = vertices[previous.End]; IPoint FromPoint = new PointClass() { X = start.X, Y = start.Y, SpatialReference = spatialReference }; Vertex end = vertices[edge.Start]; IPoint ToPoint = new PointClass() { X = end.X, Y = end.Y, SpatialReference = spatialReference }; segmentCollection.AddSegment(new LineClass() { FromPoint = FromPoint, ToPoint = ToPoint, SpatialReference = spatialReference }); previousEndPoint = ToPoint; } else if (edge.IsFinite) { Vertex start = vertices[edge.End]; IPoint FromPoint = new PointClass() { X = start.X, Y = start.Y, SpatialReference = spatialReference }; if (previousEndPoint != null) { if ((Math.Abs(previousEndPoint.X - FromPoint.X) > 0.05 || Math.Abs(previousEndPoint.X - FromPoint.X) > 0.05)) { throw new Exception("Significant change between last end point and current start point"); } else { FromPoint = previousEndPoint; } } Vertex end = vertices[edge.Start]; IPoint ToPoint = new PointClass() { X = end.X, Y = end.Y, SpatialReference = spatialReference }; if (method == ArcConstructionMethods.Straight || edge.IsLinear) { segmentCollection.AddSegment(new LineClass() { FromPoint = FromPoint, ToPoint = ToPoint, SpatialReference = spatialReference }); previousEndPoint = ToPoint; } else { // We need three points, use start, end, mid-point between focus and directrix Cell twinCell = cells[edges[edge.Twin].Cell]; VPoint pointSite; VSegment lineSite; if (cell.ContainsPoint && twinCell.ContainsSegment) { pointSite = bv.RetrieveInputPoint(cell); lineSite = bv.RetrieveInputSegment(twinCell); } else if (cell.ContainsSegment && twinCell.ContainsPoint) { pointSite = bv.RetrieveInputPoint(twinCell); lineSite = bv.RetrieveInputSegment(cell); } else { throw new Exception("Invalid edge, curves should only be present between a point and a line"); } double scaleFactor = Convert.ToDouble(bv.ScaleFactor); IPoint aoPointSite = new Point() { X = Convert.ToDouble(pointSite.X) / scaleFactor, Y = Convert.ToDouble(pointSite.Y) / scaleFactor, SpatialReference = spatialReference }; ISegment aoLineSite = new LineClass() { FromPoint = new PointClass() { X = Convert.ToDouble(lineSite.Start.X) / scaleFactor, Y = Convert.ToDouble(lineSite.Start.Y) / scaleFactor, SpatialReference = spatialReference }, ToPoint = new PointClass() { X = Convert.ToDouble(lineSite.End.X) / scaleFactor, Y = Convert.ToDouble(lineSite.End.Y) / scaleFactor, SpatialReference = spatialReference }, SpatialReference = spatialReference }; if (method == ArcConstructionMethods.Approximate) { List <Vertex> sampledVerticed = null; try { sampledVerticed = bv.SampleCurvedEdge(edge, aoLineSite.Length / 10); } catch (FocusOnDirectixException e) { //Log any exception here is required sampledVerticed = new List <Vertex>() { start, end }; } catch (UnsolvableVertexException e) { sampledVerticed = new List <Vertex>() { start, end }; } sampledVerticed.Reverse(); List <IPoint> discretizedEdge = sampledVerticed.Select( p => new Point() { X = p.X, Y = p.Y } ).ToList <IPoint>(); IPoint prev = discretizedEdge[0]; foreach (IPoint v in discretizedEdge.Skip(1)) { segmentCollection.AddSegment(new LineClass() { FromPoint = new Point() { X = prev.X, Y = prev.Y, SpatialReference = spatialReference }, ToPoint = new Point() { X = v.X, Y = v.Y, SpatialReference = spatialReference }, SpatialReference = spatialReference }); prev = v; } previousEndPoint = discretizedEdge.Last(); } else if (method == ArcConstructionMethods.Circular) { IPoint nearPoint = ((IProximityOperator)aoLineSite).ReturnNearestPoint(aoPointSite, esriSegmentExtension.esriNoExtension); IPoint midpoint = new PointClass() { X = (nearPoint.X + aoPointSite.X) / 2, Y = (nearPoint.Y + aoPointSite.Y) / 2, SpatialReference = spatialReference }; IConstructCircularArc constArc = new CircularArcClass() { SpatialReference = spatialReference }; constArc.ConstructThreePoints(FromPoint, midpoint, ToPoint, false); ICircularArc arc = (ICircularArc)constArc; if (!arc.IsMinor) { constArc = new CircularArcClass() { SpatialReference = spatialReference }; constArc.ConstructEndPointsRadius(FromPoint, ToPoint, !arc.IsCounterClockwise, arc.Radius, true); arc = (ICircularArc)constArc; } segmentCollection.AddSegment((ISegment)arc); previousEndPoint = arc.ToPoint; } else if (method == ArcConstructionMethods.Ellipse) { IPoint nearPoint = ((IProximityOperator)aoLineSite).ReturnNearestPoint(aoPointSite, esriSegmentExtension.esriExtendTangents); nearPoint.SpatialReference = spatialReference; ILine lineToFocus = new LineClass() { FromPoint = nearPoint, ToPoint = aoPointSite, SpatialReference = spatialReference }; ILine semiMajor = new LineClass() { SpatialReference = spatialReference }; lineToFocus.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 1, true, 100 * lineToFocus.Length, semiMajor); IPoint center = new PointClass() { X = (semiMajor.FromPoint.X + semiMajor.ToPoint.X) / 2, Y = (semiMajor.FromPoint.Y + semiMajor.ToPoint.Y) / 2, SpatialReference = spatialReference }; double minor_length = Math.Sqrt( Math.Pow(distance(semiMajor.FromPoint, ToPoint) + distance(semiMajor.ToPoint, ToPoint), 2) - Math.Pow(semiMajor.Length, 2)); IEllipticArc arc = new EllipticArcClass() { SpatialReference = spatialReference }; double rotation = lineToFocus.Angle; double from = GetAngle(center, FromPoint); arc.PutCoords(false, center, FromPoint, ToPoint, rotation, minor_length / semiMajor.Length, esriArcOrientation.esriArcMinor); segmentCollection.AddSegment((ISegment)arc); previousEndPoint = arc.ToPoint; } } } } return(segmentCollection); }
public void updateMemory() { try { //get values int n = this.mPath.getLastIndex(); IPoint start = this.mPath[n - 1]; IPoint end = this.mPath[n]; double angleMoved = 0; double angleLeft = 0; double angleRight = 0; IPoint startLeft = new PointClass(); IPoint startRight = new PointClass(); IPoint endLeft = new PointClass(); IPoint endRight = new PointClass(); IGeometry g; ITopologicalOperator to; CircularArcClass startCurve = new CircularArcClass(); CircularArcClass endCurve = new CircularArcClass(); LineClass line1 = new LineClass(); LineClass line2 = new LineClass(); LineClass line3 = new LineClass(); LineClass line4 = new LineClass(); PolygonClass memoryPolygon = new PolygonClass(); object Missing = Type.Missing; //get angle from start to end angleMoved = System.Math.Atan((start.Y - end.Y) / (start.X - end.X)); //rotate pi/2 angleLeft = angleMoved + Math.PI / 2; angleRight = angleMoved - Math.PI / 2; //step perceptionDistance forward and back startLeft.X = start.X + this.mPerceptionDist * System.Math.Cos(angleLeft); startLeft.Y = start.Y + mPerceptionDist * System.Math.Sin(angleLeft); startRight.X = start.X + mPerceptionDist * System.Math.Cos(angleRight); startRight.Y = start.Y + mPerceptionDist * System.Math.Sin(angleRight); //repeat for end endLeft.X = end.X + mPerceptionDist * System.Math.Cos(angleLeft); endLeft.Y = end.Y + mPerceptionDist * System.Math.Sin(angleLeft); endRight.X = end.X + mPerceptionDist * System.Math.Cos(angleRight); endRight.Y = end.Y + mPerceptionDist * System.Math.Sin(angleRight); line1.FromPoint = startLeft; line1.ToPoint = endLeft; line2.FromPoint = endLeft; line2.ToPoint = endRight; line3.FromPoint = endRight; line3.ToPoint = startRight; line4.FromPoint = startRight; line4.ToPoint = startLeft; mLog.Debug("my current location is " + this.getLocation_XY()); mLog.Debug("StartRight is x,y " + startRight.X.ToString() + " " + startRight.Y.ToString()); mLog.Debug("startLeft is x,y " + startLeft.X.ToString() + " " + startLeft.Y.ToString()); mLog.Debug("endRight is x,y " + endRight.X.ToString() + " " + endRight.Y.ToString()); mLog.Debug("endLeft is x,y " + endLeft.X.ToString() + " " + endLeft.Y.ToString()); memoryPolygon.SpatialReference = this.Location.SpatialReference; memoryPolygon.AddSegment((ISegment)line1, ref Missing, ref Missing); memoryPolygon.AddSegment((ISegment)line2, ref Missing, ref Missing); memoryPolygon.AddSegment((ISegment)line3, ref Missing, ref Missing); memoryPolygon.AddSegment((ISegment)line4, ref Missing, ref Missing); if (memoryPolygon.Area < 0.0) { memoryPolygon.ReverseOrientation(); } to = (ITopologicalOperator)end; g = to.Buffer(mPerceptionDist); mLog.Debug("adding the step for time step " + this.timeStep.ToString()); // this.MapManager.AddMemoryPoly(this.IdNum,memoryPolygon); this.MapManager.AddTimeSteps(this.IdNum, memoryPolygon, (IPolygon)g, timeStep, sex); if (goingHome) { this.setSocialIndex(end); } } catch (System.Exception ex) { mLog.Debug("error look for error file"); // System.Windows.Forms.MessageBox.Show(ex.StackTrace); eLog.Debug(ex); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ToolCreateCircle.OnMouseDown implementation if ((m_pMapCtl = ClsGlobal.GetMapControl(m_hookHelper)) == null) { return; } IPoint pPoint = m_pMapCtl.ToMapPoint(X, Y); if (Button == 1) { if (m_NewCircleFeedback == null) { m_NewCircleFeedback = new NewCircleFeedbackClass(); m_NewCircleFeedback.Display = m_pMapCtl.ActiveView.ScreenDisplay; m_NewCircleFeedback.Start(pPoint); m_CenterPoint = pPoint; } else { try { object Miss = Type.Missing; ICircularArc pArc = m_NewCircleFeedback.Stop(); //IGeometry geometry = new PolygonClass(); //geometry = m_pMapCtl.TrackCircle(); IPolygon pPolygon = new PolygonClass(); ISegment pArcC = pArc as ISegment; ISegmentCollection pArcP = pPolygon as ISegmentCollection; pArcP.AddSegment(pArcC, ref Miss, ref Miss); pPolygon.Close(); IFeature pFeature = m_FLayer.FeatureClass.CreateFeature(); pFeature.Shape = pPolygon; pFeature.Store(); m_pMapCtl.Refresh(); m_NewCircleFeedback = null; } catch (System.Exception ex) { } } } if (Button == 2) { double radius = Math.Sqrt((pPoint.X - m_CenterPoint.X) * (pPoint.X - m_CenterPoint.X) + (pPoint.Y - m_CenterPoint.Y) * (pPoint.Y - m_CenterPoint.Y)); FrmDrawCircle frm = new FrmDrawCircle(radius); IConstructCircularArc pArcConstruct = null; if (m_NewCircleFeedback == null) { return; } if (frm.ShowDialog() == DialogResult.OK) { try { pArcConstruct = new CircularArcClass(); pArcConstruct.ConstructCircle(m_CenterPoint, frm.m_radius, false); if (pArcConstruct != null) { IPolygon pPolygon = new PolygonClass(); ISegment pArcC = pArcConstruct as ISegment; ISegmentCollection pArcP = pPolygon as ISegmentCollection; pArcP.AddSegment(pArcC); pPolygon.Close(); IFeature pFeature = m_FLayer.FeatureClass.CreateFeature(); pFeature.Shape = pPolygon; pFeature.Store(); m_pMapCtl.Refresh(); m_NewCircleFeedback.Stop(); m_NewCircleFeedback = null; } } catch (System.Exception ex) { MessageBox.Show(ex.Message); if (m_NewCircleFeedback != null) { m_NewCircleFeedback.Stop(); } m_NewCircleFeedback = null; } } } }
/// <summary> /// 构造圆形对象 /// </summary> /// <params name="point"></params> /// <params name="radius"></params> /// <params name="isCCW"></params> /// <returns></returns> public ICircularArc CreateCircleArc(IPoint point, double radius, bool isCCW) { ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc construtionCircularArc = circularArc as IConstructCircularArc; construtionCircularArc.ConstructCircle(point, radius, isCCW); return circularArc; }
protected override void OnClick() { FileType ft = FileType.COGOToolbarTraverse; //start out assuming it is a cogo traverse file m_count = 1; ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); ICadastralFabric pCadFabric = pCadEd.CadastralFabric; ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)pCadEd; IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd; IParcelConstruction pTrav = pParcEditorMan.ParcelConstruction; if (!(pParcEditorMan.InTraverseEditMode) && !(pParcEditorMan.InConstructionEditMode)) {//if this is not a construction or a new parcel, then get out. MessageBox.Show("Please create a new parcel or new construction first, and then try again."); return; } //Make sure the lines grid is selected Utilities UTILS = new Utilities(); UTILS.SelectCadastralPropertyPage((ICadastralExtensionManager)pCadExtMan, "lines"); IParcelConstruction3 pTrav3 = (IParcelConstruction3)pTrav; IGSParcel pParcel = null; try { pParcel = pTrav.Parcel; } catch (COMException error) { MessageBox.Show(error.Message.ToString()); return; } //go get a traverse file // Display .Net dialog for File selection. OpenFileDialog openFileDialog = new OpenFileDialog(); // Set File Filter openFileDialog.Filter = "Traverse file (*.txt)|*.txt|Comma-delimited(*.csv)|*.csv|All Files|*.*"; // Disable multi-select openFileDialog.Multiselect = false; // Don't need to Show Help openFileDialog.ShowHelp = false; // Set Dialog Title openFileDialog.Title = "Load file"; openFileDialog.FilterIndex = 2; // Display Open File Dialog if (openFileDialog.ShowDialog() != DialogResult.OK) { openFileDialog = null; return; } TextReader tr = null; try { tr = new StreamReader(openFileDialog.FileName); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } string sCourse = ""; int iCount = 0; string[] sFileLine = new string[0]; //define as dynamic array //initialize direction units and format esriDirectionType enumDirectionType = esriDirectionType.esriDTQuadrantBearing; esriDirectionUnits enumDirectionUnits = esriDirectionUnits.esriDUDegreesMinutesSeconds; //initialize start and end points IPoint StartPoint = new PointClass(); IPoint EndPoint = new PointClass(); bool IsLoopTraverse = false; //fill the array with the lines from the file while (sCourse != null) { sCourse = tr.ReadLine(); try { if (sCourse.Trim().Length >= 1) //test for empty lines { RedimPreserveString(ref sFileLine, 1); sFileLine[iCount] = sCourse; } iCount++; sCourse = sCourse.ToLower(); if (sCourse.Contains("dt")) { if (sCourse.Contains("qb")) enumDirectionType = esriDirectionType.esriDTQuadrantBearing; else if (sCourse.Contains("na")) enumDirectionType = esriDirectionType.esriDTNorthAzimuth; else if (sCourse.Contains("sa")) enumDirectionType = esriDirectionType.esriDTSouthAzimuth; else if (sCourse.Contains("p")) enumDirectionType = esriDirectionType.esriDTPolar; } if (sCourse.Contains("du")) { if (sCourse.Contains("dms")) enumDirectionUnits = esriDirectionUnits.esriDUDegreesMinutesSeconds; else if (sCourse.Contains("dd")) enumDirectionUnits = esriDirectionUnits.esriDUDecimalDegrees; else if (sCourse.Contains("g")) enumDirectionUnits = esriDirectionUnits.esriDUGons; else if (sCourse.Contains("r")) enumDirectionUnits = esriDirectionUnits.esriDURadians; } if (sCourse.Contains("sp")) {//start point string[] XY = sCourse.Split(' '); double x = Convert.ToDouble(XY[1]); double y = Convert.ToDouble(XY[2]); StartPoint.PutCoords(x, y); } if (sCourse.Contains("ep")) {//end point string[] XY = sCourse.Split(' '); double x = Convert.ToDouble(XY[1]); double y = Convert.ToDouble(XY[2]); EndPoint.PutCoords(x, y); } if (sCourse.Contains("tometricfactor")) {//this handles the comma-separated file case string[] sScaleFactor = sCourse.Split(','); m_dScaleFactor = Convert.ToDouble(sScaleFactor[1]); } } catch { } } tr.Close(); //close the file and release resources string sFileExt = System.IO.Path.GetExtension(openFileDialog.FileName.TrimEnd()); if ((sFileExt.ToLower() == ".csv") && (sFileLine[0].Contains(","))) {//if it's a comma-delimited file ft = FileType.CommaDelimited; } //Test for loop traverse if (!(EndPoint.IsEmpty)) { if (EndPoint.Compare(StartPoint) == 0) IsLoopTraverse = true; else IsLoopTraverse = false; } //get highest point id number in grid, and get the to point id on the last line. IGSLine pParcelLine = null; int iFirstToNode = -1; int iLastToNode = -1; int iHighestPointID = -1; for (int i = 0; i < pTrav.LineCount; i++) { if (pTrav.GetLine(i, ref pParcelLine)) { if (iFirstToNode < 0) iFirstToNode = pParcelLine.ToPoint; iLastToNode = pParcelLine.ToPoint; iHighestPointID = iHighestPointID < pParcelLine.ToPoint ? pParcelLine.ToPoint : iHighestPointID; iHighestPointID = iHighestPointID < pParcelLine.FromPoint ? pParcelLine.FromPoint : iHighestPointID; } } ICadastralUndoRedo pCadUndoRedo = pTrav as ICadastralUndoRedo; pCadUndoRedo.StartUndoRedoSession("Load Lines From File"); try { IGSLine pLine = null; int iLinecount = iCount - 1; ISegment pExitTangent = null; for (iCount = 0; iCount <= iLinecount; iCount++) { if (ft == FileType.COGOToolbarTraverse) { { pLine = null; ICircularArc pCircArc;//need to use this in the test to handle curves greater than 180 pLine = CreateGSLine(sFileLine[iCount], enumDirectionUnits, enumDirectionType, pExitTangent, out pExitTangent, out pCircArc); //exit tangent from the previous course is the new entry tangent for the next course if (pLine != null) { if (pCircArc == null) {// straight line //if this is the last course then set the to point to 1 if ((iCount == iLinecount) && IsLoopTraverse) pLine.ToPoint = 1; pTrav.InsertGridRow(-1, pLine); } else {//some post-processing needed to figure out if a 180 curve needs to be split if (Math.Abs(pCircArc.CentralAngle) < (Math.PI - 0.000001))//some tolerance for being close to 180 { //this curve is OK //if this is the last course then set the to point to 1 if ((iCount == iLinecount) && IsLoopTraverse) pLine.ToPoint = 1; pTrav.InsertGridRow(-1, pLine); } else {//curve is greater than or equal to 180, special treatment for GSE needed to split curve into 2 parts //first decrement the count m_count -= 1; ISegment pFullSegment = (ISegment)pCircArc; ISegment pFirstHalf; ISegment pSecondHalf; pFullSegment.SplitAtDistance(0.5, true, out pFirstHalf, out pSecondHalf); IConstructCircularArc2 pCircArcConstr1 = new CircularArcClass(); ICircularArc pCircArc1 = (ICircularArc)pCircArcConstr1; pCircArcConstr1.ConstructEndPointsRadius(pFirstHalf.FromPoint, pFirstHalf.ToPoint, pCircArc.IsCounterClockwise, pCircArc.Radius, true); ILine2 pTangentLine = new LineClass(); pCircArc1.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 0, false, 100, pTangentLine); string sTangentBearing = PolarRadians_2_DirectionString(pTangentLine.Angle, enumDirectionType, enumDirectionUnits); sTangentBearing = sTangentBearing.Replace(" ", ""); string sHalfDelta = Radians_2_Angle(Math.Abs(pCircArc1.CentralAngle), enumDirectionUnits); string sSide = pCircArc.IsCounterClockwise ? " L " : " R "; ISegment EntryTangent = (ISegment)pTangentLine; //construct the string for the first piece // looks similar to this: NC R 500 D 181-59-59 T N59-59-59W L string sFirstCurve = "NC R " + Convert.ToString(pCircArc.Radius) + " D " + sHalfDelta + " T " + sTangentBearing + sSide; IGSLine pLineFirstCurve = CreateGSLine(sFirstCurve, enumDirectionUnits, enumDirectionType, pExitTangent, out pExitTangent, out pCircArc); pTrav.InsertGridRow(-1, pLineFirstCurve); ICircularArc pCircArc2 = (ICircularArc)pCircArcConstr1; pCircArcConstr1.ConstructEndPointsRadius(pSecondHalf.FromPoint, pSecondHalf.ToPoint, pCircArc.IsCounterClockwise, pCircArc.Radius, true); pCircArc2.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 0, false, 100, pTangentLine); sTangentBearing = PolarRadians_2_DirectionString(pTangentLine.Angle, enumDirectionType, enumDirectionUnits); sTangentBearing = sTangentBearing.Replace(" ", ""); //construct the string for the second piece // looks similar to this: NC R 500 D 181-59-59 T N59-59-59W L string sSecondCurve = "NC R " + Convert.ToString(pCircArc.Radius) + " D " + sHalfDelta + " T " + sTangentBearing + sSide; IGSLine pLineSecondCurve = CreateGSLine(sSecondCurve, enumDirectionUnits, enumDirectionType, pExitTangent, out pExitTangent, out pCircArc); //if this is the last course then set the to point to 1 if ((iCount == iLinecount) && IsLoopTraverse) pLine.ToPoint = 1; pTrav.InsertGridRow(-1, pLineSecondCurve); } } } } } else//this is comma-separated version of the grid, so do the following { pLine = null; //apply a point id number offset if there are existing lines in the grid. if (iHighestPointID > -1 && iCount >= 3) { string[] sTraverseCourse = sFileLine[iCount].Split(','); if (iCount == 3) { sTraverseCourse[0] = iLastToNode.ToString(); sTraverseCourse[5] = (Convert.ToInt32(sTraverseCourse[5]) + iHighestPointID).ToString(); } else if (iCount > 3) { sTraverseCourse[0] = (Convert.ToInt32(sTraverseCourse[0]) + iHighestPointID).ToString(); sTraverseCourse[5] = (Convert.ToInt32(sTraverseCourse[5]) + iHighestPointID).ToString(); } sFileLine[iCount] = sTraverseCourse[0]; int iAttCount = sTraverseCourse.GetLength(0); for (int j = 1; j < iAttCount; j++) sFileLine[iCount] += "," + sTraverseCourse[j]; } pLine = CreateGSLineFromCommaSeparatedString(sFileLine[iCount], enumDirectionUnits, enumDirectionType); if (pLine != null) pTrav.InsertGridRow(-1, pLine); } } pTrav3.UpdateGridFromGSLines(false); IParcelConstruction2 pConstr2 = (IParcelConstruction2)pTrav3; //hidden interface pConstr2.RecalculatePoints(); //explicit recalculate needed on a construction pParcel.Modified(); pParcEditorMan.Refresh(); pCadUndoRedo.WriteUndoRedoSession(true); sFileLine = null; openFileDialog = null; } catch(Exception ex) { MessageBox.Show(ex.Message,"Load Lines From File"); pCadUndoRedo.WriteUndoRedoSession(false); } }
public static void CreateJumps(IApplication app, JumpTypes jumpType, double jumpDistance) { IProgressDialog2 progressDialog = default(IProgressDialog2); IProgressDialogFactory progressDialogFactory = null; ITrackCancel trackCancel = null; IStepProgressor stepProgressor = null; ICursor lineCursor = null; IEditor editor = null; IFeature lineFeature = null; IMxDocument mxdoc = null; IMap map = null; UID geoFeatureLayerID = null; IEnumLayer enumLayer = null; IEditLayers eLayers = null; List<IFeatureLayer> lineLayers = null; ILayer layer = null; IFeatureLayer fLayer = null; IFeatureSelection fSel = null; try { //Get editor editor = Globals.getEditor(app); if (editor.EditState != esriEditState.esriStateEditing) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg"), A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_6")); return; } //ProgressBar progressDialogFactory = new ProgressDialogFactoryClass(); // Create a CancelTracker trackCancel = new CancelTrackerClass(); // Set the properties of the Step Progressor Int32 int32_hWnd = editor.Parent.hWnd; stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = 0; // stepProgressor.MaxRange = itotal stepProgressor.StepValue = 1; stepProgressor.Message = ""; stepProgressor.Hide(); // Create the ProgressDialog. This automatically displays the dialog progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog.CancelEnabled = false; progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_12") +"..."; progressDialog.Title = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_12"); progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; mxdoc = (IMxDocument)app.Document; map = editor.Map; //Get enumeration of feature layers geoFeatureLayerID = new UIDClass(); geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true); //Get enumeration of editable layers eLayers = (IEditLayers)editor; // Create list of visible line layers with selected feature(s) lineLayers = new List<IFeatureLayer>(); enumLayer.Reset(); layer = enumLayer.Next(); while (layer != null) { fLayer = (IFeatureLayer)layer; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_2") + fLayer.Name; if (fLayer.Valid && (fLayer.FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline) && (fLayer.Visible)) { if (eLayers.IsEditable(fLayer)) { fSel = fLayer as IFeatureSelection; if (fSel.SelectionSet.Count > 0) { stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_3") + fLayer.Name; lineLayers.Add(fLayer); } } } layer = enumLayer.Next(); } if (lineLayers.Count == 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_7")); return; } // Create an edit operation enabling undo/redo editor.StartOperation(); IPointCollection linePointCollection = null; ISpatialFilter spatialFilter = null; IFeatureCursor featureCursor = null; IFeature crossFeature = null; ITopologicalOperator topologicalOP = null; ITopologicalOperator topologicalOP2 = null; IPointCollection intersectPointCollection = null; IPoint intersectPoint = null; IPoint outPoint = null; IPoint beginPoint = null; IPoint endPoint = null; IActiveView activeView = null; IInvalidArea invalid = null; IEnvelope ext = null; ISegmentCollection testSegmentColl = null; ISegment testSegment = null; ISegmentCollection segmentColl = null; ISegmentCollection segmentCollNew = null; IConstructCircularArc constructCircArc = null; ISegment curveSegment = null; //IProximityOperator proximityOP = null; IPolycurve3 selCurve = null; IPolycurve3 selCurveB = null; IPolycurve3 crossCurve = null; IPolycurve3 crossCurveB = null; IPolycurve3 testSelCurve = null; IPolycurve3 testSelCurveB = null; object _missing = null; IFeatureSelection lineSel = null; ISelectionSet2 sel = null; IZAware pZAware = null; ISegmentCollection testSegmentColl2 = null; ISegment testSegment2 = null; IGeometryDef pGeometryDefTest = null; IFields pFieldsTest = null; IField pFieldTest = null; IGeoDataset pDS = null; try { activeView = map as IActiveView; invalid = new InvalidAreaClass(); invalid.Display = editor.Display; linePointCollection = (IPointCollection)new PolylineClass(); spatialFilter = new SpatialFilterClass(); intersectPoint = new PointClass(); outPoint = new PointClass(); //used for curve test on cross feature bool testProjectOnto; bool testCreatePart; bool testSplitHappened; int testNewPartIndex; int testNewSegmentIndex; //used for curve test on selected feature bool testProjectOnto2; bool testCreatePart2; bool testSplitHappened2; int testNewPartIndex2; int testNewSegmentIndex2; //ICurve lineCurve; double totalDistance; double distAlongCurve = 0; double distFromCurve = 0; bool boolRightSide = false; //test the amount of needed space for the inserted curve double remainderDistance = 0; double pointDistance = 0; bool projectOnto; bool createPart; bool splitHappenedBefore; bool splitHappenedAfter; int newPartIndexBegin; int newSegmentIndexBegin; int newPartIndexEnd; int newSegmentIndexEnd; _missing = Type.Missing; // Step through all line layers with selection sets foreach (IFeatureLayer lineLayer in lineLayers) { stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_4a") + lineLayer.Name; // Get cursor of selected lines lineSel = (IFeatureSelection)lineLayer; sel = lineSel.SelectionSet as ISelectionSet2; sel.Search(null, false, out lineCursor); // Process each selected line int idx = 0; while ((lineFeature = (IFeature)lineCursor.NextRow()) != null) { idx++; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_4b") + idx + A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_4c") + lineLayer.Name; if (lineFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { selCurve = (IPolycurve3)lineFeature.ShapeCopy; pZAware = selCurve as IZAware; if (pZAware.ZAware) { pZAware.ZAware = false; } // Get cursor of crossing features spatialFilter.Geometry = selCurve; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; featureCursor = lineLayer.Search(spatialFilter, false); // Process each crossing feature while ((crossFeature = (IFeature)featureCursor.NextFeature()) != null) { topologicalOP = (ITopologicalOperator)crossFeature.Shape; //topologicalOP2 = (ITopologicalOperator)polylinePointCollection; topologicalOP2 = (ITopologicalOperator)selCurve; topologicalOP2.Simplify(); topologicalOP.Simplify(); intersectPointCollection = (IPointCollection)topologicalOP.Intersect((IGeometry)selCurve, esriGeometryDimension.esriGeometry0Dimension); for (int i = 0; i < intersectPointCollection.PointCount; i++) { intersectPoint = intersectPointCollection.get_Point(i); //Determine if the crossing segement is an arc. //Continue if it is not. testProjectOnto = true; testCreatePart = false; crossCurve = (IPolycurve3)crossFeature.ShapeCopy; crossCurve.SplitAtPoint(intersectPoint, testProjectOnto, testCreatePart, out testSplitHappened, out testNewPartIndex, out testNewSegmentIndex); crossCurveB = (IPolycurve3)crossFeature.ShapeCopy; testSegmentColl = crossCurveB as ISegmentCollection; testSegment = testSegmentColl.get_Segment(testNewSegmentIndex - 1); if (testSegment.GeometryType != esriGeometryType.esriGeometryCircularArc) { //Determine if the current location of the selected line is an arc. //Continue if it is not. testProjectOnto2 = true; testCreatePart2 = false; testSelCurve = (IPolycurve3)lineFeature.ShapeCopy; testSelCurve.SplitAtPoint(intersectPoint, testProjectOnto2, testCreatePart2, out testSplitHappened2, out testNewPartIndex2, out testNewSegmentIndex2); testSelCurveB = (IPolycurve3)lineFeature.ShapeCopy; testSegmentColl2 = testSelCurveB as ISegmentCollection; testSegment2 = testSegmentColl2.get_Segment(testNewSegmentIndex2 - 1); if (testSegment2.GeometryType != esriGeometryType.esriGeometryCircularArc) { //Find distance along the original selected line //focusPolyline = (IPolyline)lineFeature.ShapeCopy; selCurveB = (IPolycurve3)lineFeature.ShapeCopy; selCurveB.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, intersectPoint, false, outPoint, ref distAlongCurve, ref distFromCurve, ref boolRightSide); remainderDistance = selCurveB.Length - distAlongCurve; totalDistance = distAlongCurve + jumpDistance; //Continue if there is enough room if ((selCurveB.Length >= (jumpDistance / 2)) && (remainderDistance >= (jumpDistance / 2))) { //find the points where the curve will begin and end beginPoint = new PointClass(); endPoint = new PointClass(); selCurveB.QueryPoint(esriSegmentExtension.esriNoExtension, (distAlongCurve - (jumpDistance / 2)), false, beginPoint); selCurveB.QueryPoint(esriSegmentExtension.esriNoExtension, (distAlongCurve + (jumpDistance / 2)), false, endPoint); //split the original line at the two points (vertices for begin and end of new curve) projectOnto = true; createPart = false; selCurveB.SplitAtPoint(beginPoint, projectOnto, createPart, out splitHappenedBefore, out newPartIndexBegin, out newSegmentIndexBegin); selCurveB.SplitAtPoint(endPoint, projectOnto, createPart, out splitHappenedAfter, out newPartIndexEnd, out newSegmentIndexEnd); if ((splitHappenedBefore = true) && (splitHappenedAfter = true)) { //Create the curve segment and add it to the polyline constructCircArc = new CircularArcClass(); // proximityOP = (IProximityOperator)intersectPoint; //pointDistance = proximityOP.ReturnDistance(beginPoint); pointDistance = jumpDistance; //check for direction of line to always make the jump on top if (jumpType == JumpTypes.Over) if (endPoint.X > beginPoint.X) { try { constructCircArc.ConstructChordDistance(intersectPoint, beginPoint, false, (pointDistance)); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_8")); continue; } } else { try { constructCircArc.ConstructChordDistance(intersectPoint, beginPoint, true, (pointDistance)); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_8")); continue; } } else { if (endPoint.X <= beginPoint.X) { try { constructCircArc.ConstructChordDistance(intersectPoint, beginPoint, false, (pointDistance)); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_8")); continue; } } else { try { constructCircArc.ConstructChordDistance(intersectPoint, beginPoint, true, (pointDistance)); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_8")); continue; } } } curveSegment = constructCircArc as ISegment; if (curveSegment != null & curveSegment.Length > 0) { segmentCollNew = (ISegmentCollection)new PolylineClass(); segmentCollNew.AddSegment(curveSegment, ref _missing, ref _missing); segmentColl = (ISegmentCollection)selCurveB; segmentColl.ReplaceSegmentCollection(newSegmentIndexBegin, 1, segmentCollNew); string sShpName = lineLayer.FeatureClass.ShapeFieldName; pFieldsTest = lineLayer.FeatureClass.Fields; int lGeomIndex = pFieldsTest.FindField(sShpName); pFieldTest = pFieldsTest.get_Field(lGeomIndex); pGeometryDefTest = pFieldTest.GeometryDef; bool bZAware; bool bMAware; //Determine if M or Z aware bZAware = pGeometryDefTest.HasZ; bMAware = pGeometryDefTest.HasM; if (bZAware) { // IGeometry pGeo = new PolylineClass(); pZAware = selCurveB as IZAware; if (pZAware.ZAware) { } else { pZAware.ZAware = true; //pZAware.DropZs(); } // pZAware.DropZs(); IZ pZ = selCurveB as IZ; pZ.SetConstantZ(0); } if (bMAware) { } pDS = lineLayer.FeatureClass as IGeoDataset; selCurveB.SpatialReference = pDS.SpatialReference; lineFeature.Shape = (IGeometry)selCurveB; lineFeature.Store(); //Prepare to redraw area around feature ext = curveSegment.Envelope; ext.Expand(2, 2, true); invalid.Add(ext); } } } else { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_9")); } } } } } } } } } catch (Exception ex) { editor.AbortOperation(); MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_6") + "\n" + ex.Message, ex.Source); } finally { // Refresh if (invalid!= null) invalid.Invalidate((short)esriScreenCache.esriAllScreenCaches); linePointCollection = null; spatialFilter = null; if (featureCursor != null) Marshal.ReleaseComObject(featureCursor); featureCursor = null; crossFeature = null; topologicalOP = null; topologicalOP2 = null; intersectPointCollection = null; intersectPoint = null; outPoint = null; beginPoint = null; endPoint = null; activeView = null; invalid = null; ext = null; testSegmentColl = null; testSegment = null; segmentColl = null; segmentCollNew = null; constructCircArc = null; curveSegment = null; //proximityOP = null; selCurve = null; selCurveB = null; crossCurve = null; crossCurveB = null; testSelCurve = null; testSelCurveB = null; _missing = null; lineSel = null; sel = null; pZAware = null; testSegmentColl2 = null; testSegment2 = null; pGeometryDefTest = null; pFieldsTest = null; pFieldTest = null; pDS = null; } // Stop the edit operation editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_6")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_6") + "\n" + ex.Message, ex.Source); return; } finally { if (lineCursor != null) { Marshal.ReleaseComObject(lineCursor); } // Cleanup if (progressDialog != null) { progressDialog.HideDialog(); //progressDialog = null; Marshal.ReleaseComObject(progressDialog); //progressDialogFactory = null; //Marshal.ReleaseComObject(progressDialogFactory); //trackCancel = null; //Marshal.ReleaseComObject(trackCancel); //stepProgressor = null; //Marshal.ReleaseComObject(stepProgressor); //appCursor = null; } progressDialog = null; progressDialogFactory = null; trackCancel = null; stepProgressor = null; lineCursor = null; editor = null; lineFeature = null; mxdoc = null; map = null; geoFeatureLayerID = null; enumLayer = null; eLayers = null; lineLayers = null; layer = null; fLayer = null; fSel = null; } }
private void DrawCircle3PMouseDown(IPoint pPoint, int shift) { IGeometry pGeom = null; IPolyline pPolyline; IPolygon pPolygon; IPoint pCenterPoint = new PointClass(); if (!m_bFirst) //如果命令没有使用 { m_pPoint1 = pPoint; m_bFirst = true; m_bSecond = false; m_pFeedback = new NewLineFeedbackClass(); m_pLineFeed = (INewLineFeedback)m_pFeedback; m_pLineFeed.Display = m_pActiveView.ScreenDisplay; m_pLineFeed.Start(pPoint); CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, m_pPoint1); } else if (!m_bSecond) //如果命令正在使用 { m_pPoint2 = pPoint; m_bSecond = true; m_bThree = false; CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, m_pPoint2); m_pLineFeed.Stop(); m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pEnvelope); m_pFeedback = new NewCircleFeedbackClass(); } else if (!m_bThree) { m_pPoint3 = m_pPoint; m_bFirst = false; m_bThree = true; m_pCenterPoint = CommonFunction.GetCenter_P123(m_pPoint1, m_pPoint2, pPoint); m_pCircleFeed = (NewCircleFeedbackClass)m_pFeedback; m_pCircleFeed.Display = m_pActiveView.ScreenDisplay; m_pCircleFeed.Stop(); m_pCircleFeed.Start(m_pCenterPoint); m_pFeedback.MoveTo(pPoint); ICircularArc pCircularArc = new CircularArcClass(); pCircularArc = m_pCircleFeed.Stop(); pCenterPoint = pCircularArc.CenterPoint; if (shift == 1) //若果按住shift健弹出对话框,让用户修改圆周上的坐标值 { frmCircle3P formCircle3P = new frmCircle3P(); formCircle3P.ShowDialog(); if (m_bModify) //修改坐标值了 { //计算圆心坐标 pCenterPoint = CommonFunction.GetCenter_P123(m_pPoint1, m_pPoint2, m_pPoint3); m_bModify = false; } } switch (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolyline: pPolyline = CommonFunction.ArcToPolyline(pCircularArc.FromPoint, pCircularArc.CenterPoint, pCircularArc.FromPoint, esriArcOrientation.esriArcClockwise); pGeom = pPolyline; break; case esriGeometryType.esriGeometryPolygon: pPolyline = CommonFunction.ArcToPolyline(pCircularArc.FromPoint, pCircularArc.CenterPoint, pCircularArc.FromPoint, esriArcOrientation.esriArcClockwise); pPolygon = CommonFunction.PolylineToPolygon(pPolyline); pGeom = pPolygon; break; default: break; } //end switch m_pEnvelope = pGeom.Envelope; if (m_pEnvelope != null && !m_pEnvelope.IsEmpty) { m_pEnvelope.Expand(10, 10, false); } ; CommonFunction.CreateFeature(m_App.Workbench, pGeom, m_FocusMap, m_CurrentLayer); Reset(); } // end if(!m_bThree) m_pLastPoint = pPoint; m_pSegment = null; }
//几何图形坐标转换 private void GeometryCoordConvert(ref IGeometry pConvertGeometry, double A1, double B1, double C1, double A2, double B2, double C2, double A3, double C3) { object a = System.Reflection.Missing.Value; object b = System.Reflection.Missing.Value; bool isRing = false; if (pConvertGeometry.GeometryType != esriGeometryType.esriGeometryPoint)//如果为线要素或面要素 { IArray pArrayPoint = new ArrayClass(); IArray pGeometryArray = new ArrayClass(); IGeometryCollection pGeometryCollection = pConvertGeometry as IGeometryCollection; for (int i = 0; i < pGeometryCollection.GeometryCount; i++) { IGeometry pGeometry = pGeometryCollection.get_Geometry(i); if (pGeometry.GeometryType != esriGeometryType.esriGeometryPoint)// { #region if (pGeometry.GeometryType == esriGeometryType.esriGeometryRing) { isRing = true; } if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon) { pGeometry = CommonFunction.GetPolygonBoundary((IPolygon)pGeometry); } ISegmentCollection pSegmentCol = (ISegmentCollection)pGeometry; ISegmentCollection pNewSegmentCol = new PolylineClass(); for (int k = 0; k < pSegmentCol.SegmentCount; k++)//遍历几何形体的每个节(片断) { //该节为直线段 if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryLine) { IPointCollection pPointCol1 = new MultipointClass(); ILine pLine = (ILine)pSegmentCol.get_Segment(k); IPoint pFromPoint = pLine.FromPoint; pPointCol1.AddPoint((IPoint)pFromPoint, ref a, ref b); IPoint pToPoint = pLine.ToPoint; pPointCol1.AddPoint((IPoint)pToPoint, ref a, ref b); PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol1);//对点集做镜像 //修改线段的端点坐标 pLine.FromPoint = pPointCol1.get_Point(0); pLine.ToPoint = pPointCol1.get_Point(1); pNewSegmentCol.AddSegment((ISegment)pLine, ref a, ref b); } //该节为圆弧 else if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryCircularArc) { IPointCollection pPointCol2 = new MultipointClass(); ICircularArc pCircularArc = (ICircularArc)pSegmentCol.get_Segment(k); try { IPoint pCenterPoint = pCircularArc.CenterPoint; pPointCol2.AddPoint((IPoint)pCenterPoint, ref a, ref b); IPoint pFromPoint = pCircularArc.FromPoint; pPointCol2.AddPoint((IPoint)pFromPoint, ref a, ref b); IPoint pToPoint = pCircularArc.ToPoint; pPointCol2.AddPoint((IPoint)pToPoint, ref a, ref b); PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol2);//对点集做镜像 //构造新的圆弧 ICircularArc pArc = new CircularArcClass(); pArc.PutCoords(pPointCol2.get_Point(0), pPointCol2.get_Point(1), pPointCol2.get_Point(2), (pCircularArc.IsCounterClockwise ? esriArcOrientation.esriArcCounterClockwise : esriArcOrientation.esriArcClockwise)); pNewSegmentCol.AddSegment((ISegment)pArc, ref a, ref b); } catch { } } //该节为贝塞尔曲线 else if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryBezier3Curve) { IPointCollection pPointCol3 = new MultipointClass(); IBezierCurve pBezierCurve = (IBezierCurve)pSegmentCol.get_Segment(k); //记录该节贝塞尔曲线的4个控制点 IPoint pFromPoint = new PointClass(); pBezierCurve.QueryCoord(0, pFromPoint); pPointCol3.AddPoint(pFromPoint, ref a, ref b); IPoint pFromTangentPoint = new PointClass(); pBezierCurve.QueryCoord(1, pFromTangentPoint); pPointCol3.AddPoint(pFromTangentPoint, ref a, ref b); IPoint pToTangentPoint = new PointClass(); pBezierCurve.QueryCoord(2, pToTangentPoint); pPointCol3.AddPoint(pToTangentPoint, ref a, ref b); IPoint pToPoint = new PointClass(); pBezierCurve.QueryCoord(3, pToPoint); pPointCol3.AddPoint(pToPoint, ref a, ref b); PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol3);//对点集做镜像 //修改该节贝塞尔曲线的4个控制点 pBezierCurve.PutCoord(0, pPointCol3.get_Point(0)); pBezierCurve.PutCoord(1, pPointCol3.get_Point(1)); pBezierCurve.PutCoord(2, pPointCol3.get_Point(2)); pBezierCurve.PutCoord(3, pPointCol3.get_Point(3)); pNewSegmentCol.AddSegment((ISegment)pBezierCurve, ref a, ref b); } }//end for 遍历几何形体的每个节(片断) CommonFunction.GeometryToArray(pNewSegmentCol as IGeometry, pArrayPoint); IPolycurve2 pPolycurve2 = CommonFunction.BuildPolyLineFromSegmentCollection(pNewSegmentCol); pGeometry = (IGeometry)pPolycurve2; #endregion } if (pConvertGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)//由线构成面 { pGeometry = CommonFunction.PolylineToPolygon(pGeometry as IPolyline); } pGeometryArray.Add(pGeometry); } if (pGeometryArray.Count > 1) { pConvertGeometry = pGeometryArray.get_Element(0) as IGeometry; if (isRing == true) { for (int i = 1; i < pGeometryArray.Count; i++) { pConvertGeometry = CommonFunction.DiffenceGeometry(pConvertGeometry, pGeometryArray.get_Element(i) as IGeometry); } } else { for (int i = 1; i < pGeometryArray.Count; i++) { pConvertGeometry = CommonFunction.UnionGeometry(pConvertGeometry, pGeometryArray.get_Element(i) as IGeometry); } } } else { pConvertGeometry = pGeometryArray.get_Element(0) as IGeometry; } CommonFunction.AddZMValueForGeometry(ref pConvertGeometry, pArrayPoint); } else { PointCoordConvert(ref pConvertGeometry, A1, B1, C1, A2, B2, C2, A3, C3); } }
private void II(StreamWriter sw) { if (sw != null) { sw.WriteLine("Distance;Eucl.Dist.;II"); } ArcMap.Document.ActiveView.GraphicsContainer.DeleteAllElements(); IRgbColor red = new RgbColor(); red.Red = 255; IRgbColor blue = new RgbColor(); blue.Blue = 255; IRgbColor green = new RgbColor(); green.Green = 255; double segin = trkbar_seg.Value; double seg = conv.ConvertUnits(segin, unit, mapunit); List <IPoint> pPoints = new List <IPoint>(); pPoints.Add(pCurve.FromPoint); double disttot = 0; double eucltot = 0; while (true) { IPoint pPointSectPrev = pPoints.ElementAt(pPoints.Count - 1); ICircularArc circularArc = new CircularArcClass(); ((IConstructCircularArc2)circularArc).ConstructCircle(pPointSectPrev, seg, true); ISegment Seg = (ISegment)circularArc; ISegmentCollection SegCollection = new PolylineClass() as ISegmentCollection; object Missing = System.Type.Missing; SegCollection.AddSegment(Seg, ref Missing, ref Missing); IGeometry pCircle = SegCollection as IGeometry; if (chkbox_con.Checked) { AddGraphicToMap(ArcMap.Document.ActiveView, pCircle, blue, blue, 1); } IPointCollection pSectPoints = ((ITopologicalOperator)pCurve).Intersect(pCircle, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection; IPoint pPointSect = null; for (int j = 0; j < pSectPoints.PointCount; j++) { if (GetDistAlong(pCurve as IPolyline, pSectPoints.get_Point(j)) > GetDistAlong(pCurve as IPolyline, pPointSectPrev)) { if (pPointSect == null) { pPointSect = pSectPoints.get_Point(j); } else if (GetDistAlong(pCurve as IPolyline, pSectPoints.get_Point(j)) < GetDistAlong(pCurve as IPolyline, pPointSect)) { pPointSect = pSectPoints.get_Point(j); } } } if (pPointSect == null) { pPointSect = pCurve.ToPoint; } pPoints.Add(pPointSect); if (chkbox_con.Checked) { AddGraphicToMap(ArcMap.Document.ActiveView, pPointSect as IGeometry, blue, blue, 1); } double d1 = GetDistAlong(pCurve as IPolyline, pPointSectPrev); double d2 = GetDistAlong(pCurve as IPolyline, pPointSect); ICurve pSubCurve; pCurve.GetSubcurve(d1, d2, false, out pSubCurve); double dist = conv.ConvertUnits(pSubCurve.Length, ArcMap.Document.FocusMap.MapUnits, esriUnits.esriMeters); double eucl = conv.ConvertUnits(((IProximityOperator)pSubCurve.FromPoint).ReturnDistance(pSubCurve.ToPoint), ArcMap.Document.FocusMap.MapUnits, esriUnits.esriMeters); double II = dist / eucl; disttot += dist; eucltot += eucl; if (sw != null) { sw.WriteLine(disttot.ToString("0") + ";" + eucltot.ToString("0") + ";" + II.ToString("0.00")); } IRgbColor pCol = new RgbColorClass(); if (II < 1.1) { pCol.Green = 255; } else if (II < 1.25) { pCol.Red = 192; pCol.Green = 255; } else if (II < 1.5) { pCol.Red = 255; pCol.Green = 255; } else if (II < 1.75) { pCol.Red = 255; pCol.Green = 192; } else { pCol.Red = 255; } if (chkbox_cat.Checked) { AddGraphicToMap(ArcMap.Document.ActiveView, pSubCurve as IGeometry, pCol, pCol, 2); } IPolyline pSubLine = new PolylineClass(); pSubLine.FromPoint = pPointSectPrev; pSubLine.ToPoint = pPointSect; if (chkbox_con.Checked) { AddGraphicToMap(ArcMap.Document.ActiveView, pSubLine as IGeometry, blue, blue, 1); } if (GetDistAlong(pCurve as IPolyline, pPointSect) == pCurve.Length) { if (sw != null) { sw.Close(); } break; } } }
private ISegmentCollection createSegments(Cell cell,BoostVoronoi bv,ArcConstructionMethods method,ISpatialReference spatialReference) { List<Cell> cells = bv.Cells; List<Edge> edges = bv.Edges; List<Vertex> vertices = bv.Vertices; IPoint previousEndPoint = null; ISegmentCollection segmentCollection = new PolygonClass() { SpatialReference = spatialReference }; // As per boost documentation, edges are returned in counter clockwise (CCW) rotation. // voronoi_edge_type* next() Returns the pointer to the CCW next edge within the corresponding Voronoi cell. Edges not necessarily share a common vertex (e.g. infinite edges). for (int i = cell.EdgesIndex.Count - 1; i >= 0; i--) { Edge edge = edges[cell.EdgesIndex[i]]; //If the vertex index equals -1, it means the edge is infinite. It is impossible to print the coordinates. if (!edge.IsFinite && edge.End < 0) { // this is the ending portion of a pair of infinite edges, file the previous edge with Start >= 0 Edge previous = null; for (int k = i + 1; k < cell.EdgesIndex.Count; k++) { previous = edges[cell.EdgesIndex[k]]; if (previous.End >= 0) break; previous = null; } if (previous == null) { for (int k = 0; k < i; k++) { previous = edges[cell.EdgesIndex[k]]; if (previous.End >= 0) break; previous = null; } } if (previous == null) throw new Exception("No outbound infinite edge could be found"); //Add a straight line segment Vertex start = vertices[previous.End]; IPoint FromPoint = new PointClass() { X = start.X, Y = start.Y, SpatialReference = spatialReference }; Vertex end = vertices[edge.Start]; IPoint ToPoint = new PointClass() { X = end.X, Y = end.Y, SpatialReference = spatialReference }; segmentCollection.AddSegment(new LineClass() { FromPoint = FromPoint, ToPoint = ToPoint, SpatialReference = spatialReference }); previousEndPoint = ToPoint; } else if (edge.IsFinite) { Vertex start = vertices[edge.End]; IPoint FromPoint = new PointClass() { X = start.X, Y = start.Y, SpatialReference = spatialReference }; if (previousEndPoint != null) { if ((Math.Abs(previousEndPoint.X - FromPoint.X) > 0.05 || Math.Abs(previousEndPoint.X - FromPoint.X) > 0.05)) throw new Exception("Significant change between last end point and current start point"); else FromPoint = previousEndPoint; } Vertex end = vertices[edge.Start]; IPoint ToPoint = new PointClass() { X = end.X, Y = end.Y, SpatialReference = spatialReference }; if (method == ArcConstructionMethods.Straight || edge.IsLinear) { segmentCollection.AddSegment(new LineClass() { FromPoint = FromPoint, ToPoint = ToPoint, SpatialReference = spatialReference }); previousEndPoint = ToPoint; } else { // We need three points, use start, end, mid-point between focus and directrix Cell twinCell = cells[edges[edge.Twin].Cell]; VPoint pointSite; VSegment lineSite; if (cell.ContainsPoint && twinCell.ContainsSegment) { pointSite = bv.RetrieveInputPoint(cell); lineSite = bv.RetrieveInputSegment(twinCell); } else if (cell.ContainsSegment && twinCell.ContainsPoint) { pointSite = bv.RetrieveInputPoint(twinCell); lineSite = bv.RetrieveInputSegment(cell); } else { throw new Exception("Invalid edge, curves should only be present between a point and a line"); } double scaleFactor = Convert.ToDouble(bv.ScaleFactor); IPoint aoPointSite = new Point() { X = Convert.ToDouble(pointSite.X) / scaleFactor, Y = Convert.ToDouble(pointSite.Y) / scaleFactor, SpatialReference = spatialReference }; ISegment aoLineSite = new LineClass() { FromPoint = new PointClass() { X = Convert.ToDouble(lineSite.Start.X) / scaleFactor, Y = Convert.ToDouble(lineSite.Start.Y) / scaleFactor, SpatialReference = spatialReference }, ToPoint = new PointClass() { X = Convert.ToDouble(lineSite.End.X) / scaleFactor, Y = Convert.ToDouble(lineSite.End.Y) / scaleFactor, SpatialReference = spatialReference }, SpatialReference = spatialReference }; if (method == ArcConstructionMethods.Approximate) { List<Vertex> sampledVerticed = null; try { sampledVerticed = bv.SampleCurvedEdge(edge, aoLineSite.Length / 10); } catch (FocusOnDirectixException e) { //Log any exception here is required sampledVerticed = new List<Vertex>() { start, end }; } catch (UnsolvableVertexException e) { sampledVerticed = new List<Vertex>() { start, end }; } sampledVerticed.Reverse(); List<IPoint> discretizedEdge = sampledVerticed.Select( p => new Point() { X = p.X, Y = p.Y } ).ToList<IPoint>(); IPoint prev = discretizedEdge[0]; foreach (IPoint v in discretizedEdge.Skip(1)) { segmentCollection.AddSegment(new LineClass() { FromPoint = new Point() { X = prev.X, Y = prev.Y, SpatialReference = spatialReference }, ToPoint = new Point() { X = v.X, Y = v.Y, SpatialReference = spatialReference }, SpatialReference = spatialReference }); prev = v; } previousEndPoint = discretizedEdge.Last(); } else if (method == ArcConstructionMethods.Circular) { IPoint nearPoint = ((IProximityOperator)aoLineSite).ReturnNearestPoint(aoPointSite, esriSegmentExtension.esriNoExtension); IPoint midpoint = new PointClass() { X = (nearPoint.X + aoPointSite.X) / 2, Y = (nearPoint.Y + aoPointSite.Y) / 2, SpatialReference = spatialReference }; IConstructCircularArc constArc = new CircularArcClass() { SpatialReference = spatialReference }; constArc.ConstructThreePoints(FromPoint, midpoint, ToPoint, false); ICircularArc arc = (ICircularArc)constArc; if (!arc.IsMinor) { constArc = new CircularArcClass() { SpatialReference = spatialReference }; constArc.ConstructEndPointsRadius(FromPoint, ToPoint, !arc.IsCounterClockwise, arc.Radius, true); arc = (ICircularArc)constArc; } segmentCollection.AddSegment((ISegment)arc); previousEndPoint = arc.ToPoint; } else if (method == ArcConstructionMethods.Ellipse) { IPoint nearPoint = ((IProximityOperator)aoLineSite).ReturnNearestPoint(aoPointSite, esriSegmentExtension.esriExtendTangents); nearPoint.SpatialReference = spatialReference; ILine lineToFocus = new LineClass() { FromPoint = nearPoint, ToPoint = aoPointSite, SpatialReference = spatialReference }; ILine semiMajor = new LineClass() { SpatialReference = spatialReference }; lineToFocus.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 1, true, 100 * lineToFocus.Length, semiMajor); IPoint center = new PointClass() { X = (semiMajor.FromPoint.X + semiMajor.ToPoint.X) / 2, Y = (semiMajor.FromPoint.Y + semiMajor.ToPoint.Y) / 2, SpatialReference = spatialReference }; double minor_length = Math.Sqrt( Math.Pow(distance(semiMajor.FromPoint, ToPoint) + distance(semiMajor.ToPoint, ToPoint), 2) - Math.Pow(semiMajor.Length, 2)); IEllipticArc arc = new EllipticArcClass() { SpatialReference = spatialReference }; double rotation = lineToFocus.Angle; double from = GetAngle(center, FromPoint); arc.PutCoords(false, center, FromPoint, ToPoint, rotation, minor_length / semiMajor.Length, esriArcOrientation.esriArcMinor); segmentCollection.AddSegment((ISegment)arc); previousEndPoint = arc.ToPoint; } } } } return segmentCollection; }
private void II_analyze(StreamWriter sw) { if (sw == null) { return; } List <List <double> > pLevelsDist = new List <List <double> >(); List <List <double> > pLevelsEucl = new List <List <double> >(); List <List <double> > pLevelsII = new List <List <double> >(); bool lastlevel = false; while (!lastlevel) { double segin = trkbar_seg.Value * Math.Pow(2, (pLevelsII.Count)); double seg = conv.ConvertUnits(segin, unit, mapunit); List <IPoint> pPoints = new List <IPoint>(); pPoints.Add(pCurve.FromPoint); List <double> pDist = new List <double>(); List <double> pEucl = new List <double>(); List <double> pII = new List <double>(); bool lastpoint = false; while (!lastpoint) { System.Windows.Forms.Application.DoEvents(); IPoint pPointSectPrev = pPoints.ElementAt(pPoints.Count - 1); ICircularArc circularArc = new CircularArcClass(); ((IConstructCircularArc2)circularArc).ConstructCircle(pPointSectPrev, seg, true); ISegment Seg = (ISegment)circularArc; ISegmentCollection SegCollection = new PolylineClass() as ISegmentCollection; object Missing = System.Type.Missing; SegCollection.AddSegment(Seg, ref Missing, ref Missing); IGeometry pCircle = SegCollection as IGeometry; IPointCollection pSectPoints = ((ITopologicalOperator)pCurve).Intersect(pCircle, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection; if (pSectPoints.PointCount == 0) { lastlevel = true; break; } IPoint pPointSect = null; for (int j = 0; j < pSectPoints.PointCount; j++) { if (GetDistAlong(pCurve as IPolyline, pSectPoints.get_Point(j)) > GetDistAlong(pCurve as IPolyline, pPointSectPrev)) { if (pPointSect == null) { pPointSect = pSectPoints.get_Point(j); } else if (GetDistAlong(pCurve as IPolyline, pSectPoints.get_Point(j)) < GetDistAlong(pCurve as IPolyline, pPointSect)) { pPointSect = pSectPoints.get_Point(j); } } } if (pPointSect == null) { pPointSect = pCurve.ToPoint; lastpoint = true; } pPoints.Add(pPointSect); double d1 = GetDistAlong(pCurve as IPolyline, pPointSectPrev); double d2 = GetDistAlong(pCurve as IPolyline, pPointSect); ICurve pSubCurve; pCurve.GetSubcurve(d1, d2, false, out pSubCurve); double dist = conv.ConvertUnits(pSubCurve.Length, ArcMap.Document.FocusMap.MapUnits, esriUnits.esriMeters); double eucl = conv.ConvertUnits(((IProximityOperator)pSubCurve.FromPoint).ReturnDistance(pSubCurve.ToPoint), ArcMap.Document.FocusMap.MapUnits, esriUnits.esriMeters); double II = dist / eucl; pDist.Add(dist); pEucl.Add(eucl); pII.Add(II); } if (pII.Count == 0) { break; } pLevelsII.Add(pII); pLevelsEucl.Add(pEucl); pLevelsDist.Add(pDist); } int levels = pLevelsII.Count; sw.Write("Segment"); for (int i = 1; i <= levels; i++) { double eucl = conv.ConvertUnits(pLevelsEucl.ElementAt(i - 1).First(), mapunit, unit); double eucllast = conv.ConvertUnits(pLevelsEucl.ElementAt(i - 1).Last(), mapunit, unit); sw.Write(";" + i.ToString() + "(" + (pLevelsII.ElementAt(i - 1).Count - 1) + " x " + eucl.ToString("0") + " + 1 x " + eucllast.ToString("0") + " " + combox_unit.Text + ")"); } sw.WriteLine(); for (int i = 0; i < pLevelsII.ElementAt(0).Count; i++) { string line = (i + 1).ToString(); for (int j = 0; j < levels; j++) { System.Windows.Forms.Application.DoEvents(); try { line = line + ";" + pLevelsII.ElementAt(j).ElementAt(i).ToString("0.00"); } catch { line = line + ";"; } } sw.WriteLine(line); } sw.Close(); }
public static IPolyline CreatePolyline(object[] paths) { IPolyline result = null; IGeometryCollection pGeomCol = new PolylineClass(); object objMissing = Type.Missing; foreach (object o in paths)//part { object[] ringpoints = o as object[]; if (ringpoints != null) { ISegmentCollection pSegCol = new PathClass(); ISegment pSeg = new LineClass(); IPoint pFromPt = new PointClass(); IPoint pToPt = new PointClass(); IPoint pEndPt = new PointClass(); List <PointObject> poList = new List <PointObject>(); foreach (object po in ringpoints) { PointObject pObj = new PointObject(); object[] ptxya = po as object[]; if (ptxya != null) { if (ptxya.Length == 3) { pObj.X = double.Parse(ptxya[0].ToString()); pObj.Y = double.Parse(ptxya[1].ToString()); pObj.A = int.Parse(ptxya[2].ToString()); } else if (ptxya.Length == 2) { pObj.X = double.Parse(ptxya[0].ToString()); pObj.Y = double.Parse(ptxya[1].ToString()); pObj.A = 0; } else { throw new Exception("坐标串输入错误!"); } poList.Add(pObj); } } if (poList.Count < 2) { throw new Exception("至少保证两个点来确定一条线!"); } for (int i = 0; i < poList.Count - 1; i++) { if (poList[i].A.Equals(1))//处理狐段 { PointObject poF = null; PointObject poT = null; PointObject poE = null; if (i - 1 < 0) { poF = poList[poList.Count - 2]; } else { poF = poList[i - 1]; } poT = poList[i]; poE = poList[i + 1]; pFromPt.PutCoords(poF.X, poF.Y); pToPt.PutCoords(poT.X, poT.Y); pEndPt.PutCoords(poE.X, poE.Y); //圆弧 ICircularArc cirularArc = new CircularArcClass(); IConstructCircularArc constructCircularArc = cirularArc as IConstructCircularArc; constructCircularArc.ConstructThreePoints(pFromPt, pToPt, pEndPt, true); pSeg = cirularArc as ISegment; pSegCol.AddSegment(pSeg, ref objMissing, ref objMissing); } else { if (poList[i + 1].A.Equals(0))//处理直线,否则不处理 { pFromPt.PutCoords(poList[i].X, poList[i].Y); pToPt.PutCoords(poList[i + 1].X, poList[i + 1].Y); pSeg = new LineClass(); pSeg.FromPoint = pFromPt; pSeg.ToPoint = pToPt; //一根线段 pSegCol.AddSegment(pSeg, ref objMissing, ref objMissing); } } } //一个part pGeomCol.AddGeometry(pSegCol as IGeometry, ref objMissing, ref objMissing); } } result = pGeomCol as IPolyline; return(result); }
protected override void OnClick() { FileType ft = FileType.COGOToolbarTraverse; //start out assuming it is a cogo traverse file m_count = 1; ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); ICadastralFabric pCadFabric = pCadEd.CadastralFabric; ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)pCadEd; IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd; IParcelConstruction pTrav = pParcEditorMan.ParcelConstruction; if (!(pParcEditorMan.InTraverseEditMode) && !(pParcEditorMan.InConstructionEditMode)) {//if this is not a construction or a new parcel, then get out. MessageBox.Show("Please create a new parcel or new construction first, and then try again."); return; } //Make sure the lines grid is selected Utilities UTILS = new Utilities(); UTILS.SelectCadastralPropertyPage((ICadastralExtensionManager)pCadExtMan, "lines"); IParcelConstruction3 pTrav3 = (IParcelConstruction3)pTrav; IGSParcel pParcel = null; try { pParcel = pTrav.Parcel; } catch (COMException error) { MessageBox.Show(error.Message.ToString()); return; } //go get a traverse file // Display .Net dialog for File selection. OpenFileDialog openFileDialog = new OpenFileDialog(); // Set File Filter openFileDialog.Filter = "Traverse file (*.txt)|*.txt|Comma-delimited(*.csv)|*.csv|All Files|*.*"; // Disable multi-select openFileDialog.Multiselect = false; // Don't need to Show Help openFileDialog.ShowHelp = false; // Set Dialog Title openFileDialog.Title = "Load file"; openFileDialog.FilterIndex = 2; // Display Open File Dialog if (openFileDialog.ShowDialog() != DialogResult.OK) { openFileDialog = null; return; } TextReader tr = null; try { tr = new StreamReader(openFileDialog.FileName); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } string sCourse = ""; int iCount = 0; string[] sFileLine = new string[0]; //define as dynamic array //initialize direction units and format esriDirectionType enumDirectionType = esriDirectionType.esriDTQuadrantBearing; esriDirectionUnits enumDirectionUnits = esriDirectionUnits.esriDUDegreesMinutesSeconds; //initialize start and end points IPoint StartPoint = new PointClass(); IPoint EndPoint = new PointClass(); bool IsLoopTraverse = false; //fill the array with the lines from the file while (sCourse != null) { sCourse = tr.ReadLine(); try { if (sCourse.Trim().Length >= 1) //test for empty lines { RedimPreserveString(ref sFileLine, 1); sFileLine[iCount] = sCourse; } iCount++; sCourse = sCourse.ToLower(); if (sCourse.Contains("dt")) { if (sCourse.Contains("qb")) { enumDirectionType = esriDirectionType.esriDTQuadrantBearing; } else if (sCourse.Contains("na")) { enumDirectionType = esriDirectionType.esriDTNorthAzimuth; } else if (sCourse.Contains("sa")) { enumDirectionType = esriDirectionType.esriDTSouthAzimuth; } else if (sCourse.Contains("p")) { enumDirectionType = esriDirectionType.esriDTPolar; } } if (sCourse.Contains("du")) { if (sCourse.Contains("dms")) { enumDirectionUnits = esriDirectionUnits.esriDUDegreesMinutesSeconds; } else if (sCourse.Contains("dd")) { enumDirectionUnits = esriDirectionUnits.esriDUDecimalDegrees; } else if (sCourse.Contains("g")) { enumDirectionUnits = esriDirectionUnits.esriDUGons; } else if (sCourse.Contains("r")) { enumDirectionUnits = esriDirectionUnits.esriDURadians; } } if (sCourse.Contains("sp")) {//start point string[] XY = sCourse.Split(' '); double x = Convert.ToDouble(XY[1]); double y = Convert.ToDouble(XY[2]); StartPoint.PutCoords(x, y); } if (sCourse.Contains("ep")) {//end point string[] XY = sCourse.Split(' '); double x = Convert.ToDouble(XY[1]); double y = Convert.ToDouble(XY[2]); EndPoint.PutCoords(x, y); } if (sCourse.Contains("tometricfactor")) {//this handles the comma-separated file case string[] sScaleFactor = sCourse.Split(','); m_dScaleFactor = Convert.ToDouble(sScaleFactor[1]); } } catch { } } tr.Close(); //close the file and release resources string sFileExt = System.IO.Path.GetExtension(openFileDialog.FileName.TrimEnd()); if ((sFileExt.ToLower() == ".csv") && (sFileLine[0].Contains(","))) {//if it's a comma-delimited file ft = FileType.CommaDelimited; } //Test for loop traverse if (!(EndPoint.IsEmpty)) { if (EndPoint.Compare(StartPoint) == 0) { IsLoopTraverse = true; } else { IsLoopTraverse = false; } } //get highest point id number in grid, and get the to point id on the last line. IGSLine pParcelLine = null; int iFirstToNode = -1; int iLastToNode = -1; int iHighestPointID = -1; for (int i = 0; i < pTrav.LineCount; i++) { if (pTrav.GetLine(i, ref pParcelLine)) { if (iFirstToNode < 0) { iFirstToNode = pParcelLine.ToPoint; } iLastToNode = pParcelLine.ToPoint; iHighestPointID = iHighestPointID < pParcelLine.ToPoint ? pParcelLine.ToPoint : iHighestPointID; iHighestPointID = iHighestPointID < pParcelLine.FromPoint ? pParcelLine.FromPoint : iHighestPointID; } } ICadastralUndoRedo pCadUndoRedo = pTrav as ICadastralUndoRedo; pCadUndoRedo.StartUndoRedoSession("Load Lines From File"); try { IGSLine pLine = null; int iLinecount = iCount - 1; ISegment pExitTangent = null; for (iCount = 0; iCount <= iLinecount; iCount++) { if (ft == FileType.COGOToolbarTraverse) { { pLine = null; ICircularArc pCircArc;//need to use this in the test to handle curves greater than 180 pLine = CreateGSLine(sFileLine[iCount], enumDirectionUnits, enumDirectionType, pExitTangent, out pExitTangent, out pCircArc); //exit tangent from the previous course is the new entry tangent for the next course if (pLine != null) { if (pCircArc == null) {// straight line //if this is the last course then set the to point to 1 if ((iCount == iLinecount) && IsLoopTraverse) { pLine.ToPoint = 1; } pTrav.InsertGridRow(-1, pLine); } else { //some post-processing needed to figure out if a 180 curve needs to be split if (Math.Abs(pCircArc.CentralAngle) < (Math.PI - 0.000001)) //some tolerance for being close to 180 { //this curve is OK //if this is the last course then set the to point to 1 if ((iCount == iLinecount) && IsLoopTraverse) { pLine.ToPoint = 1; } pTrav.InsertGridRow(-1, pLine); } else {//curve is greater than or equal to 180, special treatment for GSE needed to split curve into 2 parts //first decrement the count m_count -= 1; ISegment pFullSegment = (ISegment)pCircArc; ISegment pFirstHalf; ISegment pSecondHalf; pFullSegment.SplitAtDistance(0.5, true, out pFirstHalf, out pSecondHalf); IConstructCircularArc2 pCircArcConstr1 = new CircularArcClass(); ICircularArc pCircArc1 = (ICircularArc)pCircArcConstr1; pCircArcConstr1.ConstructEndPointsRadius(pFirstHalf.FromPoint, pFirstHalf.ToPoint, pCircArc.IsCounterClockwise, pCircArc.Radius, true); ILine2 pTangentLine = new LineClass(); pCircArc1.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 0, false, 100, pTangentLine); string sTangentBearing = PolarRadians_2_DirectionString(pTangentLine.Angle, enumDirectionType, enumDirectionUnits); sTangentBearing = sTangentBearing.Replace(" ", ""); string sHalfDelta = Radians_2_Angle(Math.Abs(pCircArc1.CentralAngle), enumDirectionUnits); string sSide = pCircArc.IsCounterClockwise ? " L " : " R "; ISegment EntryTangent = (ISegment)pTangentLine; //construct the string for the first piece // looks similar to this: NC R 500 D 181-59-59 T N59-59-59W L string sFirstCurve = "NC R " + Convert.ToString(pCircArc.Radius) + " D " + sHalfDelta + " T " + sTangentBearing + sSide; IGSLine pLineFirstCurve = CreateGSLine(sFirstCurve, enumDirectionUnits, enumDirectionType, pExitTangent, out pExitTangent, out pCircArc); pTrav.InsertGridRow(-1, pLineFirstCurve); ICircularArc pCircArc2 = (ICircularArc)pCircArcConstr1; pCircArcConstr1.ConstructEndPointsRadius(pSecondHalf.FromPoint, pSecondHalf.ToPoint, pCircArc.IsCounterClockwise, pCircArc.Radius, true); pCircArc2.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 0, false, 100, pTangentLine); sTangentBearing = PolarRadians_2_DirectionString(pTangentLine.Angle, enumDirectionType, enumDirectionUnits); sTangentBearing = sTangentBearing.Replace(" ", ""); //construct the string for the second piece // looks similar to this: NC R 500 D 181-59-59 T N59-59-59W L string sSecondCurve = "NC R " + Convert.ToString(pCircArc.Radius) + " D " + sHalfDelta + " T " + sTangentBearing + sSide; IGSLine pLineSecondCurve = CreateGSLine(sSecondCurve, enumDirectionUnits, enumDirectionType, pExitTangent, out pExitTangent, out pCircArc); //if this is the last course then set the to point to 1 if ((iCount == iLinecount) && IsLoopTraverse) { pLine.ToPoint = 1; } pTrav.InsertGridRow(-1, pLineSecondCurve); } } } } } else//this is comma-separated version of the grid, so do the following { pLine = null; //apply a point id number offset if there are existing lines in the grid. if (iHighestPointID > -1 && iCount >= 3) { string[] sTraverseCourse = sFileLine[iCount].Split(','); if (iCount == 3) { sTraverseCourse[0] = iLastToNode.ToString(); sTraverseCourse[5] = (Convert.ToInt32(sTraverseCourse[5]) + iHighestPointID).ToString(); } else if (iCount > 3) { sTraverseCourse[0] = (Convert.ToInt32(sTraverseCourse[0]) + iHighestPointID).ToString(); sTraverseCourse[5] = (Convert.ToInt32(sTraverseCourse[5]) + iHighestPointID).ToString(); } sFileLine[iCount] = sTraverseCourse[0]; int iAttCount = sTraverseCourse.GetLength(0); for (int j = 1; j < iAttCount; j++) { sFileLine[iCount] += "," + sTraverseCourse[j]; } } pLine = CreateGSLineFromCommaSeparatedString(sFileLine[iCount], enumDirectionUnits, enumDirectionType); if (pLine != null) { pTrav.InsertGridRow(-1, pLine); } } } pTrav3.UpdateGridFromGSLines(false); IParcelConstruction2 pConstr2 = (IParcelConstruction2)pTrav3; //hidden interface pConstr2.RecalculatePoints(); //explicit recalculate needed on a construction pParcel.Modified(); pParcEditorMan.Refresh(); pCadUndoRedo.WriteUndoRedoSession(true); sFileLine = null; openFileDialog = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "Load Lines From File"); pCadUndoRedo.WriteUndoRedoSession(false); } }
private ICircularArc ConstructCurveFromString(string inString, ISegment ExitTangentFromPreviousCourse, esriDirectionType inDirectionType, esriDirectionUnits inDirectionUnits, out double outChordLength, out double outChordBearing) {// IConstructCircularArc pConstArc = new CircularArcClass(); ICircularArc pArc = (ICircularArc)pConstArc; IPoint pPt = new PointClass(); pPt.PutCoords(1000, 1000); //initialize the curve params bool bHasRadius = false; double dRadius = -1; bool bHasChord = false; double dChord = -1; bool bHasArc = false; double dArcLength = -1; bool bHasDelta = false; double dDelta = -1; bool bCCW = false; //assume curve to right unless proven otherwise //now initialize bearing types for non-tangent curves bool bHasRadialBearing = false; double dRadialBearing = -1; bool bHasChordBearing = false; double dChordBearing = -1; bool bHasTangentBearing = false; double dTangentBearing = -1; ISegment EntryTangentSegment = null; int iItemPosition = 0; string[] sCourse = inString.Split(' '); int UpperBound = sCourse.GetUpperBound(0); bool bIsTangentCurve = (((string)sCourse.GetValue(0)).ToLower() == "tc"); foreach (string item in sCourse) { if (item == null) { break; } if ((item.ToLower() == "r") && (!bHasRadius) && (iItemPosition <= 3)) { // this r is for radius dRadius = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasRadius = true; //found a radius } if ((item.ToLower()) == "c" && (!bHasChord) && (iItemPosition <= 3)) { // this c is for chord length dChord = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasChord = true; //found a chord length } if ((item.ToLower()) == "a" && (!bHasArc) && (iItemPosition <= 3)) { // this a is for arc length dArcLength = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasArc = true; //found an arc length } if ((item.ToLower()) == "d" && (!bHasDelta) && (iItemPosition <= 3)) { // this d is for delta or central angle dDelta = Angle_2_Radians((string)sCourse.GetValue(iItemPosition + 1), inDirectionUnits); bHasDelta = true; //found a central angle } if ((item.ToLower()) == "r" && (!bHasRadialBearing) && (iItemPosition > 3) && (UpperBound > 5)) {// this r is for radial bearing try { dRadialBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); if (!(dRadialBearing == -999)) { bHasRadialBearing = true; } //found a radial bearing } catch { }//this will catch case of final R meaning a curve right and not radial bearing } if ((item.ToLower()) == "c" && (!bHasChordBearing) && (iItemPosition > 3)) { // this c is for chord bearing dChordBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); bHasChordBearing = true; //found a chord bearing } if ((item.ToLower()) == "t" && (!bHasTangentBearing) && (iItemPosition > 3)) { // this t is for tangent bearing dTangentBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); bHasTangentBearing = true; //found a tangent bearing IConstructPoint2 pToPt = new PointClass(); pToPt.ConstructAngleDistance(pPt, dTangentBearing, 100); ILine EntryTangentLine = new LineClass(); EntryTangentLine.PutCoords(pPt, (IPoint)pToPt); EntryTangentSegment = (ISegment)EntryTangentLine; } if ((item.ToLower()) == "l") { // this l is for defining a curve to the left bCCW = true; } iItemPosition += 1; } if (!(bIsTangentCurve)) //non-tangent curve { //chord bearing if (bHasRadius && bHasChord && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusChord(pPt, dChordBearing, bCCW, dRadius, dChord, true); } catch { }; } if (bHasRadius && bHasArc && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusArc(pPt, dChordBearing, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusAngle(pPt, dChordBearing, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasChordBearing) { try { pConstArc.ConstructBearingAngleChord(pPt, dChordBearing, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasChordBearing) { try { pConstArc.ConstructBearingChordArc(pPt, dChordBearing, bCCW, dChord, dArcLength); } catch { }; } //tangent bearing if (bHasRadius && bHasChord && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusChord(EntryTangentSegment, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusArc(EntryTangentSegment, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusAngle(EntryTangentSegment, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasTangentBearing) { try { pConstArc.ConstructTangentAngleChord(EntryTangentSegment, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasTangentBearing) { try { pConstArc.ConstructTangentChordArc(EntryTangentSegment, false, bCCW, dChord, dArcLength); } catch { }; } //radial bearing if (bHasRadialBearing) { //need to convert radial bearing to tangent bearing by adding/subtracting 90 degrees double dTanBear = 0; if (bCCW) { dTanBear = dRadialBearing - (Angle_2_Radians("90", esriDirectionUnits.esriDUDecimalDegrees)); } else { dTanBear = dRadialBearing + (Angle_2_Radians("90", esriDirectionUnits.esriDUDecimalDegrees)); } IConstructPoint2 pToPt = new PointClass(); pToPt.ConstructAngleDistance(pPt, dTanBear, 100); ILine EntryTangentLine = new LineClass(); EntryTangentLine.PutCoords(pPt, (IPoint)pToPt); EntryTangentSegment = (ISegment)EntryTangentLine; } if (bHasRadius && bHasChord && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusChord(EntryTangentSegment, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusArc(EntryTangentSegment, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusAngle(EntryTangentSegment, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasRadialBearing) { try { pConstArc.ConstructTangentAngleChord(EntryTangentSegment, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasRadialBearing) { try { pConstArc.ConstructTangentChordArc(EntryTangentSegment, false, bCCW, dChord, dArcLength); } catch { }; } } else { //tangent curve if (bHasRadius && bHasChord) { try { pConstArc.ConstructTangentRadiusChord(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc) { try { pConstArc.ConstructTangentRadiusArc(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta) { try { pConstArc.ConstructTangentRadiusAngle(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta) { try { pConstArc.ConstructTangentAngleChord(ExitTangentFromPreviousCourse, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc) { try { pConstArc.ConstructTangentChordArc(ExitTangentFromPreviousCourse, false, bCCW, dChord, dArcLength); } catch { }; } } ILine pLine = new LineClass(); try { pLine.PutCoords(pArc.FromPoint, pArc.ToPoint); } catch { outChordLength = -1; outChordBearing = -1; return(null); } outChordLength = pLine.Length; outChordBearing = pLine.Angle; return(pArc); }
private void DrawFanShaped(double x, double y, IActiveView pActiveView) { double radius = this.radius; double small_radius = this.small_radius; double start_angle = this.start_angle; double central_angle = this.central_angle; if (pActiveView != null) { IGraphicsContainer graphicsContainer = pActiveView as IGraphicsContainer; //画大圆 IPoint pCenterPoint = new PointClass(); pCenterPoint.PutCoords(x, y); ICircularArc pCircularArc = new CircularArcClass(); pCircularArc.PutCoordsByAngle(pCenterPoint, start_angle * Math.PI / 180.0, central_angle * Math.PI / 180.0, radius); IPoint pStartPoint = pCircularArc.FromPoint; IPoint pEndPoint = pCircularArc.ToPoint; ILine pLine1 = new LineClass(); pLine1.PutCoords(pCenterPoint, pStartPoint); ILine pLine2 = new LineClass(); pLine2.PutCoords(pEndPoint, pCenterPoint); ISegmentCollection pRing1 = new PolygonClass(); ISegment pSegment1 = pLine1 as ISegment; pRing1.AddSegment(pSegment1); ISegment pSegment2 = pCircularArc as ISegment; pRing1.AddSegment(pSegment2); ISegment pSegment3 = pLine2 as ISegment; pRing1.AddSegment(pSegment3); //小圆 ICircularArc pCircularArc1 = new CircularArcClass(); pCircularArc1.PutCoordsByAngle(pCenterPoint, start_angle * Math.PI / 180.0, central_angle * Math.PI / 180.0, small_radius); IPoint pStartPoint1 = pCircularArc1.FromPoint; IPoint pEndPoint1 = pCircularArc1.ToPoint; ILine pLine3 = new LineClass(); pLine3.PutCoords(pCenterPoint, pStartPoint1); ILine pLine4 = new LineClass(); pLine4.PutCoords(pEndPoint1, pCenterPoint); ISegmentCollection pRing2 = new PolygonClass(); ISegment pSegment4 = pLine3 as ISegment; pRing2.AddSegment(pSegment4); ISegment pSegment5 = pCircularArc1 as ISegment; pRing2.AddSegment(pSegment5); ISegment pSegment6 = pLine4 as ISegment; pRing2.AddSegment(pSegment6); //简化 ITopologicalOperator pTopoLogical1 = pRing1 as ITopologicalOperator; pTopoLogical1.Simplify(); ITopologicalOperator pTopoLogical2 = pRing2 as ITopologicalOperator; pTopoLogical2.Simplify(); IGeometry geometry = pTopoLogical1.Difference(pTopoLogical2 as IGeometry); //产生一个SimpleFillSymbol符号 IRgbColor rgbColor = new RgbColorClass(); rgbColor.Red = 255; rgbColor.Green = 0; rgbColor.Blue = 0; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Width = 1; ISimpleFillSymbol simpleFillSymbol; simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; //设置颜色 IRgbColor rgbcolor = new RgbColorClass(); rgbcolor.Red = 0; rgbcolor.Green = 0; rgbcolor.Blue = 255; simpleFillSymbol.Color = rgbcolor as IColor; simpleFillSymbol.Outline = simpleLineSymbol; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; IElement pElement = fillShapeElement as IElement; pElement.Geometry = geometry; graphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
//private void EndDrawCircleCentRadWihtShift() //{ // frmCentRad formCentRad = new frmCentRad(); // formCentRad.ShowDialog(); // if( m_bFixRadius ) // { // IGeometry pGeom = null; // IPolyline pPolyline; // IPolygon pPolygon; // IPoint pPoint = new PointClass(); // pPoint.X = m_pCenterPoint.X + m_dblRadius; // pPoint.Y = m_pCenterPoint.Y; // pPolyline = CommonFunction.ArcToPolyline(pPoint, m_pCenterPoint, pPoint,esriArcOrientation.esriArcClockwise); // switch (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType) // { // case esriGeometryType.esriGeometryPolyline: // pGeom = pPolyline; // break; // case esriGeometryType.esriGeometryPolygon: // pPolygon = CommonFunction.PolylineToPolygon(pPolyline); // pGeom = pPolygon; // break; // default: // break; // }//end switch // m_pEnvelope = pGeom.Envelope; // if(m_pEnvelope != null &&!m_pEnvelope.IsEmpty ) m_pEnvelope.Expand(10,10,false);; // CommonFunction.CreateFeature(m_App.Workbench,pGeom, m_FocusMap, m_CurrentLayer); // m_App.Workbench.CommandBarManager.Tools["2dmap.DFEditorTool.Undo"].SharedProps.Enabled = true; // } // Reset(); //} private void DrawCircleCentRadMouseDown(IPoint pPoint, int shift) { Class.Common.DrawPointSMSSquareSymbol(m_MapControl, pPoint); if (!m_bInUse) //如果命令没有使用 { m_bInUse = true; m_pCenterPoint = pPoint; m_pFeedback = new NewCircleFeedbackClass(); m_pCircleFeed = (NewCircleFeedbackClass)m_pFeedback; m_pCircleFeed.Display = m_pActiveView.ScreenDisplay; m_pCircleFeed.Start(m_pCenterPoint); } else //如果命令已经使用使用 { IGeometry pGeom = null; IPolyline pPolyline; IPolygon pPolygon; ICircularArc pCircularArc = new CircularArcClass(); //if (shift == 1)//若果按住shift健弹出对话框,让用户修改圆周上的坐标值 //{ // EndDrawCircleCentRadWihtShift(); //} //else //{ m_pFeedback.MoveTo(pPoint); pCircularArc = m_pCircleFeed.Stop(); m_dblRadius = pCircularArc.Radius; switch (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolyline: pPolyline = Class.Common.ArcToPolyline(pCircularArc.FromPoint, pCircularArc.CenterPoint, pCircularArc.FromPoint, esriArcOrientation.esriArcClockwise); pGeom = pPolyline; break; case esriGeometryType.esriGeometryPolygon: pPolyline = Class.Common.ArcToPolyline(pCircularArc.FromPoint, pCircularArc.CenterPoint, pCircularArc.FromPoint, esriArcOrientation.esriArcClockwise); pPolygon = Class.Common.PolylineToPolygon(pPolyline); pGeom = pPolygon; break; default: break; } //end switch m_pEnvelope = pGeom.Envelope; if (m_pEnvelope != null && !m_pEnvelope.IsEmpty) { m_pEnvelope.Expand(10, 10, false); } Class.Common.CreateFeature(pGeom, m_FocusMap, m_CurrentLayer); m_App.Workbench.UpdateMenu(); Reset(); //} } m_pLastPoint = pPoint; }
private ICircularArc ConstructCurveFromString(string inString, ISegment ExitTangentFromPreviousCourse, esriDirectionType inDirectionType, esriDirectionUnits inDirectionUnits, out double outChordLength, out double outChordBearing) { // IConstructCircularArc pConstArc = new CircularArcClass(); ICircularArc pArc = (ICircularArc)pConstArc; IPoint pPt = new PointClass(); pPt.PutCoords(1000, 1000); //initialize the curve params bool bHasRadius = false; double dRadius = -1; bool bHasChord = false; double dChord = -1; bool bHasArc = false; double dArcLength = -1; bool bHasDelta = false; double dDelta = -1; bool bCCW = false; //assume curve to right unless proven otherwise //now initialize bearing types for non-tangent curves bool bHasRadialBearing = false; double dRadialBearing = -1; bool bHasChordBearing = false; double dChordBearing = -1; bool bHasTangentBearing = false; double dTangentBearing = -1; ISegment EntryTangentSegment = null; int iItemPosition = 0; string[] sCourse = inString.Split(' '); int UpperBound = sCourse.GetUpperBound(0); bool bIsTangentCurve = (((string)sCourse.GetValue(0)).ToLower() == "tc"); foreach (string item in sCourse) { if (item == null) break; if ((item.ToLower() == "r") && (!bHasRadius) && (iItemPosition <= 3)) {// this r is for radius dRadius = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasRadius = true; //found a radius } if ((item.ToLower()) == "c" && (!bHasChord) && (iItemPosition <= 3)) {// this c is for chord length dChord = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasChord = true; //found a chord length } if ((item.ToLower()) == "a" && (!bHasArc) && (iItemPosition <= 3)) {// this a is for arc length dArcLength = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasArc = true; //found an arc length } if ((item.ToLower()) == "d" && (!bHasDelta) && (iItemPosition <= 3)) {// this d is for delta or central angle dDelta = Angle_2_Radians((string)sCourse.GetValue(iItemPosition + 1), inDirectionUnits); bHasDelta = true; //found a central angle } if ((item.ToLower()) == "r" && (!bHasRadialBearing) && (iItemPosition > 3) && (UpperBound > 5)) {// this r is for radial bearing try { dRadialBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); if (!(dRadialBearing == -999)) { bHasRadialBearing = true; } //found a radial bearing } catch { }//this will catch case of final R meaning a curve right and not radial bearing } if ((item.ToLower()) == "c" && (!bHasChordBearing) && (iItemPosition > 3)) {// this c is for chord bearing dChordBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); bHasChordBearing = true; //found a chord bearing } if ((item.ToLower()) == "t" && (!bHasTangentBearing) && (iItemPosition > 3)) {// this t is for tangent bearing dTangentBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); bHasTangentBearing = true; //found a tangent bearing IConstructPoint2 pToPt = new PointClass(); pToPt.ConstructAngleDistance(pPt, dTangentBearing, 100); ILine EntryTangentLine = new LineClass(); EntryTangentLine.PutCoords(pPt, (IPoint)pToPt); EntryTangentSegment = (ISegment)EntryTangentLine; } if ((item.ToLower()) == "l") // this l is for defining a curve to the left bCCW = true; iItemPosition += 1; } if (!(bIsTangentCurve)) //non-tangent curve {//chord bearing if (bHasRadius && bHasChord && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusChord(pPt, dChordBearing, bCCW, dRadius, dChord, true); } catch { }; } if (bHasRadius && bHasArc && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusArc(pPt, dChordBearing, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusAngle(pPt, dChordBearing, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasChordBearing) { try { pConstArc.ConstructBearingAngleChord(pPt, dChordBearing, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasChordBearing) { try { pConstArc.ConstructBearingChordArc(pPt, dChordBearing, bCCW, dChord, dArcLength); } catch { }; } //tangent bearing if (bHasRadius && bHasChord && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusChord(EntryTangentSegment, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusArc(EntryTangentSegment, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusAngle(EntryTangentSegment, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasTangentBearing) { try { pConstArc.ConstructTangentAngleChord(EntryTangentSegment, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasTangentBearing) { try { pConstArc.ConstructTangentChordArc(EntryTangentSegment, false, bCCW, dChord, dArcLength); } catch { }; } //radial bearing if (bHasRadialBearing) { //need to convert radial bearing to tangent bearing by adding/subtracting 90 degrees double dTanBear = 0; if (bCCW) dTanBear = dRadialBearing - (Angle_2_Radians("90", esriDirectionUnits.esriDUDecimalDegrees)); else dTanBear = dRadialBearing + (Angle_2_Radians("90", esriDirectionUnits.esriDUDecimalDegrees)); IConstructPoint2 pToPt = new PointClass(); pToPt.ConstructAngleDistance(pPt, dTanBear, 100); ILine EntryTangentLine = new LineClass(); EntryTangentLine.PutCoords(pPt, (IPoint)pToPt); EntryTangentSegment = (ISegment)EntryTangentLine; } if (bHasRadius && bHasChord && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusChord(EntryTangentSegment, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusArc(EntryTangentSegment, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusAngle(EntryTangentSegment, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasRadialBearing) { try { pConstArc.ConstructTangentAngleChord(EntryTangentSegment, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasRadialBearing) { try { pConstArc.ConstructTangentChordArc(EntryTangentSegment, false, bCCW, dChord, dArcLength); } catch { }; } } else { //tangent curve if (bHasRadius && bHasChord) { try { pConstArc.ConstructTangentRadiusChord(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc) { try { pConstArc.ConstructTangentRadiusArc(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta) { try { pConstArc.ConstructTangentRadiusAngle(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta) { try { pConstArc.ConstructTangentAngleChord(ExitTangentFromPreviousCourse, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc) { try { pConstArc.ConstructTangentChordArc(ExitTangentFromPreviousCourse, false, bCCW, dChord, dArcLength); } catch { }; } } ILine pLine = new LineClass(); try { pLine.PutCoords(pArc.FromPoint, pArc.ToPoint); } catch { outChordLength = -1; outChordBearing = -1; return null; } outChordLength = pLine.Length; outChordBearing = pLine.Angle; return pArc; }