arcengine 按面积(批量)分割

2023-11-02 15:31
文章标签 分割 批量 面积 arcengine

本文主要是介绍arcengine 按面积(批量)分割,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

第一、填写面积,选择分割方式(横向、纵向、鼠标指向)在这里插入图片描述

二、开始分割,只需对分割的地块,绘制一条线段
在这里插入图片描述
三、完成分割
在这里插入图片描述
axMapControl1_OnMouseDown事件下

            #region 面积分割if (areaDi){if (axMapControl1.Map.LayerCount == 0) return;if (axMapControl1.Map.LayerCount > 1){MessageBox.Show("请只添加一个图层!", "提示");return;}// TODO:  Add Cut.OnMouseDown implementationif (e.button == 1)//左键按下{IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;//划线IGeometry pline = (IGeometry)axMapControl1.TrackLine();//拿到划线范围内的所有featureIGeometry 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();IFeature fsFeature = null;//依次遍历while (pFeature != null){if (rela.Crosses(pFeature.Shape) || fsFeature != null)//判断是否Cross  (rela.Crosses(pFeature.Shape)){// FrmPartitionarea frmPartitionarea = new FrmPartitionarea((pFeature.Shape as IArea).Area);// frmPartitionarea.Owner = this;//frmPartitionarea.Show();//if (frmPartitionarea.ShowDialog() == DialogResult.OK)//{if (Math.Round((pFeature.Shape as IArea).Area, 2) < Math.Round(divisionArea, 2)){MessageBox.Show("分割面积大约图斑面积!", "错误");//return;//当分割面积大约面要素面积时,返回pFeature = pEnumFeature.Next();continue;}try{//把面转成ITopologicalOperator,使用Cut函数ITopologicalOperator topo = (pFeature.Shape as IPolygon) as ITopologicalOperator;//新建两个面,作为切割函数的参数,切割后的两个对象保存于这两个面之中IGeometry pLeftGeometry = new PolygonClass();IGeometry pRightGeometry = new PolygonClass();double yValue = pFeature.Shape.Envelope.YMax - pFeature.Shape.Envelope.YMin;double xValue = pFeature.Shape.Envelope.XMax - pFeature.Shape.Envelope.XMin;bool plusChk = false;bool reduceChk = false;bool fgChk = false;double left = 0;double right = 0;double newValue = 0;double newValue2 = 0;List<double> oldleft = new List<double>();bool chkFX = false;bool chkcw = false;int n = 0;for (int j = 0; j < 100; j++){IPoint point1 = new PointClass();IPoint point2 = new PointClass();ILine newline = new LineClass();IPolyline fgx = null;//double count = pFeature.Shape.Envelope.YMax - pFeature.Shape.Envelope.YMin;//pline.if (portrait1)//纵{if (j == 0){point1.X = pFeature.Shape.Envelope.XMin + xValue / 2;point1.Y = pFeature.Shape.Envelope.YMin;point2.X = pFeature.Shape.Envelope.XMin + xValue / 2;point2.Y = pFeature.Shape.Envelope.YMax;newValue = pFeature.Shape.Envelope.XMin + xValue / 2;}else if (plusChk){point1.X = newValue + (xValue / Math.Pow(2, j + 1));point1.Y = pFeature.Shape.Envelope.YMin;point2.X = newValue + (xValue / Math.Pow(2, j + 1));point2.Y = pFeature.Shape.Envelope.YMax;newValue = newValue + (xValue / Math.Pow(2, j + 1));}else if (reduceChk){point1.X = newValue - (xValue / Math.Pow(2, j + 1));point1.Y = pFeature.Shape.Envelope.YMin;point2.X = newValue - (xValue / Math.Pow(2, j + 1));point2.Y = pFeature.Shape.Envelope.YMax;newValue = newValue - (xValue / Math.Pow(2, j + 1));}}else if (transverse1)//横{if (j == 0){point1.Y = pFeature.Shape.Envelope.YMin + yValue / 2;point1.X = pFeature.Shape.Envelope.XMin;point2.Y = pFeature.Shape.Envelope.YMin + yValue / 2;point2.X = pFeature.Shape.Envelope.XMax;newValue = pFeature.Shape.Envelope.YMin + yValue / 2;}else if (plusChk){point1.Y = newValue + (yValue / Math.Pow(2, j + 1));point1.X = pFeature.Shape.Envelope.XMin;point2.Y = newValue + (yValue / Math.Pow(2, j + 1));point2.X = pFeature.Shape.Envelope.XMax;newValue = newValue + (yValue / Math.Pow(2, j + 1));}else if (reduceChk){point1.Y = newValue - (yValue / Math.Pow(2, j + 1));point1.X = pFeature.Shape.Envelope.XMin;point2.Y = newValue - (yValue / Math.Pow(2, j + 1));point2.X = pFeature.Shape.Envelope.XMax;newValue = newValue - (yValue / Math.Pow(2, j + 1));}}else if (Mousepointing1)//鼠标指向 有问题{IPolyline lin2 = pline as IPolyline;IPoint point3 = new PointClass();IPoint point4 = new PointClass();if (j == 0){point3.X = (pFeature.Shape.Envelope.XMin + pFeature.Shape.Envelope.XMax) / 2;point3.Y = (pFeature.Shape.Envelope.YMin + pFeature.Shape.Envelope.YMax) / 2;point4.X = lin2.ToPoint.X - (lin2.FromPoint.X - point3.X);point4.Y = lin2.ToPoint.Y - (lin2.FromPoint.Y - point3.Y);newValue = point3.Y;newValue2 = point4.Y;}else if (plusChk){point3.X = (pFeature.Shape.Envelope.XMin + pFeature.Shape.Envelope.XMax) / 2;point3.Y = newValue + (yValue / Math.Pow(2, j + 1));point4.X = lin2.ToPoint.X - (lin2.FromPoint.X - point3.X);point4.Y = newValue2 + (yValue / Math.Pow(2, j + 1));newValue = point3.Y;newValue2 = point4.Y;}else if (reduceChk){point3.X = (pFeature.Shape.Envelope.XMin + pFeature.Shape.Envelope.XMax) / 2;point3.Y = newValue - (yValue / Math.Pow(2, j + 1));point4.X = lin2.ToPoint.X - (lin2.FromPoint.X - point3.X);point4.Y = newValue2 - (yValue / Math.Pow(2, j + 1));newValue = point3.Y;newValue2 = point4.Y;}ILine newline2 = new LineClass();newline2.PutCoords(point3, point4);ISegmentCollection pSegCol2 = new PolylineClass();pSegCol2.AddSegment(newline2 as ISegment);fgx = DataManager.getExtendLine(pSegCol2 as IPolyline, 3, 1000000);}if (fgx == null){newline.PutCoords(point1, point2);ISegmentCollection pSegCol = new PolylineClass();pSegCol.AddSegment(newline as ISegment);fgx = pSegCol as IPolyline;}try{try{topo.Cut((fgx as IPolyline), out pLeftGeometry, out pRightGeometry);//chkcw = false;}catch{//chkcw = true;//newValue = newValue - (yValue / Math.Pow(2, j + 1));//newValue2 = newValue2 - (yValue / Math.Pow(2, j + 1));}left = Math.Round((pLeftGeometry as IArea).Area, 2);right = Math.Round((pRightGeometry as IArea).Area, 2);//oldleft.Add(left);//if(Math.Abs(left- divisionArea))if (Math.Round((left + right), 0) == Math.Round(divisionArea, 0)){fgChk = false;break;}if (Mousepointing1){//if (oldleft.Count > 2)//{//    if (Math.Abs(oldleft[oldleft.Count - 1] - divisionArea) > Math.Abs(oldleft[oldleft.Count - 2] - divisionArea))//    {//        if (chkFX)//            chkFX = false;//        else//            chkFX = true;//    }//    if (oldleft[oldleft.Count - 1] == oldleft[oldleft.Count - 2])//    {//        if (chkFX)//            chkFX = false;//        else//            chkFX = true;//        j = 2;//    }//}//if (left / divisionArea > 2 && (!chkcw))//{//    j = 2;//}//if (left == 0 || right == 0)//{//    if (left == Math.Round(divisionArea, 2) || right == Math.Round(divisionArea, 2))//    {//        fgChk = false;//        break;//    }//    else//    { chkFX = true; }//}}if (transverse1){if (upperChk)//分割上面{if (left == Math.Round(divisionArea, 2)){fgChk = true;break;}else if (left > Math.Round(divisionArea, 2)){reduceChk = false;plusChk = true;}else if (left < Math.Round(divisionArea, 2)){plusChk = false;reduceChk = true;}}else if (lowerChk) //分割下面{if (right == Math.Round(divisionArea, 2)){fgChk = true;break;}else if (right > Math.Round(divisionArea, 2)){plusChk = false;reduceChk = true;}else if (right < Math.Round(divisionArea, 2)){reduceChk = false;plusChk = true;}}}else if (portrait1){if (rightChk)//分割右面{if (right == Math.Round(divisionArea, 2)){fgChk = true;break;}else if (right > Math.Round(divisionArea, 2)){reduceChk = false;plusChk = true;}else if (right < Math.Round(divisionArea, 2)){plusChk = false;reduceChk = true;}}else if (leftChk) //分割左面{if (left == Math.Round(divisionArea, 2)){fgChk = true;break;}else if (left > Math.Round(divisionArea, 2)){plusChk = false;reduceChk = true;}else if (left < Math.Round(divisionArea, 2)){reduceChk = false;plusChk = true;}}}else if (Mousepointing1){if (left == Math.Round(divisionArea, 2)){fgChk = true;break;}else if (left < Math.Round(divisionArea, 2)){plusChk = false;reduceChk = true;}else if (left > Math.Round(divisionArea, 2)){reduceChk = false;plusChk = true;}}}catch { }if (j == 99){MessageBox.Show("图形面积远大于分割面积,无法切割成功!");}}//topo.Cut((pline as IPolyline), out pLeftGeometry, out pRightGeometry);//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 (fgChk){//获取字段名List<string> pAllFieldsList = new List<string>();pAllFieldsList = KYKJ.AttributeOperate.AttTableOperate.get_FieldsString(pFeatureLayer.FeatureClass);//由FeatureClass新建FeatureIFeature 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();if (transverse1 && tValue > 1){if (upperChk)fsFeature = pFeatureRight;elsefsFeature = pFeatureLeft;}else if (portrait1 && pValue > 1){if (rightChk)fsFeature = pFeatureLeft;elsefsFeature = pFeatureRight;}elsefsFeature = null;//删除pFeature.Delete();}}catch (Exception ex){MessageBox.Show("分割失败,可能该图形为多面体(包含z)!");//string ss = ex.ToString();}// }}if (tValue > 1){pFeature = fsFeature;tValue--;}else if (pValue > 1){pFeature = fsFeature;pValue--;}if (fsFeature == null)pFeature = pEnumFeature.Next();}//清除选择IFeatureSelection pFeatureSelectionClear = axMapControl1.get_Layer(0) as IFeatureSelection;pFeatureSelectionClear.Clear();axMapControl1.Refresh();}}#endregion

