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

2024-03-13 04:36

本文主要是介绍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;}}}
}

这篇关于DayDreamInGIS 之 ArcGIS Pro二次开发 锐角检查的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Java实现检查多个时间段是否有重合

《Java实现检查多个时间段是否有重合》这篇文章主要为大家详细介绍了如何使用Java实现检查多个时间段是否有重合,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录流程概述步骤详解China编程步骤1:定义时间段类步骤2:添加时间段步骤3:检查时间段是否有重合步骤4:输出结果示例代码结语作

如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解

《如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解》:本文主要介绍如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别的相关资料,描述了如何使用海康威视设备网络SD... 目录前言开发流程问题和解决方案dll库加载不到的问题老旧版本sdk不兼容的问题关键实现流程总结前言作为

如何在本地部署 DeepSeek Janus Pro 文生图大模型

《如何在本地部署DeepSeekJanusPro文生图大模型》DeepSeekJanusPro模型在本地成功部署,支持图片理解和文生图功能,通过Gradio界面进行交互,展示了其强大的多模态处... 目录什么是 Janus Pro1. 安装 conda2. 创建 python 虚拟环境3. 克隆 janus

shell脚本快速检查192.168.1网段ip是否在用的方法

《shell脚本快速检查192.168.1网段ip是否在用的方法》该Shell脚本通过并发ping命令检查192.168.1网段中哪些IP地址正在使用,脚本定义了网络段、超时时间和并行扫描数量,并使用... 目录脚本:检查 192.168.1 网段 IP 是否在用脚本说明使用方法示例输出优化建议总结检查 1

Ubuntu 24.04 LTS怎么关闭 Ubuntu Pro 更新提示弹窗?

《Ubuntu24.04LTS怎么关闭UbuntuPro更新提示弹窗?》Ubuntu每次开机都会弹窗提示安全更新,设置里最多只能取消自动下载,自动更新,但无法做到直接让自动更新的弹窗不出现,... 如果你正在使用 Ubuntu 24.04 LTS,可能会注意到——在使用「软件更新器」或运行 APT 命令时,

最便宜的8口2.5G网管交换机! 水星SE109 Pro拆机测评

《最便宜的8口2.5G网管交换机!水星SE109Pro拆机测评》水星SE109Pro价格很便宜,水星SE109Pro,外观、接口,和SE109一样,区别Pro是网管型的,下面我们就来看看详细拆... 听说水星SE109 Pro开卖了,PDD卖 220元,于是买回来javascript拆机看看。推荐阅读:水

使用Python检查CPU型号并弹出警告信息

《使用Python检查CPU型号并弹出警告信息》本教程将指导你如何编写一个Python程序,该程序能够在启动时检查计算机的CPU型号,如果检测到CPU型号包含“I3”,则会弹出一个警告窗口,感兴趣的小... 目录教程目标方法一所需库步骤一:安装所需库步骤二:编写python程序步骤三:运行程序注意事项方法二

husky 工具配置代码检查工作流:提交代码至仓库前做代码检查

提示:这篇博客以我前两篇博客作为先修知识,请大家先去看看我前两篇博客 博客指路:前端 ESlint 代码规范及修复代码规范错误-CSDN博客前端 Vue3 项目开发—— ESLint & prettier 配置代码风格-CSDN博客 husky 工具配置代码检查工作流的作用 在工作中,我们经常需要将写好的代码提交至代码仓库 但是由于程序员疏忽而将不规范的代码提交至仓库,显然是不合理的 所

VMware Fusion Pro 13 Mac版虚拟机 安装Win11系统教程

Mac分享吧 文章目录 Win11安装完成,软件打开效果一、VMware安装Windows11虚拟机1️⃣:准备镜像2️⃣:创建虚拟机3️⃣:虚拟机设置4️⃣:安装虚拟机5️⃣:解决连不上网问题 安装完成!!! Win11安装完成,软件打开效果 一、VMware安装Windows11虚拟机 首先确保自己的mac开启了网络共享。不然虚拟机连不上👀的 1️⃣:准备镜像

ArcGIS Pro 克隆clone python环境报错问题处理方法

ArcGIS Pro 克隆clone python环境报错问题处理方法 (一)安装arcpro和深度学习安装包 首先安装arcgis pro桌面版和深度学习安装包后 然后克隆默认 Python 环境 arcgispro-py3 接下来,安装以下 Python 软件包:Tensorflow、fast.ai、Keras、Pytorch、Scikit-image、Pillow 和 Libtiff。 切