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 );<br>
         //转成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();
     }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值