arcengine 批量分割

一、开始分割
在这里插入图片描述
二、提示图层ID,显示分割后的两个要素的面积,最后确定是否分割
在这里插入图片描述
三、分割完成
在这里插入图片描述
axMapControl1_OnMouseDown事件下代码:
#region 分割
if (plqg)
{
if (axMapControl1.Map.LayerCount == 0) return;
if (axMapControl1.Map.LayerCount > 1)
{
MessageBox.Show(“请只添加一个图层!”, “提示”);
return;
}
// TODO: Add Cut.OnMouseDown implementation
if (e.button == 1)//左键按下
{
IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
//划线
IGeometry pline = (IGeometry)axMapControl1.TrackLine();
//拿到划线范围内的所有feature
IGeometry pGeometry = pline as IGeometry;
IMap pMap = axMapControl1.Map;
pMap.SelectByShape(pGeometry, null, false);//< br >
//转成IRealtionOperator接口,以便在遍历时判断几何位置关系。
IRelationalOperator rela = (pline as IPolyline) as IRelationalOperator;
//拿到切割目标集合
IEnumFeature pEnumFeature = (IEnumFeature)pMap.FeatureSelection;
IEnumFeatureSetup pEnumFeatureSetup = pEnumFeature as IEnumFeatureSetup;
pEnumFeatureSetup.AllFields = true;
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);
double left = (pLeftGeometry as IArea).Area;
double right = (pRightGeometry as IArea).Area;
//MessageBox.Show(left.ToString()+","+right.ToString(),MessageBoxButtons.OKCancel);
//DialogResult result=null;
// if (pFeature.HasOID)
DialogResult result = MessageBox.Show(“图层ID:” + pFeature.get_Value(0).ToString() + “,确定要分割!!!!”, “切割面积分别为:” + Math.Round(left, 3).ToString() + “,” + Math.Round(right, 3).ToString(), MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
{
//获取字段名
List pAllFieldsList = new List();
pAllFieldsList = KYKJ.AttributeOperate.AttTableOperate.get_FieldsString(pFeatureLayer.FeatureClass);
//由FeatureClass新建Feature
IFeature pFeatureLeft = pFeatureLayer.FeatureClass.CreateFeature();
IFeature pFeatureRight = pFeatureLayer.FeatureClass.CreateFeature();
//赋值
pFeatureLeft.Shape = pLeftGeometry;
pFeatureRight.Shape = pRightGeometry;
for (int i = 0; i < pAllFieldsList.Count; i++)
{
if (pAllFieldsList[i].ToUpper().Contains(“ID”) || pAllFieldsList[i].ToUpper().Contains(“SHP”) || pAllFieldsList[i].ToUpper().Contains(“SHAPE_”)) continue;
int fieldindex = pFeatureLeft.Fields.FindField(pAllFieldsList[i]);
string sd = pFeature.Value[fieldindex].ToString();
pFeatureLeft.set_Value(fieldindex, pFeature.Value[fieldindex]);
pFeatureRight.set_Value(fieldindex, pFeature.Value[fieldindex]);
}
//保存
pFeatureLeft.Store();
pFeatureRight.Store();
//删除
pFeature.Delete();
}
}
catch (Exception ex)
{
MessageBox.Show(“分割失败,可能该图形为多面体(包含z)!”);
//string ss = ex.ToString();
}
}
pFeature = pEnumFeature.Next();
}
//清除选择
IFeatureSelection pFeatureSelectionClear = axMapControl1.get_Layer(0) as IFeatureSelection;
pFeatureSelectionClear.Clear();
axMapControl1.Refresh();
}
}
#endregion

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值