AE 移動要素(可多個)、差保存的代碼


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;


namespace test1023
{
    public partial class Form1 : Form
    {
        private IActiveView pActiveView;
        private IMap pMap;
        private IWorkspaceEdit pWorkspaceEdit;
        private IPoint startPoint;
        private INewLineFeedback pLineFeedback;
        private IMoveGeometryFeedback pMoveGeometryFeedback;
        private ISet pMoveSet;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseDownEventHandler(defaultMapControl_OnMouseDown);
            this.axMapControl1.OnMouseMove += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseMoveEventHandler(defaultMapControl_OnMouseMove);
            this.axMapControl1.OnMouseUp += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseUpEventHandler(defaultMapControl_OnMouseUp);
        }

        private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            //if (this.axMapControl1.CurrentTool != null)
            //{
            //    return;
            //} 
            //pActiveView = this.axMapControl1.ActiveView;
            //pMap = this.axMapControl1.Map;
            //startPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            //if (pMoveGeometryFeedback == null)
            //{
            //    IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
            //    if (pEnumFeature == null)
            //        return;
            //    ////定義InvalidAreaClass對象,用於局部刷新數據
            //    //pInvalidArea = new InvalidAreaClass();
            //    //pInvalidArea.Display = pActiveView.ScreenDisplay;
            //    //pInvalidArea.Add(pEnumFeature);

            //    pEnumFeature.Reset();
            //    IFeature pFeature = pEnumFeature.Next();
            //    //定義SetClass對象,用於存儲當前要素選擇集
            //    pMoveSet = new SetClass();
            //    pMoveGeometryFeedback = new MoveGeometryFeedbackClass();
            //    pMoveGeometryFeedback.Display = pActiveView.ScreenDisplay;
            //    while (pFeature != null)
            //    {
            //        pMoveGeometryFeedback.AddGeometry(pFeature.Shape);
            //        pMoveSet.Add(pFeature);
            //        pFeature = pEnumFeature.Next();
            //    }
            //    pMoveGeometryFeedback.Start(startPoint);
            //}
            ////定義NewLineFeedbackClass對象,用於顯示要素移動的軌跡
            //if (pLineFeedback == null)
            //{
            //    pLineFeedback = new NewLineFeedbackClass();
            //    pLineFeedback.Display = pActiveView.ScreenDisplay;
            //    pLineFeedback.Start(startPoint);
            //}
        }

        private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
        {
            //if (this.axMapControl1.CurrentTool != null)
            //{
            //    return;
            //}
            //if (startPoint == null)
            //    return;
            //if (pLineFeedback == null || pMoveGeometryFeedback == null)
            //    return;
            //IPoint pMouseMovePoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            //pLineFeedback.MoveTo(pMouseMovePoint);
            //pMoveGeometryFeedback.MoveTo(pMouseMovePoint);
        }

        private void axMapControl1_OnMouseUp(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvent e)
        {
            //if (this.axMapControl1.CurrentTool != null)
            //{
            //    return;
            //}
            //if (pLineFeedback == null || pMoveGeometryFeedback == null)
            //    return;
            //if (startPoint == null)
            //    return;
            //IPoint pEndPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            //pLineFeedback.Stop();
            //pMoveGeometryFeedback.MoveTo(pEndPoint);
            //if (startPoint.X != pEndPoint.X || startPoint.X != pEndPoint.Y)
            //{
            //    MoveAllFeatures(pMoveSet, startPoint, pEndPoint);
            //    this.axMapControl1.Refresh();
            //}
            //pLineFeedback = null;
            //pMoveGeometryFeedback = null;
        }

        private void MoveAllFeatures(ISet pMoveSet, IPoint pStartPoint, IPoint pEndPoint)
        {
            try
            {
                //pWorkspaceEdit.StartEditOperation();
                ILine pLine = new LineClass();
                pLine.PutCoords(pStartPoint, pEndPoint);
                pLine.SpatialReference = pMap.SpatialReference;

                pMoveSet.Reset();
                IFeatureEdit pFeatureEdit = pMoveSet.Next() as IFeatureEdit;
                while (pFeatureEdit != null)
                {
                    pFeatureEdit.MoveSet(pMoveSet, pLine);
                    pFeatureEdit = pMoveSet.Next() as IFeatureEdit;
                }
                //pWorkspaceEdit.StopEditOperation();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.axMapControl1.CurrentTool = null;
        }

        //------------
        private void defaultMapControl_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            if (this.axMapControl1.CurrentTool != null)
            {
                return;
            }
            pActiveView = this.axMapControl1.ActiveView;
            pMap = this.axMapControl1.Map;
            startPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            if (pMoveGeometryFeedback == null)
            {
                IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
                if (pEnumFeature == null)
                    return;
                ////定義InvalidAreaClass對象,用於局部刷新數據
                //pInvalidArea = new InvalidAreaClass();
                //pInvalidArea.Display = pActiveView.ScreenDisplay;
                //pInvalidArea.Add(pEnumFeature);

                pEnumFeature.Reset();
                IFeature pFeature = pEnumFeature.Next();
                //定義SetClass對象,用於存儲當前要素選擇集
                pMoveSet = new SetClass();
                pMoveGeometryFeedback = new MoveGeometryFeedbackClass();
                pMoveGeometryFeedback.Display = pActiveView.ScreenDisplay;
                while (pFeature != null)
                {
                    pMoveGeometryFeedback.AddGeometry(pFeature.Shape);
                    pMoveSet.Add(pFeature);
                    pFeature = pEnumFeature.Next();
                }
                pMoveGeometryFeedback.Start(startPoint);
            }
            //定義NewLineFeedbackClass對象,用於顯示要素移動的軌跡
            if (pLineFeedback == null)
            {
                pLineFeedback = new NewLineFeedbackClass();
                pLineFeedback.Display = pActiveView.ScreenDisplay;
                pLineFeedback.Start(startPoint);
            }
        }

        private void defaultMapControl_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
        {
            if (this.axMapControl1.CurrentTool != null)
            {
                return;
            }
            if (startPoint == null)
                return;
            if (pLineFeedback == null || pMoveGeometryFeedback == null)
                return;
            IPoint pMouseMovePoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            pLineFeedback.MoveTo(pMouseMovePoint);
            pMoveGeometryFeedback.MoveTo(pMouseMovePoint);
        }

        private void defaultMapControl_OnMouseUp(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvent e)
        {
            if (this.axMapControl1.CurrentTool != null)
            {
                return;
            }
            if (pLineFeedback == null || pMoveGeometryFeedback == null)
                return;
            if (startPoint == null)
                return;
            IPoint pEndPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            pLineFeedback.Stop();
            pMoveGeometryFeedback.MoveTo(pEndPoint);
            if (startPoint.X != pEndPoint.X || startPoint.X != pEndPoint.Y)
            {
                MoveAllFeatures(pMoveSet, startPoint, pEndPoint);
                this.axMapControl1.Refresh();
            }
            pLineFeedback = null;
            pMoveGeometryFeedback = null;
        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM