public InsertionTool()
 {
     _movePointFeedback = new MovePointFeedbackClass();
     if (ArcMap.Document.ActiveView != null)
         _movePointFeedback.Display = ArcMap.Document.ActiveView.ScreenDisplay;
     _movePointFeedback.Symbol = Cartography.CreateInsertionSymbol();
 }
        public void FeatureMoveMouseDown(int x, int y)
        {
            if (MyselectedLayer == null)
            {
                return;
            }
            if ((MyselectedLayer as IGeoFeatureLayer) == null)
            {
                return;
            }

            IFeatureLayer featureLayer = MyselectedLayer as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;

            if (featureClass == null)
            {
                return;
            }

            if (MyselectedFeature.Count < 1)
            {
                return;
            }
            IFeature  feature   = MyselectedFeature[0];
            IGeometry startGeom = feature.Shape;

            IPoint point = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            try
            {
                switch (featureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    MyfeedBack         = new MovePointFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMovePointFeedback pointMoveFeedback = MyfeedBack as IMovePointFeedback;
                    pointMoveFeedback.Start(startGeom as IPoint, point);
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    MyfeedBack         = new MoveLineFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMoveLineFeedback lineMoveFeedback = MyfeedBack as IMoveLineFeedback;
                    lineMoveFeedback.Start(startGeom as IPolyline, point);
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    MyfeedBack         = new MovePolygonFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMovePolygonFeedback polygonMoveFeedback = MyfeedBack as IMovePolygonFeedback;
                    polygonMoveFeedback.Start(startGeom as IPolygon, point);
                    break;

                default:
                    break;
                }
            }
            catch { return; }
        }
Exemple #3
0
 public Form1()
 {
     ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
     ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Engine);
     currentPoint      = new PointClass();
     movePointFeedback = new MovePointFeedbackClass();
     InitializeComponent();
 }
Exemple #4
0
        private void axMapControl1_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
        {
            if (m_Feature == null)
            {
                return;
            }
            IGeometry resultGeometry = null;

            switch (strOperator)
            {
            case "move":
                if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                {
                    //停止移动
                    resultGeometry  = m_MovePointFeedback.Stop() as IGeometry;
                    m_Feature.Shape = resultGeometry;
                }
                else if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                {
                    //停止移动
                    resultGeometry  = m_MoveLineFeedback.Stop() as IGeometry;
                    m_Feature.Shape = resultGeometry;
                }
                else if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    //停止移动
                    resultGeometry  = m_MovePolygonFeedback.Stop() as IGeometry;
                    m_Feature.Shape = resultGeometry;
                }
                IWorkspaceEdit workspaceEdit;
                IWorkspace     workspace;
                IDataset       dataset = m_FeatureLayer.FeatureClass as IDataset;
                workspace     = dataset.Workspace;
                workspaceEdit = workspace as IWorkspaceEdit;
                //开始编辑
                workspaceEdit.StartEditing(true);
                workspaceEdit.StartEditOperation();
                //保存实体
                m_Feature.Store();
                //结束编辑
                workspaceEdit.StopEditOperation();
                workspaceEdit.StopEditing(true);
                m_MovePointFeedback   = null;
                m_MoveLineFeedback    = null;
                m_MovePolygonFeedback = null;
                break;
            }
            m_activeView.Refresh();
            this.axMapControl1.Map.ClearSelection();
        }
