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

相关文章

Oracle 通过 ROWID 批量更新表的方法

《Oracle通过ROWID批量更新表的方法》在Oracle数据库中,使用ROWID进行批量更新是一种高效的更新方法,因为它直接定位到物理行位置,避免了通过索引查找的开销,下面给大家介绍Orac... 目录oracle 通过 ROWID 批量更新表ROWID 基本概念性能优化建议性能UoTrFPH优化建议注

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

Python实现图片分割的多种方法总结

《Python实现图片分割的多种方法总结》图片分割是图像处理中的一个重要任务,它的目标是将图像划分为多个区域或者对象,本文为大家整理了一些常用的分割方法,大家可以根据需求自行选择... 目录1. 基于传统图像处理的分割方法(1) 使用固定阈值分割图片(2) 自适应阈值分割(3) 使用图像边缘检测分割(4)

Python如何将大TXT文件分割成4KB小文件

《Python如何将大TXT文件分割成4KB小文件》处理大文本文件是程序员经常遇到的挑战,特别是当我们需要把一个几百MB甚至几个GB的TXT文件分割成小块时,下面我们来聊聊如何用Python自动完成这... 目录为什么需要分割TXT文件基础版:按行分割进阶版:精确控制文件大小完美解决方案:支持UTF-8编码

Python实现AVIF图片与其他图片格式间的批量转换

《Python实现AVIF图片与其他图片格式间的批量转换》这篇文章主要为大家详细介绍了如何使用Pillow库实现AVIF与其他格式的相互转换,即将AVIF转换为常见的格式,比如JPG或PNG,需要的小... 目录环境配置1.将单个 AVIF 图片转换为 JPG 和 PNG2.批量转换目录下所有 AVIF 图

详解如何通过Python批量转换图片为PDF

《详解如何通过Python批量转换图片为PDF》:本文主要介绍如何基于Python+Tkinter开发的图片批量转PDF工具,可以支持批量添加图片,拖拽等操作,感兴趣的小伙伴可以参考一下... 目录1. 概述2. 功能亮点2.1 主要功能2.2 界面设计3. 使用指南3.1 运行环境3.2 使用步骤4. 核

C++字符串提取和分割的多种方法

《C++字符串提取和分割的多种方法》在C++编程中,字符串处理是一个常见的任务,尤其是在需要从字符串中提取特定数据时,本文将详细探讨如何使用C++标准库中的工具来提取和分割字符串,并分析不同方法的适用... 目录1. 字符串提取的基本方法1.1 使用 std::istringstream 和 >> 操作符示

基于Python开发批量提取Excel图片的小工具

《基于Python开发批量提取Excel图片的小工具》这篇文章主要为大家详细介绍了如何使用Python中的openpyxl库开发一个小工具,可以实现批量提取Excel图片,有需要的小伙伴可以参考一下... 目前有一个需求,就是批量读取当前目录下所有文件夹里的Excel文件,去获取出Excel文件中的图片,并

Jmeter如何向数据库批量插入数据

《Jmeter如何向数据库批量插入数据》:本文主要介绍Jmeter如何向数据库批量插入数据方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Jmeter向数据库批量插入数据Jmeter向mysql数据库中插入数据的入门操作接下来做一下各个元件的配置总结Jmete

Python批量调整Word文档中的字体、段落间距及格式

《Python批量调整Word文档中的字体、段落间距及格式》这篇文章主要为大家详细介绍了如何使用Python的docx库来批量处理Word文档,包括设置首行缩进、字体、字号、行间距、段落对齐方式等,需... 目录关键代码一级标题设置  正文设置完整代码运行结果最近关于批处理格式的问题我查了很多资料,但是都没