Exemplo n.º 1
0
        public static int ThinPolyline3D(IPointCollection ipointCollection_0)
        {
            int num   = -1;
            int index = 0;
            int num2  = -1;
            int num3  = 0;

            while (ipointCollection_0.PointCount != num2)
            {
                num2 = ipointCollection_0.PointCount;
                ISegmentCollection segmentCollection = ipointCollection_0 as ISegmentCollection;
                IEnumSegment       enumSegments      = segmentCollection.EnumSegments;
                enumSegments.Reset();
                ISegment segment;
                enumSegments.Next(out segment, ref num, ref index);
                ISegment segment2;
                enumSegments.Next(out segment2, ref num, ref index);
                while (segment2 != null)
                {
                    int num4 = segment.ReturnTurnDirection(segment2);
                    if (num4 == 1)
                    {
                        ipointCollection_0.RemovePoints(index, 1);
                    }
                    segment = segment2;
                    enumSegments.Next(out segment2, ref num, ref index);
                }
                num3++;
            }
            return(num3);
        }
Exemplo n.º 2
0
 public SegmentCollectionLengthProvider([NotNull] ISegmentCollection segments, bool is3D)
     : base(is3D)
 {
     _segments     = segments;
     _enumSegments = segments.EnumSegments;
     _isRecycling  = _enumSegments.IsRecycling;
 }
Exemplo n.º 3
0
        private IPolygon polylinetoPolygon(IPolyline pPolyline)
        {
            IPointCollection pPtC;

            ESRI.ArcGIS.Geometry.IPoint pPt0, pPtn;
            ESRI.ArcGIS.Geometry.ILine  pSeg = new LineClass();

            IPolygon           polygon           = new PolygonClass();
            ISegmentCollection segmentCollection = (ISegmentCollection)pPolyline;
            int segmentCount = segmentCollection.SegmentCount;
            ISegmentCollection segmentCollection2 = (ISegmentCollection)polygon;
            object             value  = Missing.Value;
            object             value2 = Missing.Value;

            for (int i = 0; i < segmentCount; i++)
            {
                segmentCollection2.AddSegment(segmentCollection.get_Segment(i), ref value, ref value2);
            }
            if (!pPolyline.IsClosed)
            {
                pPtC            = pPolyline as IPointCollection;
                pPt0            = pPtC.get_Point(0);
                polygon.ToPoint = pPt0;
                //pPtn = pPtC.get_Point(pPtC.PointCount - 1);
                //pSeg.PutCoords(pPtn, pPt0);
                //segmentCollection2.AddSegment((ISegment)pSeg, ref value, ref value2);
            }

            polygon.SimplifyPreserveFromTo();
            return(polygon);
        }
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                IPolyline chain_geom = new PolylineClass();

                ISegmentCollection path1 = new PathClass();

                foreach (Range r in Errors.CenterlineChains[select_chain_name])
                {
                    ISegmentCollection segcoll = r.Shape as ISegmentCollection;
                    path1.AddSegmentCollection(segcoll);
                }

                object obj = Type.Missing;

                IGeometryCollection gCollection = chain_geom as IGeometryCollection;

                gCollection.AddGeometry((IGeometry)path1, obj, obj);

                chain_geom = (IPolyline)gCollection;

                FlashGeometry(chain_geom);
            }
            catch { }
        }
Exemplo n.º 5
0
        public override void OnMouseMove(int Button, int shift, int X, int Y)
        {
            //Determine tangent to last segment on edit sketch
            //Set as angle constraint +90

            ISegmentCollection pSc = m_EdSketch.Geometry as ISegmentCollection;

            if (pSc.SegmentCount > 0)
            {
                ICurve3 pCurve;
                if (m_EdSketch.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    pCurve = pSc.get_Segment(pSc.SegmentCount - 2) as ICurve3;
                }
                else
                {
                    pCurve = pSc.get_Segment(pSc.SegmentCount - 1) as ICurve3;
                }

                ILine pLine = new Line();
                pCurve.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 1, true, 10, pLine);

                base.AngleConstraint = pLine.Angle + (90 * Math.PI / 180);
                base.Constraint      = esriSketchConstraint.esriConstraintAngle;
            }
            base.OnMouseMove(Button, shift, X, Y);
        }