Exemple #5
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ModifyShape.OnMouseDown implementation

            m_MapControl.Map.ClearSelection();
            m_MapControl.ActiveView.Refresh();
            SelectMouseDown(X, Y);
            IEnumFeature pSelected = (IEnumFeature)m_MapControl.Map.FeatureSelection;
            IFeature     pFeature  = pSelected.Next();

            if (pFeature == null)
            {
                return;
            }
            IActiveView pActiveView = m_MapControl.ActiveView;
            IPoint      pPoint      = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            //设置捕捉容差
            double       tol          = ConvertPixelsToMapUnits(pActiveView, 4);
            IGeometry    pGeom        = pFeature.Shape;
            IObjectClass pObjectClass = pFeature.Class;

            m_EditFeature = pFeature;

            switch (pGeom.GeometryType)
            {
            case esriGeometryType.esriGeometryPoint:
                m_Feedback         = new MovePointFeedbackClass();
                m_Feedback.Display = pActiveView.ScreenDisplay;
                IMovePointFeedback pPointMove = (IMovePointFeedback)m_Feedback;
                pPointMove.Start((IPoint)pGeom, pPoint);
                break;

            case esriGeometryType.esriGeometryPolyline:
                m_Feedback         = new MoveLineFeedbackClass();
                m_Feedback.Display = pActiveView.ScreenDisplay;
                IMoveLineFeedback m_MoveLineFeedback = (IMoveLineFeedback)m_Feedback;
                m_MoveLineFeedback.Start((IPolyline)pGeom, pPoint);
                break;

            case esriGeometryType.esriGeometryPolygon:
                m_Feedback         = new MovePolygonFeedbackClass();
                m_Feedback.Display = pActiveView.ScreenDisplay;
                IMovePolygonFeedback m_MovePolygonFeedback = (IMovePolygonFeedback)m_Feedback;
                m_MovePolygonFeedback.Start((IPolygon)pGeom, pPoint);
                break;
            }
        }