这篇关于arcengine 按面积(批量)分割的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/331573

相关文章

使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解

《使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解》本文详细介绍了如何使用Python通过ncmdump工具批量将.ncm音频转换为.mp3的步骤,包括安装、配置ffmpeg环... 目录1. 前言2. 安装 ncmdump3. 实现 .ncm 转 .mp34. 执行过程5. 执行结

Python实现批量CSV转Excel的高性能处理方案

《Python实现批量CSV转Excel的高性能处理方案》在日常办公中,我们经常需要将CSV格式的数据转换为Excel文件,本文将介绍一个基于Python的高性能解决方案,感兴趣的小伙伴可以跟随小编一... 目录一、场景需求二、技术方案三、核心代码四、批量处理方案五、性能优化六、使用示例完整代码七、小结一、

C#实现一键批量合并PDF文档

《C#实现一键批量合并PDF文档》这篇文章主要为大家详细介绍了如何使用C#实现一键批量合并PDF文档功能,文中的示例代码简洁易懂,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言效果展示功能实现1、添加文件2、文件分组(书签)3、定义页码范围4、自定义显示5、定义页面尺寸6、PDF批量合并7、其他方法

Python批量替换多个Word文档的多个关键字的方法

《Python批量替换多个Word文档的多个关键字的方法》有时,我们手头上有多个Excel或者Word文件,但是领导突然要求对某几个术语进行批量的修改,你是不是有要崩溃的感觉,所以本文给大家介绍了Py... 目录工具准备先梳理一下思路神奇代码来啦!代码详解激动人心的测试结语嘿,各位小伙伴们,大家好!有没有想