Exemplo n.º 6
0
        }//获取夹角的辅助

        private double AngleToPoint(IGeometry pGeometry)
        {
            double             pAngle       = 0;
            ISegmentCollection pSC          = pGeometry as ISegmentCollection;//可能用到的东西:FromPoint、ToPoint、EnumCurve、EnumSegments---IEnumSegment
            IEnumSegment       pEnumSegment = pSC.EnumSegments;

            pEnumSegment.Reset();
            ISegment pSegment;
            int      partIndex    = 0;
            int      segmentIndex = 0;

            pEnumSegment.Next(out pSegment, ref partIndex, ref segmentIndex);
            int i = 0;

            while (!pEnumSegment.IsLastInPart())
            {
                pEnumSegment.SetAt(0, i);
                pEnumSegment.Next(out pSegment, ref partIndex, ref segmentIndex);
                i++;
            }
            pEnumSegment.SetAt(0, i - 1);
            pEnumSegment.Next(out pSegment, ref partIndex, ref segmentIndex);
            ILine  pLine = pSegment as ILine;
            double a     = pLine.Angle;

            if (a > 0 && a <= Math.PI)
            {
                pAngle = a - Math.PI;
            }
            if (a > -Math.PI && a <= 0)
            {
                pAngle = a + Math.PI;
            }
            return(pAngle);
        }//获取夹角的辅助
Exemplo n.º 7
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            m_ActiveView = m_hookHelper.ActiveView;
            m_Map        = m_hookHelper.FocusMap;
            IScreenDisplay    pScreenDisplay = m_ActiveView.ScreenDisplay;
            IRubberBand       pRubberCircle  = new RubberCircleClass();
            ISimpleFillSymbol pFillSymbol    = new SimpleFillSymbolClass();

            pFillSymbol.Color = getRGB(255, 255, 0);
            IGeometry pCircle = pRubberCircle.TrackNew(pScreenDisplay, (ISymbol)pFillSymbol) as IGeometry;

            IConstructCircularArc pConstructArc   = pCircle as IConstructCircularArc;
            IPolygon           pPolygon           = new PolygonClass();
            ISegmentCollection pSegmentCollection = pPolygon as ISegmentCollection;
            ISegment           pSegment           = pConstructArc as ISegment;
            object             missing            = Type.Missing;

            pSegmentCollection.AddSegment(pSegment, ref missing, ref missing);
            pFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross;
            pFillSymbol.Color = getRGB(255, 0, 0);
            IFillShapeElement pPolygonEle = new PolygonElementClass();

            pPolygonEle.Symbol = pFillSymbol;
            IElement pEle = pPolygonEle as IElement;

            pEle.Geometry = pPolygon;
            IGraphicsContainer pGraphicsContainer = m_Map as IGraphicsContainer;

            pGraphicsContainer.AddElement(pEle, 0);
            m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Exemplo n.º 8
0
        public SegmentSearcher([NotNull] ISegmentCollection segments, bool releaseOnDispose)
        {
            Assert.ArgumentNotNull(segments, nameof(segments));

            _segments         = segments;
            _releaseOnDispose = releaseOnDispose;
        }
Exemplo n.º 9
0
        public ISegmentProxy GetPreviousSegment([NotNull] IGeometry geometry)
        {
            int index = SegmentIndex - 1;

            var geomColl = geometry as IGeometryCollection;
            ISegmentCollection segColl = geomColl == null
                                                             ? (ISegmentCollection)geometry
                                                             : (ISegmentCollection)
                                         geomColl.Geometry[PartIndex];
            var path = (IPath)segColl;

            if (index < 0)
            {
                if (!path.IsClosed)
                {
                    return(null);
                }

                index = segColl.SegmentCount - 1;
            }

            var previousSegment = new DummySegmentProxy(PartIndex, index);

            return(previousSegment);
        }
