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将长图片分割为若干张小图片

《使用Python将长图片分割为若干张小图片》这篇文章主要为大家详细介绍了如何使用Python将长图片分割为若干张小图片,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. python需求的任务2. Python代码的实现3. 代码修改的位置4. 运行结果1. Python需求

Python在固定文件夹批量创建固定后缀的文件(方法详解)

《Python在固定文件夹批量创建固定后缀的文件(方法详解)》文章讲述了如何使用Python批量创建后缀为.md的文件夹,生成100个,代码中需要修改的路径、前缀和后缀名,并提供了注意事项和代码示例,... 目录1. python需求的任务2. Python代码的实现3. 代码修改的位置4. 运行结果5.

使用Python实现批量访问URL并解析XML响应功能

《使用Python实现批量访问URL并解析XML响应功能》在现代Web开发和数据抓取中,批量访问URL并解析响应内容是一个常见的需求,本文将详细介绍如何使用Python实现批量访问URL并解析XML响... 目录引言1. 背景与需求2. 工具方法实现2.1 单URL访问与解析代码实现代码说明2.2 示例调用

C#中字符串分割的多种方式

《C#中字符串分割的多种方式》在C#编程语言中,字符串处理是日常开发中不可或缺的一部分,字符串分割是处理文本数据时常用的操作,它允许我们将一个长字符串分解成多个子字符串,本文给大家介绍了C#中字符串分... 目录1. 使用 string.Split2. 使用正则表达式 (Regex.Split)3. 使用

使用Python制作一个PDF批量加密工具

《使用Python制作一个PDF批量加密工具》PDF批量加密‌是一种保护PDF文件安全性的方法,通过为多个PDF文件设置相同的密码,防止未经授权的用户访问这些文件,下面我们来看看如何使用Python制... 目录1.简介2.运行效果3.相关源码1.简介一个python写的PDF批量加密工具。PDF批量加密

Python按条件批量删除TXT文件行工具

《Python按条件批量删除TXT文件行工具》这篇文章主要为大家详细介绍了Python如何实现按条件批量删除TXT文件中行的工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1.简介2.运行效果3.相关源码1.简介一个由python编写android的可根据TXT文件按条件批

Java实现批量化操作Excel文件的示例代码

《Java实现批量化操作Excel文件的示例代码》在操作Excel的场景中,通常会有一些针对Excel的批量操作,这篇文章主要为大家详细介绍了如何使用GcExcel实现批量化操作Excel,感兴趣的可... 目录前言 | 问题背景什么是GcExcel场景1 批量导入Excel文件,并读取特定区域的数据场景2

SAM2POINT:以zero-shot且快速的方式将任何 3D 视频分割为视频

摘要 我们介绍 SAM2POINT,这是一种采用 Segment Anything Model 2 (SAM 2) 进行零样本和快速 3D 分割的初步探索。 SAM2POINT 将任何 3D 数据解释为一系列多向视频,并利用 SAM 2 进行 3D 空间分割,无需进一步训练或 2D-3D 投影。 我们的框架支持各种提示类型,包括 3D 点、框和掩模,并且可以泛化到不同的场景,例如 3D 对象、室

Python脚本:对文件进行批量重命名

字符替换:批量对文件名中指定字符进行替换添加前缀:批量向原文件名添加前缀添加后缀:批量向原文件名添加后缀 import osdef Rename_CharReplace():#对文件名中某字符进行替换(已完结)re_dir = os.getcwd()re_list = os.listdir(re_dir)original_char = input('请输入你要替换的字符:')replace_ch

Python脚本:批量解压RAR文件

所需模块: os.getcwd() #获取脚本文件路径os.system() #执行系统命令 import os#source_dir = input("Please input in source_dir:")#unzip_dir = input("Please input in unzip_dir:") source_dir = os.