zoukankan      html  css  js  c++  java
  • Arcgis Engine 切割图斑(ITool)

            public override void OnMouseDown(int Button, int Shift, int X, int Y)
            {
                // TODO:  Add Cut.OnMouseDown implementation
                if(Button==1)//左键按下
                {
                    //拿到hook
                    IMapControl3 pMapControlx = (IMapControl3)m_hookHelper.Hook;
    
                    IFeatureLayer pFeatureLayer = pMapControlx.get_Layer(0) as IFeatureLayer;
    
                    //划线
                    IGeometry pline = (IGeometry)pMapControlx.TrackLine();
    
                    
                    //拿到划线范围内的所有feature
                    IGeometry pGeometry = pline as IGeometry;
                    IMap pMap = pMapControlx.Map;
                    pMap.SelectByShape(pGeometry, null, false);
    //转成IRealtionOperator接口,以便在遍历时判断几何位置关系。 IRelationalOperator rela = (pline as IPolyline) as IRelationalOperator; //拿到切割目标集合 IEnumFeature pEnumFeature = (IEnumFeature)pMap.FeatureSelection; IFeature pFeature = pEnumFeature.Next(); //依次遍历 while (pFeature != null) { if(rela.Crosses(pFeature.Shape))//判断是否Cross { try { //把面转成ITopologicalOperator,使用Cut函数 ITopologicalOperator topo = (pFeature.Shape as IPolygon) as ITopologicalOperator; //新建两个面,作为切割函数的参数,切割后的两个对象保存于这两个面之中 IGeometry pLeftGeometry = new PolygonClass(); IGeometry pRightGeometry = new PolygonClass(); topo.Cut((pline as IPolyline), out pLeftGeometry, out pRightGeometry); //由FeatureClass新建Feature IFeature pFeatureLeft = pFeatureLayer.FeatureClass.CreateFeature(); IFeature pFeatureRight = pFeatureLayer.FeatureClass.CreateFeature(); //保存 pFeatureLeft.Shape = pLeftGeometry; pFeatureRight.Shape = pRightGeometry; pFeatureLeft.Store(); pFeatureRight.Store(); //删除 pFeature.Delete(); } catch { } } pFeature = pEnumFeature.Next(); } //清除选择 IFeatureSelection pFeatureSelectionClear= pMapControlx.get_Layer(0) as IFeatureSelection; pFeatureSelectionClear.Clear(); pMapControlx.Refresh(); } }

      

  • 相关阅读:
    第 9 章 完成购物车
    新建 ASP.NET MVC 项目快速代码
    一个真正的应用程序(第7~8章)(所需代码在下一篇随笔里)
    HTML
    squid 高匿设置
    Linux操作系统上ADSL拨号上网的方法详解
    MYSQL-max_binlog_cache_size参数
    mysql查杀会话
    centos配置Tomcat以指定的身份(非root)运行
    mysql load data导入脚本
  • 原文地址:https://www.cnblogs.com/xianerwonder/p/4311479.html
Copyright © 2011-2022 走看看