ArcGIS Pro SDK (七)编辑 6 检查器

ArcGIS Pro SDK (七)编辑 6 检查器

目录

  • [ArcGIS Pro SDK (七)编辑 6 检查器](#ArcGIS Pro SDK (七)编辑 6 检查器)
    • [1 将要素从图层加载到检查器中](#1 将要素从图层加载到检查器中)
    • [2 将地图选择加载到检查器中](#2 将地图选择加载到检查器中)
    • [3 获取所选要素的属性值](#3 获取所选要素的属性值)
    • [4 将地图选择加载到检查器并更改属性](#4 将地图选择加载到检查器并更改属性)
    • [5 使用检查器获取图层方案](#5 使用检查器获取图层方案)
    • [6 添加验证](#6 添加验证)

环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0

1 将要素从图层加载到检查器中

csharp 复制代码
// 获取地图中的第一个要素图层
var firstFeatureLayer = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetLayersAsFlattenedList().
    OfType<ArcGIS.Desktop.Mapping.FeatureLayer>().FirstOrDefault();

// 创建Inspector类的实例
var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();
// 将具有ObjectID 'oid' 的要素加载到Inspector中
await inspector.LoadAsync(firstFeatureLayer, oid);

2 将地图选择加载到检查器中

csharp 复制代码
// 获取地图中当前选择的要素
var selectedFeatures = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection();
// 获取第一个图层及其对应的选择要素的OID列表
var firstSelectionSet = selectedFeatures.ToDictionary().First();

// 创建Inspector类的实例
var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();
// 使用对象ID列表将选定的要素加载到Inspector中
await inspector.LoadAsync(firstSelectionSet.Key, firstSelectionSet.Value);

3 获取所选要素的属性值

csharp 复制代码
QueuedTask.Run(() =>
               {
                   // 获取地图中当前选择的要素
                   var selectedFeatures = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection();

                   // 获取第一个图层及其对应的选择要素的OID列表
                   var firstSelectionSet = selectedFeatures.ToDictionary().First();

                   // 创建Inspector类的实例
                   var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();

                   // 使用对象ID列表将选定的要素加载到Inspector中
                   inspector.Load(firstSelectionSet.Key, firstSelectionSet.Value);

                   // 获取属性值
                   var pscode = inspector["STATE_NAME"];
                   var myGeometry = inspector.Shape;
               });

4 将地图选择加载到检查器并更改属性

csharp 复制代码
// 获取地图中当前选择的要素
var selectedFeatures = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection();
// 获取第一个图层及其对应的选择要素的OID列表
var firstSelectionSet = selectedFeatures.ToDictionary().First();

// 创建Inspector类的实例
var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();
// 使用对象ID列表将选定的要素加载到Inspector中
await inspector.LoadAsync(firstSelectionSet.Key, firstSelectionSet.Value);

// 为字段 "Description" 分配新的属性值
// 如果加载了多个要素,更改将应用于所有要素
inspector["Description"] = "The new value.";
// 作为编辑操作应用更改 - 但没有撤销/重做
await inspector.ApplyAsync();

5 使用检查器获取图层方案

csharp 复制代码
QueuedTask.Run(() =>
               {
                   var firstFeatureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<ArcGIS.Desktop.Mapping.FeatureLayer>().FirstOrDefault();

                   // 创建Inspector类的实例
                   var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();

                   // 加载图层
                   inspector.LoadSchema(firstFeatureLayer);

                   // 迭代属性,查看属性
                   foreach (var attribute in inspector)
                   {
                       var fldName = attribute.FieldName;
                       var fldAlias = attribute.FieldAlias;
                       var fldType = attribute.FieldType;
                       int idxFld = attribute.FieldIndex;
                       var fld = attribute.GetField();
                       var isNullable = attribute.IsNullable;
                       var isEditable = attribute.IsEditable;
                       var isVisible = attribute.IsVisible;
                       var isSystemField = attribute.IsSystemField;
                       var isGeometryField = attribute.IsGeometryField;
                   }
               });

6 添加验证

csharp 复制代码
var insp = new Inspector();
insp.LoadSchema(featLayer);
var attrib = insp.Where(a => a.FieldName == "Mineral").First();

attrib.AddValidate(() =>
                   {
                       if (attrib.CurrentValue.ToString() == "Salt")
                           return Enumerable.Empty<ArcGIS.Desktop.Editing.Attributes.Attribute.ValidationError>();
                       else return new[] { ArcGIS.Desktop.Editing.Attributes.Attribute.ValidationError.Create("Error", ArcGIS.Desktop.Editing.Attributes.Severity.Low) };
                   });
相关推荐
Ray Liang6 小时前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
Scout-leaf3 天前
WPF新手村教程(三)—— 路由事件
c#·wpf
用户298698530143 天前
程序员效率工具:Spire.Doc如何助你一键搞定Word表格排版
后端·c#·.net
mudtools4 天前
搭建一套.net下能落地的飞书考勤系统
后端·c#·.net
玩泥巴的5 天前
搭建一套.net下能落地的飞书考勤系统
c#·.net·二次开发·飞书
唐宋元明清21885 天前
.NET 本地Db数据库-技术方案选型
windows·c#
lindexi5 天前
dotnet DirectX 通过可等待交换链降低输入渲染延迟
c#·directx·d2d·direct2d·vortice
油墨香^_^5 天前
Node.js 安装指南(Mac 版本)
arcgis
qq_454245035 天前
基于组件与行为的树状节点系统
数据结构·c#
bugcome_com5 天前
C# 类的基础与进阶概念详解
c#