注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

快乐小屋

 
 
 

日志

 
 

移动要素(可同时移动多个要素)  

2013-04-28 11:15:34|  分类: ArcGIS Engine开 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
//定义成员变量
private IActiveView pActiveView;
private IMap pMap;
private IWorkspaceEdit pWorkspaceEdit;
private  IPoint startPoint;
private INewLineFeedback pLineFeedback;
private IMoveGeometryFeedback pMoveGeometryFeedback;
private ISet pMoveSet;


public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
    if (pMap.SelectionCount == 0)
    {
        MessageBox.Show("当前选择集为空,请选择要素!", "提示",
            MessageBoxButtons.OK, MessageBoxIcon.Warning);
        return;
    }
    if (pWorkspaceEdit == null)
        return;
    if (!pWorkspaceEdit.IsBeingEdited())
        return;
    startPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

    if (pMoveGeometryFeedback == null)
    {
        IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;      //QI
        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);
    }         
}

public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
    // TODO:  Add MoveFeatures.OnMouseMove implementation
    if (startPoint == null)
        return;
    if (pLineFeedback == null || pMoveGeometryFeedback == null)
        return;
    IPoint pMouseMovePoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
    pLineFeedback.MoveTo(pMouseMovePoint);
    pMoveGeometryFeedback.MoveTo(pMouseMovePoint);
}

public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
    // TODO:  Add MoveFeatures.OnMouseUp implementation
    if (pMap.SelectionCount == 0)
        return;
    if (pLineFeedback == null || pMoveGeometryFeedback == null)
        return;
    if (startPoint == null)
        return;
    IPoint pEndPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
    pLineFeedback.Stop();         
    pMoveGeometryFeedback.MoveTo(pEndPoint);
    if (startPoint.X != pEndPoint.X || startPoint.X != pEndPoint.Y)
    {
        MoveAllFeatures(pMoveSet, startPoint, pEndPoint);
        //局部刷新视图
        pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);
       // pActiveView.Refresh();
    }
    pLineFeedback = null;
    pMoveGeometryFeedback = null;
}


//定义MoveAllFeatures函数,用于移动要素集
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);
    }
}



运行效果之移动单个要素:

无标题.png


运行效果之移动多个要素:

2.jpg
  评论这张
 
阅读(345)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018