Exemplo n.º 10
0
 /// <summary>
 /// 绘制矩形
 /// </summary>
 /// <params name="pLayer"></params>
 /// <params name="pScreenDisplay"></params>
 private void DrawRectangular(ILayer pLayer, IGeometry pGeo)
 {
     if (pLayer != null)
     {
         ISegmentCollection pSegmentCollection = null;
         if (pLayer is IFeatureLayer)
         {
             IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
             IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
             if (pFeatureClass != null)
             {
                 if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                 {
                     pSegmentCollection = new PolylineClass();
                 }
                 else if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                 {
                     pSegmentCollection = new PolygonClass();
                 }
                 pSegmentCollection.SetRectangle(pGeo.Envelope);
                 IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(pFeatureLayer, (IGeometry)pSegmentCollection);
                 m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature);
                 m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null);
             }
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>Gets the end point of a turn edge</summary>
        /// <remarks>
        /// - The Via node of a turn is assumed to be at the From or To point of the edge
        /// </remarks>
        private static IPoint GetTurnEndpoint(IPolyline line, IPoint ptVia, out bool edgeEndAtToPoint, out double position)
        {
            IPoint point = null;

            edgeEndAtToPoint = false;
            position         = 0.0;

            if ((ptVia.X == line.FromPoint.X) && (ptVia.Y == line.FromPoint.Y))
            {
                point = ((IPointCollection)line).get_Point(1);
                ISegment segment = ((ISegmentCollection)line).get_Segment(0);
                position = segment.Length / line.Length;
            }
            else
            {
                edgeEndAtToPoint = true;

                IPointCollection pc = (IPointCollection)line;
                point = pc.get_Point(pc.PointCount - 2);

                ISegmentCollection sc      = line as ISegmentCollection;
                ISegment           segment = sc.get_Segment(sc.SegmentCount - 1);

                position = (line.Length - segment.Length) / line.Length;
            }

            return(point);
        }
Exemplo n.º 12
0
        private void DrawCircleByCenterAndRadius(ILayer pLayer, ICircularArc pCircularArc, IScreenDisplay pScreenDisplay)
        {
            object o = Type.Missing;

            if (pLayer != null)
            {
                ISegmentCollection pSegmentCollection = null;
                pSegmentCollection = new PathClass();
                if (pLayer is IFeatureLayer)
                {
                    IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                    if (pFeatureClass != null)
                    {
                        ISegment pSegment = pCircularArc as ISegment;
                        pSegmentCollection.AddSegment(pSegment, ref o, ref o);
                        IGeometryCollection pPolyline = new PolylineClass();
                        //通过IGeometryCollection为Polyline对象添加Path对象
                        pPolyline.AddGeometry(pSegmentCollection as IGeometry, ref o, ref o);
                        IFeature pCircleFeature = pFeatureClass.CreateFeature();
                        pCircleFeature.Shape = pPolyline as PolylineClass;
                        pCircleFeature.Store();

                        //局部刷新
                        IInvalidArea pInvalidArea = new InvalidAreaClass();
                        pInvalidArea.Add(pCircularArc);
                        pInvalidArea.Display = pScreenDisplay;
                        pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);

                        //20140410 lyf
                        m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
                    }
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 根据圆心和半径绘制圆
        /// </summary>
        /// <params name="pLayer"></params>
        /// <params name="pPoint"></params>
        /// <params name="circleRadius"></params>
        /// <params name="pScreenDisplay"></params>
        private void DrawCircleByCenterAndRadius(ILayer pLayer, IPoint pPoint, double circleRadius, IScreenDisplay pScreenDisplay)
        {
            if (pLayer != null)
            {
                ISegmentCollection pSegmentCollection = null;
                if (pLayer is IFeatureLayer)
                {
                    IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                    if (pFeatureClass != null)
                    {
                        if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                        {
                            pSegmentCollection = new PolylineClass();
                        }
                        else if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            pSegmentCollection = new PolygonClass();
                        }
                        //开始画圆
                        pSegmentCollection.SetCircle(pPoint, circleRadius);

                        IFeature pCircleFeature = pFeatureClass.CreateFeature();
                        pCircleFeature.Shape = pSegmentCollection as IGeometry;
                        pCircleFeature.Store();
                        //局部刷新
                        IInvalidArea pInvalidArea = new InvalidAreaClass();
                        pInvalidArea.Add(pSegmentCollection);
                        pInvalidArea.Display = pScreenDisplay;
                        pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);
                    }
                }
            }
        }
Exemplo n.º 14
0
 //根据线的方向获取其更新的位置
 private void GetFromPointMovepointChangeLocation(IPolyline line, double distance, ref IPoint point, ref IPolyline retureline)
 {
     try
     {
         IPolyline[] pLines     = new IPolyline[2];
         IPolyline   pSplitLine = new PolylineClass();
         pSplitLine = line;
         IPolyline StarttoPointLine = new PolylineClass();
         IPolyline EndtoPointLine   = new PolylineClass();
         bool      splithappened;
         int       partindex, segmentindex;
         object    pObject = Type.Missing;
         pSplitLine.SplitAtDistance(distance, false, false, out splithappened, out partindex, out segmentindex);
         ISegmentCollection lineSegCol  = pSplitLine as ISegmentCollection;
         ISegmentCollection startSegCol = StarttoPointLine as ISegmentCollection;
         ISegmentCollection endSegCol   = EndtoPointLine as ISegmentCollection;
         for (int i = 0; i < segmentindex; i++)
         {
             startSegCol.AddSegment(lineSegCol.get_Segment(i), ref pObject, ref pObject);
         }
         for (int j = segmentindex; j < lineSegCol.SegmentCount; j++)
         {
             endSegCol.AddSegment(lineSegCol.get_Segment(j), ref pObject, ref pObject);
         }
         pLines[0]  = endSegCol as IPolyline;
         pLines[1]  = startSegCol as IPolyline;
         point      = new PointClass();
         point      = pLines[0].FromPoint;
         retureline = pLines[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "/n" + ex.ToString(), "异常");
     }
 }
Exemplo n.º 15
0
 public SegmentCollectionMeanLengthProvider(ISegmentCollection segments,
                                            bool perPart, bool is3D)
 {
     _segments = segments;
     _perPart  = perPart;
     _is3D     = is3D;
 }
Exemplo n.º 16
0
 private int ReportCorruptNonLinearSegments([NotNull] ISegmentCollection segments,
                                            [NotNull] IRow row)
 {
     return(!HasNonLinearSegments(segments)
                                ? NoError
                                : GetSegments(segments).Sum(segment => CheckSegment(segment, row)));
 }
Exemplo n.º 17
0
        public IPolyline ScaleRaai(ref IPolyline Raai)
        {
            ISegmentCollection Segments       = Raai as ISegmentCollection;
            IEnumSegment       enumSegment    = Segments.EnumSegments;
            ISegment           Segment        = null;
            ISegment           LangsteSegment = null;

            int outPartIndex = 0;
            int SegmentIndex = 0;

            enumSegment.Next(out Segment, ref outPartIndex, ref SegmentIndex);
            LangsteSegment = Segment;

            while (Segment != null)
            {
                if (Segment.Length >= LangsteSegment.Length)
                {
                    LangsteSegment = (Segment as IClone).Clone() as ISegment;
                }
                enumSegment.Next(out Segment, ref outPartIndex, ref SegmentIndex);
            }

            IConstructLine line = new Line() as IConstructLine;

            line.ConstructExtended(LangsteSegment as ILine, esriSegmentExtension.esriExtendEmbedded);

            Raai = new Polyline() as IPolyline;
            (Raai as IPointCollection).AddPoint((line as ILine).FromPoint);
            (Raai as IPointCollection).AddPoint((line as ILine).ToPoint);

            return(Raai);
        }
        private static ICollection <int> GetShortSegmentIndexes(
            [NotNull] ISegmentCollection segments, double minSegmentLength)
        {
            var indexes = new List <int>();

            var        index          = 0;
            const bool allowRecycling = true;

            foreach (
                ISegment segment in
                GeometryUtils.GetSegments(segments.EnumSegments, allowRecycling, null))
            {
                if (segment.Length < minSegmentLength)
                {
                    indexes.Add(index);
                }

                index++;
            }

            const int maxArraySize = 5;

            return(indexes.Count <= maxArraySize
                                       ? (ICollection <int>)indexes.ToArray()
                                       : new HashSet <int>(indexes));
        }
Exemplo n.º 19
0
        /// <summary>
        /// 角度同步,点与线的角度同步
        /// </summary>
        /// <param name="pPolyline">线</param>
        /// <param name="pPoint">线附近的点(许可的范围内)</param>
        /// <param name="dAngle">返回点符号的角度</param>
        /// <param name="pRetPoint">返回的在线上的点的位置</param>
        /// <returns>是否可以同步角度(如果距离过大,无法执行角度同步)</returns>
        public static bool SynchronizeAngle(IPolyline pPolyline, IPoint pPoint, ref double dAngle, ref IPoint pRetPoint)
        {
            double   dRadius         = 10;
            IPoint   pHitPoint       = new PointClass();
            IHitTest pHitTest        = pPolyline as IHitTest;
            double   hitDist         = 0.0;
            int      hitPartIndex    = 0;
            int      hitSegmentIndex = 0;
            bool     bRightSide      = false;

            bool bPointOnLine = pHitTest.HitTest(pPoint, dRadius, esriGeometryHitPartType.esriGeometryPartBoundary, pHitPoint, ref hitDist, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);

            if (bPointOnLine)
            {
                if (distance(pHitPoint, pPoint) < 0.0001)
                {
                    pRetPoint = null;
                }
                else
                {
                    pRetPoint = pHitPoint;
                }

                ISegmentCollection pSegment = pPolyline as ISegmentCollection;
                ILine pLine = pSegment.get_Segment(hitSegmentIndex) as ILine;
                dAngle = pLine.Angle;
                return(true);
            }
            return(false);
        }
Exemplo n.º 20
0
        /// <summary>
        /// 获取线起点
        /// </summary>
        /// <param name="pLine"></param>
        /// <returns></returns>
        public static IPoint GetStartPoint(IPolyline pLine)
        {
            IPoint pStartPoint = null;

            try
            {
                if (pLine == null)
                {
                    return(pStartPoint);
                }
                ISegmentCollection pLines = pLine as ISegmentCollection;
                if (pLines.SegmentCount == 0)
                {
                    return(pStartPoint);
                }
                ILine pStarLine = pLines.get_Segment(0) as ILine;
                if (pStarLine == null)
                {
                    return(pStartPoint);
                }
                pStartPoint = pStarLine.FromPoint;
                return(pStartPoint);
            }
            catch (Exception ex)
            {
                return(pStartPoint);
            }
        }
Exemplo n.º 21
0
 //根据第一应急处置空间位置点,将即将污染的河流切割成两段
 public IPolyline GetPointSplitAtPoint(IPolyline InputLine, IPoint point)
 {
     try
     {
         IPolyline[] pLines     = new IPolyline[2];
         IPolyline   pSplitLine = new PolylineClass();
         pSplitLine = InputLine;
         IPolyline StarttoPointLine = new PolylineClass();
         IPolyline EndtoPointLine = new PolylineClass();
         bool      projectOnto = true, createPart = false;
         bool      SplitHappened;
         int       partindex, segmentindex;
         object    pObject = Type.Missing;
         pSplitLine.SplitAtPoint(point, projectOnto, createPart, out SplitHappened, out partindex, out segmentindex);
         ISegmentCollection lineSegCol  = pSplitLine as ISegmentCollection;
         ISegmentCollection startSegCol = StarttoPointLine as ISegmentCollection;
         ISegmentCollection endSegCol   = EndtoPointLine as ISegmentCollection;
         for (int i = 0; i < segmentindex; i++)
         {
             startSegCol.AddSegment(lineSegCol.get_Segment(i), ref pObject, ref pObject);
         }
         for (int j = segmentindex; j < lineSegCol.SegmentCount; j++)
         {
             endSegCol.AddSegment(lineSegCol.get_Segment(j), ref pObject, ref pObject);
         }
         pLines[0] = endSegCol as IPolyline;
         pLines[1] = startSegCol as IPolyline;
         return(pLines[0]);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
         return(null);
     }
 }
Exemplo n.º 22
0
        public static SegmentCounts GetSegmentCounts(
            [NotNull] ISegmentCollection segmentCollection)
        {
            var result = new SegmentCounts();

            foreach (ISegment segment in
                     GeometryUtils.GetSegments(segmentCollection.EnumSegments,
                                               allowRecycling: true))
            {
                switch (segment.GeometryType)
                {
                case esriGeometryType.esriGeometryLine:
                    result.LinearSegmentCount++;
                    break;

                case esriGeometryType.esriGeometryCircularArc:
                    result.CircularArcCount++;
                    break;

                case esriGeometryType.esriGeometryEllipticArc:
                    result.EllipticArcCount++;
                    break;

                case esriGeometryType.esriGeometryBezier3Curve:
                    result.BezierCount++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                              $"Unexpected segment geometry type: {segment.GeometryType}");
                }
            }

            return(result);
        }
