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) };
                   });
相关推荐
用户7884773163416 小时前
WinForms 迁移 WPF:Upgrade Assistant 覆盖 30%,剩下 70% 我手写了六周
c#
总要学点什么20 小时前
第105篇:三维特效-流动图片墙体效果——让箭头沿墙长滚,它俩竟是同一份代码
开发语言·javascript·ecmascript·gis·webgl·材质·cesium
寂寞的船21 小时前
【Unity知识速递】第13期 Unity 内存泄漏排查实战:从 Memory Profiler 到 Lua 引用泄漏的生产级全链路诊断
unity·junit·c#·游戏引擎·lua
总要学点什么1 天前
第104篇:三维特效-流动墙体效果——让贴图沿墙流动,它却只肯走一条对角线
开发语言·javascript·ecmascript·gis·webgl·材质·cesium
用户3721574261352 天前
C# 提取 PDF 附件:包括文档附件和页面注释附件
c#
寂寞的船2 天前
【Unity Bug挑战】第12期 Awaitable 二次 await 死锁之谜 —— 为什么同一个异步操作等两次就卡死?
unity·c#·游戏引擎·bug
huaqianzkh3 天前
WinForm C#:循环修改控件UI闪烁卡顿?SuspendLayout / ResumeLayout 与 BeginUpdate 优化
开发语言·ui·c#
用户3721574261354 天前
C# 实现 Excel 单元格保护:锁定公式并允许编辑指定区域
c#·ai编程·编程语言
总要学点什么4 天前
第96篇:三维数据加载-城市建筑白模样式+着色器——让色带按体量上色,最白的那档却涂不上去
前端·gis·webgl·cesium·着色器·空间分析·白模
公子小六4 天前
基于.NET的Windows窗体编程之WinForms数据持久化(1)
windows·microsoft·c#·.net·winforms