DayDreamInGIS 之 ArcGIS Pro二次开发 锐角检查

功能:检查图斑中所有的夹角,如果为锐角,在单独的标记图层中标记。生成的结果放在默认gdb中,以 图层名_锐角检查 的方式命名

大体实现方式:遍历图层中的所有要素(多部件要素分别处理),对每个夹角进行判断。

具体功能与ArcMap中锐角检查工具类似

DayDreamInGIS数据处理工具 V1.1.5_beta 锐角检查工具源码与解析_daydreamingistool-CSDN博客

工具界面:

(使用prowindow,样式确实更和谐)

界面代码:

<controls:ProWindow x:Class="DayDreamInGISTool.CornerCheck.CornerCheckWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:controls="clr-namespace:ArcGIS.Desktop.Framework.Controls;assembly=ArcGIS.Desktop.Framework"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:extensions="clr-namespace:ArcGIS.Desktop.Extensions;assembly=ArcGIS.Desktop.Extensions"mc:Ignorable="d"Title="锐角检查" Width="500" Height="200" WindowStartupLocation="CenterOwner"><controls:ProWindow.Resources><ResourceDictionary><ResourceDictionary.MergedDictionaries><extensions:DesignOnlyResourceDictionary Source="pack://application:,,,/ArcGIS.Desktop.Framework;component\Themes\Default.xaml"/></ResourceDictionary.MergedDictionaries></ResourceDictionary></controls:ProWindow.Resources><Grid Margin="5"><Grid.RowDefinitions><RowDefinition></RowDefinition><RowDefinition></RowDefinition><RowDefinition></RowDefinition></Grid.RowDefinitions><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="90"></ColumnDefinition><ColumnDefinition></ColumnDefinition></Grid.ColumnDefinitions><Label VerticalAlignment="Center" HorizontalAlignment="Right">图层</Label><ComboBox Grid.Column="1" Name="cmbLayer" VerticalAlignment="Center" Height="27"></ComboBox></Grid><Grid Grid.Row="1"><Grid.ColumnDefinitions><ColumnDefinition Width="90"></ColumnDefinition><ColumnDefinition></ColumnDefinition></Grid.ColumnDefinitions><Label VerticalAlignment="Center" HorizontalAlignment="Right">角度阈值(度)</Label><TextBox Grid.Column="1" Name="txtYuzhi" VerticalAlignment="Center" Height="27" Text="10"></TextBox></Grid><Grid Grid.Row="2"><Grid.ColumnDefinitions><ColumnDefinition></ColumnDefinition><ColumnDefinition></ColumnDefinition></Grid.ColumnDefinitions><Button Width="140" Height="35" Name="btnOK" Click="btnOK_Click">确定</Button><Button Width="140" Height="35" Grid.Column="1" Name="btnCancel" Click="btnCancel_Click">取消</Button></Grid></Grid>
</controls:ProWindow>

界面交互代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ArcGIS.Core.Data;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using RGeometry=ArcGIS.Core.Geometry;
using GISCommonHelper;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Core;
using ArcGIS.Core.Data.DDL;
using ArcGIS.Desktop.Editing;
using ArcGIS.Core.Data.Exceptions;
using ArcGIS.Core.Internal.CIM;namespace DayDreamInGISTool.CornerCheck
{/// <summary>/// Interaction logic for CornerCheckWindow.xaml/// </summary>public partial class CornerCheckWindow : ArcGIS.Desktop.Framework.Controls.ProWindow{private FeatureLayer player;private double yuzhi;public CornerCheckWindow(){InitializeComponent();try{var map = MapView.Active.Map;cmbLayer.setLyrlist<FeatureLayer>(map, (o, e) =>{if (cmbLayer.SelectedIndex != -1){Player = this.cmbLayer.SelectedValue as FeatureLayer;}});}catch (Exception){}}public FeatureLayer Player { get => player; set => player = value; }public double Yuzhi { get => yuzhi; set => yuzhi = value; }private void btnCancel_Click(object sender, RoutedEventArgs e){this.DialogResult = false;}private void btnOK_Click(object sender, RoutedEventArgs e){if (this.cmbLayer.SelectedIndex == -1){MessageBox.Show("请设置图层");return;}if(double.TryParse(txtYuzhi.Text,out yuzhi)){}else{MessageBox.Show("阈值必须为数字");return;}this.DialogResult = true;}}
}