Exemple #6
0
        /// <summary>
        /// 完成地图对象编辑,取得编辑后的对象,并将其更新到图层中
        /// 建议在Map.MouseUp事件中调用本方法
        /// </summary>
        public void EditFeatureEnd()
        {
            IGeometry pGeometry;

            try
            {
                if (m_pFeedback == null)
                {
                    return;
                }

                if (m_pFeedback is IMovePointFeedback)
                {
                    IMovePointFeedback pPointMove = (IMovePointFeedback)m_pFeedback;
                    pGeometry = pPointMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is ILineMovePointFeedback)
                {
                    ILineMovePointFeedback pLineMove = (ILineMovePointFeedback)m_pFeedback;
                    pGeometry = pLineMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is IPolygonMovePointFeedback)
                {
                    IPolygonMovePointFeedback pPolyMove = (IPolygonMovePointFeedback)m_pFeedback;
                    pGeometry = pPolyMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }

                m_pFeedback = null;
//				m_pSelectionTracker = null;
                IActiveView pActiveView = (IActiveView)m_pMap;
                pActiveView.Refresh();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
Exemple #7
0
 //snap功能开关
 private void miStartSnap_Click(object sender, EventArgs e)
 {
     //打开开关并初始化成员变量
     if (!miStartSnap.Checked)
     {
         miStartSnap.Checked = true;
         m_element_snap      = null;                         //当前鼠标点
         m_currentPoint      = new PointClass();             //捕捉到得点
         m_snapPoint         = null;                         //移动点反馈对象
         m_movePointFeedback = new MovePointFeedbackClass(); //捕捉图层
         m_flag = 0;
     }
     else//关闭开关并删除GraphicsContainer中的element
     {
         miStartSnap.Checked = false;
         if (m_flag != 0)
         {
             axMapControl1.ActiveView.GraphicsContainer.DeleteElement(m_element_snap);
             axMapControl1.ActiveView.GraphicsContainer.DeleteElement((IElement)m_textelement);
             axMapControl1.ActiveView.Refresh();
         }
     }
 }
Exemple #8
0
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add ToolSplitLine.OnClick implementation
            //Find the Modify Feature task and set it as the current task
            IEngineEditTask editTask = m_engineEditor.GetTaskByUniqueName("ControlToolsEditing_ModifyFeatureTask");

            m_engineEditor.CurrentTask = editTask;

            IEngineEditLayers editLayers = m_editLayer;

            snapEnvironment = m_engineEditor as IEngineSnapEnvironment;
            pt = new PointClass();
            //Check the user is editing; otherwise, there will be no snap agent loaded.
            if (editLayers.TargetLayer == null)
            {
                System.Windows.Forms.MessageBox.Show("Please start an edit session");
                return;
            }

            ////Create a feature snap agent.
            IEngineFeatureSnapAgent featureSnapAgent  = new EngineFeatureSnap();
            IFeatureClass           layerFeatureClass = editLayers.TargetLayer.FeatureClass;

            featureSnapAgent.FeatureClass = layerFeatureClass;
            featureSnapAgent.HitType      = esriGeometryHitPartType.esriGeometryPartBoundary;

            //Activate only the snap agent for the target layer.
            snapEnvironment.AddSnapAgent(featureSnapAgent);
            pMPfeedback         = new MovePointFeedbackClass();
            pMPfeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;
            pMPfeedback.Start(pt, pt);

            IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy;

            oldtool = toolbarbuddy.CurrentTool;
        }
        public bool EditFeature(int x, int y, IGeometry geometry)
        {
            GetFeatureOnMouseDown(x, y);
            SelectOnMouseDown();
            if (MyselectedFeature.Count < 1)
            {
                return(false);
            }
            if (geometry == null)
            {
                return(false);
            }

            IPoint pHitPoint = null;
            double hitDist = 0, tol = 0;
            int    vertexIndex = 0, vertexOffset = 0, numVertices = 0, partIndex = 0;
            bool   vertex = false;

            IFeature editedFeature = MyselectedFeature[0];
            IPoint   point         = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            tol = ConvertPixelsToMapUnits(4);
            //IGeometry pGeo = editedFeature.Shape;
            //m_EditingFeature = editedFeature;

            try
            {
                switch (geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryPoint:
                    MyfeedBack         = new MovePointFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMovePointFeedback pointMove = MyfeedBack as IMovePointFeedback;
                    pointMove.Start(geometry as IPoint, point);
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    if (TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex))
                    {
                        if (!vertex)
                        {
                            IGeometryCollection geometryColl = geometry as IGeometryCollection;
                            IPath            path            = geometryColl.get_Geometry(partIndex) as IPath;
                            IPointCollection pointColl       = path as IPointCollection;
                            numVertices = pointColl.PointCount;
                            object missing = Type.Missing;

                            if (vertexIndex == 0)
                            {
                                object start = 1 as object;
                                pointColl.AddPoint(point, ref start, ref missing);
                            }
                            else
                            {
                                object objVertexIndex = vertexIndex as object;
                                pointColl.AddPoint(point, ref missing, ref objVertexIndex);
                            }
                            TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex);
                        }
                        MyfeedBack         = new LineMovePointFeedbackClass();
                        MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                        ILineMovePointFeedback lineMove = MyfeedBack as ILineMovePointFeedback;
                        lineMove.Start(geometry as IPolyline, vertexIndex, point);
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    if (TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex))
                    {
                        if (!vertex)
                        {
                            IGeometryCollection geometryColl = geometry as IGeometryCollection;
                            IPath            path            = geometryColl.get_Geometry(partIndex) as IPath;
                            IPointCollection pointColl       = path as IPointCollection;
                            numVertices = pointColl.PointCount;
                            object missing = Type.Missing;
                            if (vertexIndex == 0)
                            {
                                object start = 1 as object;
                                pointColl.AddPoint(point, ref start, ref missing);
                            }
                            else
                            {
                                object objVertexIndex = vertexIndex as object;
                                pointColl.AddPoint(point, ref missing, ref objVertexIndex);
                            }
                            TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex);
                        }
                        MyfeedBack         = new PolygonMovePointFeedbackClass();
                        MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                        IPolygonMovePointFeedback polyMove = MyfeedBack as IPolygonMovePointFeedback;
                        polyMove.Start(geometry as IPolygon, vertexIndex + vertexOffset, point);
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                default:
                    break;
                }
            }
            catch { return(false); }
            return(true);
        }