Exemplo n.º 23
0
        public static GeoAPI.Geometries.ILinearRing ConvertTo(ESRI.ArcGIS.Geometry.IRing ring)
        {
            ESRI.ArcGIS.Geometry.IPoint          fromToPoint = ring.FromPoint;
            List <GeoAPI.Geometries.ICoordinate> list        = new List <GeoAPI.Geometries.ICoordinate>();

            list.Add(ConvertTo(fromToPoint));
            ISegmentCollection segmentCollection = ring as ISegmentCollection;

            if (segmentCollection != null)
            {
                int count = segmentCollection.SegmentCount;
                for (int i = 0; i < count; i++)
                {
                    ISegment segment = segmentCollection.get_Segment(i);
                    if (!(segment is ILine))
                    {
                        throw new ApplicationException("Curves are not supported.");
                    }
                    list.Add(ConvertTo(segment.ToPoint));
                }
            }
            else
            {
                throw new ApplicationException("No segments found in the ring geometry.");
            }

            list.Add(ConvertTo(fromToPoint));
            list.Reverse();
            return(new GisSharpBlog.NetTopologySuite.Geometries.LinearRing(list.ToArray()));
        }
        private void UpdateFeature(IFeature selectedFeature, ISegmentCollection polylineSegments)
        {
            ISegmentCollection polyline = new PolylineClass();

            polyline.AddSegmentCollection(polylineSegments);
            IFeatureClass  featureClass  = selectedFeature.Class as IFeatureClass;
            IDataset       dataset       = featureClass as IDataset;
            IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit;

            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }

            try
            {
                workspaceEdit.StartEditOperation();
                selectedFeature.Shape = polyline as IGeometry;
                selectedFeature.Store();
                workspaceEdit.StopEditOperation();
            }
            catch (Exception ex)
            {
                workspaceEdit.AbortEditOperation();
                MessageBox.Show("移动线段失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 25
0
        private esriFlowDirection method_7(IGeometry geometry)
        {
            ISegmentCollection segmentCollection = (ISegmentCollection)geometry;
            ISegmentZ          segmentZ          = (ISegmentZ)segmentCollection.get_Segment(0);
            ISegmentZ          segmentZ2         = (ISegmentZ)segmentCollection.get_Segment(-1);
            double             num;
            double             num2;

            segmentZ.GetZs(out num, out num2);
            double num3;

            segmentZ2.GetZs(out num2, out num3);
            esriFlowDirection result;

            if (num > num3)
            {
                result = (esriFlowDirection)1;
            }
            else if (num < num3)
            {
                result = (esriFlowDirection)2;
            }
            else
            {
                result = (esriFlowDirection)3;
            }
            return(result);
        }
Exemplo n.º 26
0
        public override void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            if (Button != 1 || m_pFeature == null || m_pVertexFeed == null || m_HitSegmentIndex == -1)
            {
                return;
            }

            IPoint pPnt = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            //如果开启捕捉则以捕捉到的点为准
            if (MoData.v_bSnapStart && m_pSnapPoint != null)
            {
                pPnt = m_pSnapPoint;
            }

            ISegmentCollection pSegmentCollection = m_pFeature.Shape as ISegmentCollection;


            //检查是否点击第一点
            if (m_HitSegmentIndex == 0)
            {
                //如果是第一点且是Polygon,更新最后一段
                if (m_pFeature.Shape is IPolygon)
                {
                    pPnt.Z = pSegmentCollection.get_Segment(pSegmentCollection.SegmentCount - 1).ToPoint.Z;
                    pSegmentCollection.get_Segment(pSegmentCollection.SegmentCount - 1).ToPoint = pPnt;
                }
            }
            else
            {
                //如果不是第一点,更新上一段(FromPoint as anchor)
                pPnt.Z = pSegmentCollection.get_Segment(m_HitSegmentIndex - 1).ToPoint.Z;
                pSegmentCollection.get_Segment(m_HitSegmentIndex - 1).ToPoint = pPnt;
            }

            //检查是否点击最后一个节点
            if (m_HitSegmentIndex == pSegmentCollection.SegmentCount)
            {
                //如果是点击最后一个节点,并且是polygon,更新第一段
                if (m_pFeature.Shape is IPolygon)
                {
                    pPnt.Z = pSegmentCollection.get_Segment(0).FromPoint.Z;
                    pSegmentCollection.get_Segment(0).FromPoint = pPnt;
                }
            }
            else
            {
                //如果不是最后一个节点,更新下一段(ToPoint as anchor)
                pPnt.Z = pSegmentCollection.get_Segment(m_HitSegmentIndex).FromPoint.Z;
                pSegmentCollection.get_Segment(m_HitSegmentIndex).FromPoint = pPnt;
            }

            StoreFeature(m_pFeature, pSegmentCollection, MoData.v_CurWorkspaceEdit);

            m_MapControl.ActiveView.Refresh();
            m_pVertexFeed     = null;
            m_bMouseDown      = false;
            m_HitSegmentIndex = 0;
        }
Exemplo n.º 27
0
        //存储Feature
        private void StoreFeature(IFeature pFeature, ISegmentCollection pSegcol, IWorkspaceEdit pCurWorkspaceEdit)
        {
            pCurWorkspaceEdit.StartEditOperation();

            pFeature.Shape = pSegcol as IGeometry;
            pFeature.Store();
            pCurWorkspaceEdit.StopEditOperation();
        }
Exemplo n.º 28
0
            public TangentAngleProvider([NotNull] ISegmentCollection segments,
                                        [NotNull] Settings settings)
                : base(settings)
            {
                Assert.ArgumentNotNull(segments, nameof(segments));

                _segments = segments;
            }
Exemplo n.º 29
0
 public PropertyCache([CanBeNull] IGeometry geometry)
 {
     _geometry = geometry;
     _segments = geometry as ISegmentCollection;
     _isEmpty  = geometry == null || geometry.IsEmpty;
     _zAware   = geometry != null && GeometryUtils.IsZAware(geometry);
     _mAware   = geometry != null && GeometryUtils.IsMAware(geometry);
 }
        private double GetAngle(ICurve curvePath)
        {
            IPolyline          pPoly = (IPolyline)curvePath;
            ISegmentCollection pSG   = pPoly as ISegmentCollection;
            ILine pLine = pSG.get_Segment(0) as ILine;

            return(Math.Round((180 * pLine.Angle) / Math.PI, 3));
        }
Exemplo n.º 31
0
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            _absX = arg.X;
            _absY = arg.Y;
            if (arg.Button == MouseButtons.Left)
            {
                _constrainedAngle = 0;
                _constrainedDistance = 0;

                if (_currentTargetLayer != null)
                {
                    if (ArcMap.Document.ActiveView.ScreenDisplay != null)
                    {
                        IPoint anchor = ArcMap.Document.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
                        GISApplication.SnapPoint(anchor);

                        if (_currentTargetLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                        {
                            _initialAnchorPoint = null;
                            try
                            {
                                if (_moveDeviceAlongLineOnInsert)
                                {
                                    if (!arg.Control)
                                    {
                                        //get connected section which is longer
                                        IFeature nearestEdge = null;// GetNearestEdge(anchor, null, new List<string>() { "PrimaryConductor" });// NetworkAnalysis.GetEdgeNearestToPoint(((INetworkClass)_currentTargetLayer.FeatureClass).GeometricNetwork, ArcMap.Document.FocusMap, anchor);
                                        if (nearestEdge != null)
                                        {
                                            if (nearestEdge.Shape is IPolyline)
                                            {
                                                bool rightSide = false;
                                                double distanceAlongCurve = 0, distanceFromCurve = 0;

                                                IPoint outPoint = new PointClass();
                                                IPolyline pLine = nearestEdge.Shape as IPolyline;
                                                pLine.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, anchor, true, outPoint, ref distanceAlongCurve, ref distanceFromCurve, ref rightSide);

                                                bool asRatio = false;
                                                IPoint newAnchor = new PointClass();
                                                double distanceToMoveAlongCurve = 30;// (double)UserDefinedElectricSettings.PrimaryDeviceInsertionOffset;//TODO.configurable

                                                if (pLine.Length < 10) //TODO.configurable
                                                {
                                                    MessageBox.Show("The line you are trying to split is shorter than the " + Environment.NewLine + "[MinimumLineSplitDistanceForPrimaryDevices] setting value of 10", "Invalid Operation.", MessageBoxButtons.OK);
                                                    return;
                                                }

                                                if (pLine.Length <= (distanceToMoveAlongCurve + 1))
                                                {
                                                    distanceToMoveAlongCurve = .3;
                                                    asRatio = true;
                                                }

                                                if (distanceAlongCurve <= .5)
                                                    pLine.QueryPoint(esriSegmentExtension.esriNoExtension, distanceToMoveAlongCurve, asRatio, newAnchor);
                                                else if (distanceAlongCurve > .5)
                                                {
                                                    if (asRatio)
                                                        distanceToMoveAlongCurve = 1 - distanceToMoveAlongCurve;
                                                    else
                                                        distanceToMoveAlongCurve = pLine.Length - distanceToMoveAlongCurve;
                                                    pLine.QueryPoint(esriSegmentExtension.esriNoExtension, distanceToMoveAlongCurve, asRatio, newAnchor);
                                                }

                                                if (DisplayMap.IsGeometryValid(newAnchor))
                                                {
                                                    //Center on the insertion point if it is outside the visible extent.
                                                    if (DisplayMap.IsPointInExtent(newAnchor, ArcMap.Document.ActiveView.Extent) == false)
                                                        DisplayMap.ZoomToPoint(ArcMap.Document.ActiveView, newAnchor);
                                                    anchor = newAnchor;
                                                    _movePointFeedback.MoveTo(anchor);
                                                }
                                            }
                                        }
                                    }
                                }
                                CreateFeature(anchor);
                            }
                            catch(Exception ex)
                            {
                                DeactivateCurrentTool();
                            }
                        }
                        else
                        {
                            if (!_insertionFeedbackInUse)
                            {
                                _segmentCollection = new PolylineClass();
                                _segmentAnchorPoint = null;

                                if (_currentTargetLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                                {
                                    _insertionFeedbackInUse = true;
                                    _insertionFeedback = new NewLineFeedbackClass();
                                    INewLineFeedback lineEditFeedback = (INewLineFeedback)_insertionFeedback;
                                    lineEditFeedback.Start(anchor);
                                    _initialAnchorPoint = anchor;

                                }
                                else if (_currentTargetLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                                {
                                    _insertionFeedbackInUse = true;
                                    _insertionFeedback = new NewLineFeedbackClass();
                                    INewPolygonFeedback polygonEditFeedback = (INewPolygonFeedback)_insertionFeedback;
                                    polygonEditFeedback.Start(anchor);
                                }
                                if (_insertionFeedback != null)
                                    _insertionFeedback.Display = ArcMap.Document.ActiveView.ScreenDisplay;
                            }
                            else//LINES
                            {
                                if (_constrainedAnchor != null)
                                    ProcessSegment(_constrainedAnchor);
                                else
                                    ProcessSegment(anchor);
                            }
                        }
                        anchor.SnapToSpatialReference();
                    }
                }
            }
            else //if (_insertionFeedbackInUse)
                DisplayContextMenu(_currentTargetLayer.FeatureClass.ShapeType);
        }