要素的移动

本文介绍了一段用于移动GIS环境中已选中要素(点、线、面)的代码实现。该功能通过监听鼠标事件来更新要素的位置,并确保要素类型与操作匹配。文中详细展示了如何在要素被选中时开始移动过程,移动过程中实时更新显示位置,以及移动结束后的要素更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里只给出主要的功能代码,实现了移动选定点,当然还可以扩展实现以线和面。

 

public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (m_CurrentLayer == null)//m_CurrentLayer 是IFeatureLayer
                return;
            if ((m_CurrentLayer as IGeoFeatureLayer) == null) return;
            featureLayer = m_CurrentLayer as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;          
            if (featureClass == null) return;
            // 检查是否有要素被选中,没有则MessageBox提醒
           
            IFeatureSelection pFeatSel = (IFeatureSelection)m_CurrentLayer;
            ISelectionSet pSelectionSet = pFeatSel.SelectionSet;
            if (pSelectionSet.Count == 0)
            {
                MessageBox.Show("在 '" + m_CurrentLayer.Name + "' 图层没有要素被选中!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            // 有则返回要素游标
            ICursor pCursor1;
            pSelectionSet.Search(null, false, out pCursor1);
            IFeatureCursor featureCursor = pCursor1 as IFeatureCursor;
            newfeature = featureCursor.NextFeature();
            IGeometry startGeom = newfeature.Shape;
            IPoint point = m_ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            try
            {
                switch (featureClass.ShapeType)
                {
                    case esriGeometryType.esriGeometryPoint:
                        m_FeedBack = new MovePointFeedbackClass();
                        m_FeedBack.Display = m_ActiveView.ScreenDisplay;
                        IMovePointFeedback pointMoveFeedback = m_FeedBack as IMovePointFeedback;
                        pointMoveFeedback.Start(startGeom as IPoint, point);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                MessageBox.Show("请检查代码!");
                return;
            }
        }

        public override void OnMouseMove(int Button, int Shift, int X, int Y)
        {
            IPoint point = m_ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            m_FeedBack.MoveTo(point);
        }

        public override void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            m_DisplayGeometry = EndFeatureMove(X, Y);
            //UpdateEdit(m_DisplayGeometry);
            //IFeature point =null ;
            point = m_CurrentLayer.FeatureClass.CreateFeature();
            point.Shape = m_DisplayGeometry;
            point.Store();
            newfeature.Delete();
            m_Map.ClearSelection();           
            IFeatureSelection feaSelect = featureLayer as IFeatureSelection;
            feaSelect.SelectionSet.Add(point.OID);
            //m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGraphicSelection, null, m_ActiveView.Extent);
            m_ActiveView.Refresh();
        }

        public IGeometry EndFeatureMove(int x, int y)
        {
            if (m_FeedBack == null) return null;
            IGeometry geometry = null;
            try
            {
                if ((m_FeedBack as IMovePointFeedback) != null)
                {
                    IMovePointFeedback pointMoveFeedback = m_FeedBack as IMovePointFeedback;
                    geometry = pointMoveFeedback.Stop();
                }
            }
            catch { return null; }
            m_FeedBack = null;
            return geometry;
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值