Exemple #10
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            try
            {
                pt = ((m_hookHelper.ActiveView.ScreenDisplay).DisplayTransformation).ToMapPoint(X, Y);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            bool ddd = snapEnvironment.SnapPoint(pt);

            if (pMPfeedback != null)
            {
                pMPfeedback.Stop();
            }
            pMPfeedback = null;

            bool hasCut         = false;
            ISet newFeaturesSet = null;

            try
            {
                IFeatureSelection featureSelection = m_editLayer.TargetLayer as IFeatureSelection;
                ISelectionSet     selectionSet     = featureSelection.SelectionSet;
                IEnumIDs          enumIDs          = selectionSet.IDs;
                int iD = enumIDs.Next();
                while (iD != -1) //-1 is reutned after the last valid ID has been reached
                {
                    m_engineEditor.StartOperation();
                    IFeatureClass featureClass = m_editLayer.TargetLayer.FeatureClass;
                    IFeature      feature      = featureClass.GetFeature(iD);
                    // 判断点是否在线上,不是则跳过
                    ITopologicalOperator pto       = feature.Shape as ITopologicalOperator;
                    IGeometry            pgeometry = pto.Intersect(pt, esriGeometryDimension.esriGeometry0Dimension);
                    if (pgeometry.IsEmpty == true)
                    {
                        iD = enumIDs.Next();
                        continue;
                    }
                    IFeatureEdit featureedit = feature as IFeatureEdit;
                    /*ISet*/
                    newFeaturesSet = featureedit.Split(pgeometry);
                    if (newFeaturesSet != null)
                    {
                        newFeaturesSet.Reset();
                        hasCut = true;
                        break;
                    }
                    iD = enumIDs.Next();
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (hasCut)
            {
                //如果操作成功,选中切割的两条线
                //IFeatureSelection featureSelection = m_editLayer.TargetLayer as IFeatureSelection;
                //ISelectionSet selectionSet = featureSelection.SelectionSet;
                //for (int i = 0; i < newFeaturesSet.Count; i++)
                //{
                //    selectionSet.Add(((IFeature)newFeaturesSet.Next()).OID);
                //}
                //selectionSet.Refresh();

                //Refresh the display including modified layer and any previously selected component.
                IActiveView activeView = m_engineEditor.Map as IActiveView;
                activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, activeView.Extent);
                activeView.Refresh();
                //Complete the edit operation.
                m_engineEditor.StopOperation("Split a line");
                // 将当前工具设置为选择工具
                IToolbarControl toolbarctl = m_hookHelper.Hook as IToolbarControl;
                //ICommand com = new ControlsEditingEditToolClass();
                //com.OnCreate(m_mapControl.Object);
                //this.m_mapControl.CurrentTool = com as ITool;
                for (int i = 0; i < toolbarctl.Count; i++)
                {
                    IToolbarItem tbi = toolbarctl.GetItem(i);
                    if (tbi.Command != null && tbi.Command.Name.Equals("ControlToolsEditing_Edit"))
                    {
                        tbi.Command.OnClick();// = true;
                        toolbarctl.CurrentTool = tbi.Command as ITool;
                        IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy;
                        break;
                    }
                }
                //  操作成功后将当前工具置为以前的工具
                //IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy;
                //toolbarbuddy.CurrentTool = oldtool;
                //((IToolbarControl)m_hookHelper.Hook).SetBuddyControl(toolbarbuddy);
                this.Deactivate();
            }
            else
            {
                m_engineEditor.AbortOperation();
                MessageBox.Show("切割点不在线上,未能成功切割选择的线段");
                //重新开始选点
                this.OnClick();
            }
            base.OnMouseDown(Button, Shift, X, Y);
        }
Exemple #11
0
        /// <summary>
        /// 编辑当前图层中鼠标击中的地图对象(开始编辑),
        /// 如果为点对象,可进行位置移动,如果为线对象或面对象,可进行节点编辑
        /// 建议在Map.MouseDown事件中调用本方法
        /// </summary>
        /// <param name="x">鼠标X坐标,屏幕坐标</param>
        /// <param name="y">鼠标Y坐标,屏幕坐标</param>
        /// <returns></returns>
        public void  EditFeatureMouseDown(int x, int y)
        {
            IGeometryCollection pGeomColn;
            IPointCollection    pPointColn;
            IObjectClass        pObjectClass;
            IFeature            pFeature;
            IGeometry           pGeom;

            IPath  pPath;
            IPoint pHitPoint = null;
            IPoint pPoint    = null;
            Double hitDist   = 0.0;
            double tol;
            int    vertexIndex = 0;
            int    numVertices;
            int    partIndex = 0;
            bool   vertex    = false;

            try
            {
                m_pMap.ClearSelection();

                // 取得鼠标击中的第一个对象
                SelectMouseDown(x, y);
                IEnumFeature pSelected = (IEnumFeature)m_pMap.FeatureSelection;
                pFeature = pSelected.Next();
                if (pFeature == null)
                {
                    return;
                }

                IActiveView pActiveView = (IActiveView)m_pMap;
                pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

                // 节点空间查询容差
                tol = ConvertPixelsToMapUnits(pActiveView, 4.0);

                pGeom          = pFeature.Shape;
                pObjectClass   = pFeature.Class;
                m_pEditFeature = pFeature;
                object objNull = Missing.Value;
                object objBefore, objAfter;

                switch (pGeom.GeometryType)
                {
                case esriGeometryType.esriGeometryPoint:
                    m_pFeedback         = new MovePointFeedbackClass();
                    m_pFeedback.Display = pActiveView.ScreenDisplay;
                    IMovePointFeedback pPointMove = (IMovePointFeedback)m_pFeedback;
                    pPointMove.Start((IPoint)pGeom, pPoint);
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    if (TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex))
                    {
                        if (!vertex)
                        {
                            pGeomColn   = (IGeometryCollection)pGeom;
                            pPath       = (IPath)pGeomColn.get_Geometry(partIndex);
                            pPointColn  = (IPointCollection)pPath;
                            numVertices = pPointColn.PointCount;

                            if (vertexIndex == 0)
                            {
                                objBefore = (object)(vertexIndex + 1);
                                pPointColn.AddPoint(pPoint, ref objBefore, ref objNull);
                            }
                            else
                            {
                                objAfter = (object)vertexIndex;
                                pPointColn.AddPoint(pPoint, ref objNull, ref objAfter);
                            }

                            TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex);
                        }
                        m_pFeedback         = new LineMovePointFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        ILineMovePointFeedback pLineMove = (ILineMovePointFeedback)m_pFeedback;
                        pLineMove.Start((IPolyline)pGeom, vertexIndex, pPoint);

//							m_pSelectionTracker = new LineTrackerClass();
//							m_pSelectionTracker.Display = pActiveView.ScreenDisplay ;
//							m_pSelectionTracker.Geometry = pGeom;
//							m_pSelectionTracker.ShowHandles = true;
//							m_pSelectionTracker.QueryResizeFeedback(ref m_pFeedback);
//							m_pSelectionTracker.OnMouseDown(1,0,x,y);
                    }
                    else
                    {
                        return;
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    if (TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex))
                    {
                        if (!vertex)
                        {
                            pGeomColn   = (IGeometryCollection)pGeom;
                            pPath       = (IPath)pGeomColn.get_Geometry(partIndex);
                            pPointColn  = (IPointCollection)pPath;
                            numVertices = pPointColn.PointCount;

                            if (vertexIndex == 0)
                            {
                                objBefore = (object)(vertexIndex + 1);
                                pPointColn.AddPoint(pPoint, ref objBefore, ref objNull);
                            }
                            else
                            {
                                objAfter = (object)vertexIndex;
                                pPointColn.AddPoint(pPoint, ref objNull, ref objAfter);
                            }

                            TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex);
                        }

                        m_pFeedback         = new PolygonMovePointFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        IPolygonMovePointFeedback pPolyMove = (IPolygonMovePointFeedback)m_pFeedback;
                        pPolyMove.Start((IPolygon)pGeom, vertexIndex, pPoint);
                    }
                    else
                    {
                        return;
                    }
                    break;
                }
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                return;
            }
        }