核心逻辑代码,放在ProWindow的showButton中。

using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Data.DDL;
using ArcGIS.Core.Data.Exceptions;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Layouts;
using ArcGIS.Desktop.Mapping;
using GISCommonHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;namespace DayDreamInGISTool.CornerCheck
{internal class ShowCornerCheckWindow : Button{private CornerCheckWindow _cornercheckwindow = null;private FeatureClass resultFtCls = null;string orignoidfdnm = "Orign_OId";  //源oidstring corneranglefdnm = "CornerAngle";  //夹角string targetanglefdnm = "Angle";  //指向角string summaryfdnm = "Summary";  //其他说明private FeatureLayer pftlyr;private double yuzhi;ProgressDialog progDlg = null;CancelableProgressorSource progSrc = null;protected override void OnClick(){//already open?if (_cornercheckwindow != null)return;_cornercheckwindow = new CornerCheckWindow();_cornercheckwindow.Owner = FrameworkApplication.Current.MainWindow;//_cornercheckwindow.Closed += (o, e) => { _cornercheckwindow = null; };//_cornercheckwindow.Show();//uncomment for modaltry{progDlg = new ProgressDialog($"锐角检查中...", "取消", 100, true);bool? res = _cornercheckwindow.ShowDialog();if (res.Value){yuzhi = _cornercheckwindow.Yuzhi;pftlyr = _cornercheckwindow.Player;//{pftlyr.GetDefinition().Name} progDlg.Show();progSrc = new CancelableProgressorSource(progDlg);execute();}}catch (Exception ex){MessageBox.Show("发生未知异常_"+ex.Message);}finally{if (progDlg != null){progDlg.Hide();progDlg.Dispose();}_cornercheckwindow = null;}}private void execute(){//暂时不做进度条QueuedTask.Run(() =>{long ftcount=pftlyr.GetFeatureClass().GetCount();progSrc.Progressor.Max = (uint)ftcount;resultFtCls = createResultFtCls();FeatureClass ftcls = pftlyr.GetFeatureClass();using (RowCursor cursor = ftcls.Search()){EditOperation editOperation = new EditOperation();while (cursor.MoveNext()){using (Feature feature = cursor.Current as Feature){long oid = feature.GetObjectID();Geometry geo = feature.GetShape();if (geo.GeometryType == ArcGIS.Core.Geometry.GeometryType.Polygon){var polygon = geo as Polygon;check(polygon, oid, editOperation);}progSrc.Progressor.Value++;progSrc.Message = $"要素:{oid} 检查完成";}}string message = "";try{// 执行编辑操作bool creationResult = editOperation.Execute();// 如果操作失败,存储错误消息if (!creationResult) { message = editOperation.ErrorMessage; }}catch (GeodatabaseException exObj){// 如果出现地理数据库异常,存储异常消息message = exObj.Message;throw;}}},progSrc.Progressor);}private void check(Polygon polygon, long oid, EditOperation editOperation){//多部件要素,每个部分单独处理var list = GeometryEngine.Instance.MultipartToSinglePart(polygon);foreach (var item in list){CornerAngleCheck(item as Polygon, yuzhi, oid, editOperation);}}private void CornerAngleCheck(Polygon pPolygon, double tolerance, long oid, EditOperation editOperation){var pntCol = pPolygon.Points;for (int i = 0; i < pntCol.Count - 1; i++)  //循环,多边形的点首尾相接,最后一个点不用核查{MapPoint currentpnt = pntCol[i];MapPoint prePoint = null;MapPoint nextPoint = null;if (i == 0){prePoint = pntCol[pntCol.Count - 2];  //获取倒数第二个点,即为肉眼意义上的前一个点}else{prePoint = pntCol[i - 1];}if (i == pntCol.Count - 2){nextPoint = pntCol[0];}else{nextPoint = pntCol[i + 1];}double ca = calcCornerAngle(currentpnt, prePoint, nextPoint);double aindegredd = GISCommonHelper.MathHelper.Radian2Degree(ca);double d1 = GISCommonHelper.GeometryHelper.getDistance(currentpnt, prePoint);double d2 = GISCommonHelper.GeometryHelper.getDistance(currentpnt, nextPoint);//定位点距离大致算double dis = (d1 + d2) / 5.0;  //平均边长的十分之一处//生成定位点MapPoint pc = GeometryEngine.Instance.ConstructPointFromAngleDistance(currentpnt, GISCommonHelper.GeometryHelper.getAngle(currentpnt, prePoint) + ca / 2.0, dis);if (aindegredd <= tolerance){editOperation.Callback(context => {using RowBuffer rowBuffer = resultFtCls.CreateRowBuffer();rowBuffer[orignoidfdnm] = oid;rowBuffer[corneranglefdnm] = aindegredd;//rowBuffer[targetanglefdnm] = 0;  //指向角度//构建线Polyline pln = GISCommonHelper.GeometryHelper.getPolyline(pc, currentpnt, MapView.Active.Map.SpatialReference);rowBuffer[resultFtCls.GetDefinition().GetShapeField()] = pln;using Feature feature = resultFtCls.CreateRow(rowBuffer);context.Invalidate(feature);}, resultFtCls);}else{//非锐角}}}/// <summary>/// 计算夹角 返回结果弧度/// </summary>/// <param name="cPnt">顶点</param>/// <param name="p1">起点</param>/// <param name="p2">结点</param>/// <returns>弧度</returns>public double calcCornerAngle(MapPoint cPnt, MapPoint p1, MapPoint p2){double a1 = GISCommonHelper.GeometryHelper.getAngle(cPnt, p1);double a2 = GISCommonHelper.GeometryHelper.getAngle(cPnt, p2);double a = a2 - a1;if (a < 0){a = a + Math.PI * 2;}return a;}string ruijiaojcfcname = "锐角检查";/// <summary>/// 创建结果要素类 默认/// </summary>/// <returns></returns>private FeatureClass createResultFtCls(){ruijiaojcfcname = $"{pftlyr.GetDefinition().Name}_锐角检查";var sr = pftlyr.GetFeatureClass().GetDefinition().GetSpatialReference();//在当前数据库中创建var DefaultGDB = Project.Current.DefaultGeodatabasePath;using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(DefaultGDB)))){bool isexist = gdb.FeatureClassExists(ruijiaojcfcname);//如果存在,则先删除if (isexist){var dr=MessageBox.Show("工作空间已经存在锐角检查数据集,是否删除?", "提示", System.Windows.MessageBoxButton.YesNo);if(dr== System.Windows.MessageBoxResult.Yes){//删除已有var featureclass = gdb.OpenDataset<FeatureClass>(ruijiaojcfcname);FeatureClassDescription fdc = new FeatureClassDescription(featureclass.GetDefinition());SchemaBuilder sb3 = new SchemaBuilder(gdb);sb3.Delete(fdc);}else{ruijiaojcfcname = $"锐角检查_{DateTime.Now.GetTimeStamp()}";}progSrc.Progressor.Message = $"创建结果数据集 {ruijiaojcfcname} 完成";}var hasZ = false;var hasM = false;var shapeDescription = new ShapeDescription(GeometryType.Polyline, sr){HasM = hasM,HasZ = hasZ};var f0 = new ArcGIS.Core.Data.DDL.FieldDescription("OBJECTID", FieldType.OID);var f1 = new ArcGIS.Core.Data.DDL.FieldDescription(orignoidfdnm, FieldType.Integer);var f2 = new ArcGIS.Core.Data.DDL.FieldDescription(corneranglefdnm, FieldType.Double);var f3 = new ArcGIS.Core.Data.DDL.FieldDescription(targetanglefdnm, FieldType.Double);var f4 = new ArcGIS.Core.Data.DDL.FieldDescription(summaryfdnm, FieldType.String);f4.Length = 80;var fieldDescriptions = new List<ArcGIS.Core.Data.DDL.FieldDescription>(){f0,f1,f2,f3,f4};//创建FeatureClassDescriptionvar fcDescription = new FeatureClassDescription(ruijiaojcfcname, fieldDescriptions, shapeDescription);//创建SchemaBuilderSchemaBuilder sb = new SchemaBuilder(gdb);sb.Create(fcDescription);bool success = sb.Build();var featureclass2 = gdb.OpenDataset<FeatureClass>(ruijiaojcfcname); ;  //再次打开//添加图层Uri uu = featureclass2.GetPath();var layer = LayerFactory.Instance.CreateLayer(uu, MapView.Active.Map, 0, ruijiaojcfcname);return featureclass2;}}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/740071.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C语言字符函数和字符串函数

前言 今天这篇博客咱们一起来认识一些特殊的函数&#xff0c;在编程的过程中&#xff0c;我们经常要处理字符和字符串&#xff0c;为了方便字符和字符串&#xff0c;C语言提供了一些库函数&#xff0c;让我们一起看看这些函数都有什么功能吧&#xff01;&#xff01;&#xff0…

Linux的目录结构(介绍主要的)

/&#xff1a;根目录&#xff0c;文件系统的起点&#xff0c;包含了所有目录和文件 /bin&#xff1a;存放基本的可执行命令&#xff0c;如ls&#xff0c;cp&#xff0c;rm /lib&#xff1a;主要存放动态链接库 /opt&#xff1a;供第三方软件安装的目录&#xff0c;通常将软件…

C#使用自定义的泛型节点类 Node<T>实现二叉树类BinaryTree<T>及其方法

目录 一、涉及到的知识点 1.Comparer.Default 属性 2.实现二叉树类BinaryTree步骤 &#xff08;1&#xff09;先设计一个泛型节点类 &#xff08;2&#xff09;再设计一个泛型的二叉树类 &#xff08;3&#xff09;最后设计Main方法 二、 使用泛型节点类 Node实现二叉树…

基础刷题50之八(数组元素积的符号)

文章目录 前言一、题目二、力扣官方解释文心一言解释总结 前言 刚上研一&#xff0c;有人劝我好好学C&#xff0c;当时用的不多就没学&#xff0c;现在毕业上班了。在此亡羊补牢了 在此感谢力扣和文心一言 一、题目 数组元素积的符号 已知函数 signFunc(x) 将会根据 x 的正负…

python读取execl里的图片

正常的读取图片 from openpyxl import load_workbook from PIL import Imagefrom openpyxl import load_workbook wb load_workbook(rC:\Users\Administrator\Downloads\output1111.xlsx) ws wb[wb.sheetnames[0]] for image in ws._images:data image.anchor._fromif image…

深耕大屏营销领域的酷开科技,为品牌方带来更多的收益

互联网作为一种新的发展趋势&#xff0c;更是为我们提供了无数的机会和无限可能性&#xff0c;从电子商务时代到社交网络时代&#xff0c;价值文化也成为了品牌与消费者之间紧密联系的关键纽带。而在此背景下&#xff0c;OTT大屏拥有着独特的优势&#xff0c;作为OTT行业内的独…

数据库三大范式设计原则

数据库三大范式 第一范式(确保每列保持原子性) 第一范式是最基本的范式。如果数据库表中的所有字段值都是不可分解的原子值&#xff0c;就说明该数据库表满足了第一范式。 第二范式(确保表中的每列都和主键相关) 第二范式在第一范式的基础之上更进一层。第二范式需要确保数据…

第十节 JDBC事务

如果JDBC连接处于自动提交模式&#xff0c;默认情况下&#xff0c;则每个SQL语句在完成后都会提交到数据库。 对于简单的应用程序可能没有问题&#xff0c;但是有三个原因需要考虑是否关闭自动提交并管理自己的事务 - 提高性能保持业务流程的完整性使用分布式事务 事务能够控…

网络工程师——2024自学

一、怎样从零开始学习网络工程师 当今社会&#xff0c;人人离不开网络。整个IT互联网行业&#xff0c;最好入门的&#xff0c;网络工程师算是一个了。 什么是网络工程师呢&#xff0c;简单来说&#xff0c;就是互联网从设计、建设到运行和维护&#xff0c;都需要网络工程师来…

03在ESP-IDF中使用C++面向对象编程

在ESP-IDF中使用C和C进行混合编译 ESP-IDF是Espressif Systems开发的官方IoT开发框架&#xff0c;用于编程和开发ESP32系列的微控制器。虽然ESP-IDF主要使用C语言编写&#xff0c;但它也支持使用C进行开发 为什么要进行混合编译&#xff1f; C是一种功能强大的编程语言&…

Win11右键菜单恢复经典样式

一、使用Cmd恢复Windows 11上的经典上下文菜单 1.使用管理员权限打开Cmd 2.复制并粘贴以下代码&#xff0c;然后按enter键 reg.exe add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /f 二、使用Cmd恢复Windows 11上的默认…

Spring事务实现原理和工作原理

文章目录 Spring事务实现原理1. **事务管理器&#xff08;Transaction Manager&#xff09;**&#xff1a;2. **事务定义&#xff08;Transaction Definition&#xff09;**&#xff1a;3. **切面&#xff08;Aspect&#xff09;**&#xff1a;4. **代理对象&#xff08;Proxy&…

web中实现一个账号同一时间只能由一个人使用

实现一个账号同一时间只能由一个人使用&#xff0c;通常需要在前端和后端同时进行控制。以下是一个基本的实现方案&#xff1a; 后端实现&#xff1a; 会话管理&#xff1a; 当用户登录时&#xff0c;生成一个唯一的会话标识&#xff08;如Token或Session ID&#xff09;。将该…

Java学习笔记(十五)IO流(二)

字符流 字符流其实就是字节流字符集&#xff0c;他在遇到相关的数据时会转变为相关的字节&#xff0c;例如遇到英文就转变为一个字节&#xff0c;遇到中文转变为三个字节 FileReader&#xff08;读取数据类&#xff09; 作用&#xff1a;纯文本文件-------->程序 将纯文…

【NR 定位】3GPP NR Positioning 5G定位标准解读(十五)-UL-TDOA 定位

前言 3GPP NR Positioning 5G定位标准&#xff1a;3GPP TS 38.305 V18 3GPP 标准网址&#xff1a;Directory Listing /ftp/ 【NR 定位】3GPP NR Positioning 5G定位标准解读&#xff08;一&#xff09;-CSDN博客 【NR 定位】3GPP NR Positioning 5G定位标准解读&#xff08;…

Linux:时间指令 - cal date

Linux&#xff1a;时间指令 - cal & date date指令cal指令 date指令 date用于以指定格式显示时间 我们先看看直接输入date指令的效果&#xff1a; [hxyiZ2zehtehrgzt3wqccrpyfZ CSDN]$ date Tue Mar 12 21:38:01 CST 2024直接输入date指令&#xff0c;得到了以 星期 月 日…

C#,数值计算,解微分方程的龙格-库塔二阶方法与源代码

1 微分方程 含有导数或微分的方程称为微分方程,未知函数为一元函数的微分方程称为常微分方程。 微分方程的阶数 微分方程中导数或微分的最高阶数称为微分方程的阶数。 微分方程的解 使得微分方程成立的函数称为微分方程的解。 微分方程的特解 微分方程的不含任意常数的解称…

软考介绍的创新技术

本博客地址&#xff1a;https://security.blog.csdn.net/article/details/136632895 一. 信息物理系统 1、信息物理系统&#xff08;CPS&#xff09;通过集成先进的感知、计算、通信、控制等信息技术和自动控制技术&#xff0c;构建了物理空间与信息空间中人、机、物、环境、…

蚂蚁集团2025届暑期实习开始啦~

蚂蚁集团2025届暑期实习开始啦&#xff5e;欢迎大家投递信贷事业群-风险管理部的算法岗&#xff0c;找我内推哦&#xff5e;社招也有hc&#xff0c;欢迎大家沟通&#xff01;

LeetCode 2129.将标题首字母大写:模拟(一个变量记录是否该大写)

【LetMeFly】2129.将标题首字母大写&#xff1a;模拟&#xff08;一个变量记录是否该大写&#xff09; 力扣题目链接&#xff1a;https://leetcode.cn/problems/capitalize-the-title/ 给你一个字符串 title &#xff0c;它由单个空格连接一个或多个单词组成&#xff0c;每个…