shell脚本批量导出redis key-value方式

《shell脚本批量导出rediskey-value方式》为避免keys全量扫描导致Redis卡顿,可先通过dump.rdb备份文件在本地恢复,再使用scan命令渐进导出key-value,通过CN... 目录1 背景2 详细步骤2.1 本地docker启动Redis2.2 shell批量导出脚本3 附录总

批量导入txt数据到的redis过程

《批量导入txt数据到的redis过程》用户通过将Redis命令逐行写入txt文件,利用管道模式运行客户端,成功执行批量删除以Product*匹配的Key操作,提高了数据清理效率... 目录批量导入txt数据到Redisjs把redis命令按一条 一行写到txt中管道命令运行redis客户端成功了批量删除k

Python实现批量提取BLF文件时间戳

《Python实现批量提取BLF文件时间戳》BLF(BinaryLoggingFormat)作为Vector公司推出的CAN总线数据记录格式,被广泛用于存储车辆通信数据,本文将使用Python轻松提取... 目录一、为什么需要批量处理 BLF 文件二、核心代码解析:从文件遍历到数据导出1. 环境准备与依赖库

Python实现PDF按页分割的技术指南

《Python实现PDF按页分割的技术指南》PDF文件处理是日常工作中的常见需求,特别是当我们需要将大型PDF文档拆分为多个部分时,下面我们就来看看如何使用Python创建一个灵活的PDF分割工具吧... 目录需求分析技术方案工具选择安装依赖完整代码实现使用说明基本用法示例命令输出示例技术亮点实际应用场景扩

linux批量替换文件内容的实现方式

《linux批量替换文件内容的实现方式》本文总结了Linux中批量替换文件内容的几种方法,包括使用sed替换文件夹内所有文件、单个文件内容及逐行字符串,强调使用反引号和绝对路径,并分享个人经验供参考... 目录一、linux批量替换文件内容 二、替换文件内所有匹配的字符串 三、替换每一行中全部str1为st

基于Python开发一个图像水印批量添加工具

《基于Python开发一个图像水印批量添加工具》在当今数字化内容爆炸式增长的时代,图像版权保护已成为创作者和企业的核心需求,本方案将详细介绍一个基于PythonPIL库的工业级图像水印解决方案,有需要... 目录一、系统架构设计1.1 整体处理流程1.2 类结构设计(扩展版本)二、核心算法深入解析2.1 自