Example #1
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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        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);
        }
Example #4
0
        public static ICircularArc ConstructCircle(IPoint centerPoint, double radius)
        {
            ICircularArc          circularArc          = new CircularArcClass();
            IConstructCircularArc constructCircluarArc = circularArc as IConstructCircularArc;

            constructCircluarArc.ConstructCircle(centerPoint, radius, true);
            return(circularArc);
        }
Example #5
0
        private void CreateFeature(IGeometry pGeom)
        {
            IWorkspaceEdit        pWorkspaceEdit  = GetWorkspaceEdit();
            IFeatureLayer         pFeatureLayer   = (IFeatureLayer)m_pCurrentLayer;
            IFeatureClass         pFeatureClass   = pFeatureLayer.FeatureClass;
            IConstructCircularArc pConstructArc   = pGeom 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);
            pWorkspaceEdit.StartEditOperation();
            IFeature pFeature = pFeatureClass.CreateFeature();

            pFeature.Shape = pPolygon;

            pFeature.Store();
            pWorkspaceEdit.StopEditOperation();
            m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, m_pCurrentLayer, pGeom.Envelope);
        }
Example #6
0
        private void CreateFeature(IGeometry pGeom)
        {
            if (pGeom == null)
            {
                return;
            }
            if (m_pCurrentLayer == null)
            {
                return;
            }

            // Create the feature
            IWorkspaceEdit pWorkspaceEdit = GetWorkspaceEdit();
            IFeatureLayer  pFeatureLayer  = (IFeatureLayer)m_pCurrentLayer;
            IFeatureClass  pFeatureClass  = pFeatureLayer.FeatureClass;

            IConstructCircularArc pConstructArc   = pGeom 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);

            pWorkspaceEdit.StartEditOperation();
            IFeature pFeature = pFeatureClass.CreateFeature();

            try
            {
                pFeature.Shape = pPolygon;
            }
            catch (Exception ex)
            {
                MessageBox.Show("创建要素", ex.Message);
            }
            pFeature.Store();
            pWorkspaceEdit.StopEditOperation();

            m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, m_pCurrentLayer, pGeom.Envelope);
        }
Example #7
0
        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);
        }
Example #8
0
        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;
                    }
                }
            }
        }