ARCGIS PRO SDK 常用的选择操作

一、'获取当前图层FeatureLayer选择要素: ly选择要素

Dim selSet As Selection = ly.GetSelection()

二、获取当前激活的地图选择要素集: 不同层的所有的选择要素

Dim selSet As SelectionSet = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection()

三、用例

Map:获取地图的选择。 必须在 MCT 上调用此方法。使用 QueuedTask.Run

1、将地图选择加载到 Inspector 中

c+

复制代码
// 获取地图中的当前所选要素
var selectedFeatures = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection();
// 获取第一个图层及其对应的所选要素OID
var firstSelectionSet = selectedFeatures.ToDictionary().First();
// 创建检查器类的实例
var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();
// 使用对象ID列表将所选要素加载到检查器中
await inspector.LoadAsync(firstSelectionSet.Key, firstSelectionSet.Value);

vb :将地图选择加载到 Inspector 中

复制代码
'获取当前地图选择要素
Dim selSet As SelectionSet = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection()
'获取第一个图层及其对应的所选要素OID
Dim firstSelectionSet = selSet.ToDictionary().First()
'写入字典
Dim selSetDict As Dictionary(Of MapMember, List(Of Long)) = selSet.ToDictionary()
'创建检查器类的实例
Dim insp = new ArcGIS.Desktop.Editing.Attributes.Inspector
'使用对象ID列表将所选要素加载到检查器中
await insp.inspector.LoadAsync(firstSelectionSet.Key, firstSelectionSet.Value)

vb:将地图图层选择加载到 Inspector 中,统一修改属性MOMC

复制代码
'获取当前地图选择要素
Dim selSet As SelectionSet = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection()
'Featurelayer ly选择的要素读入列表
Dim selSetDict As List(Of Long) = selSet.ToDictionary(ly)
'创建检查器类的实例
Dim insp = New ArcGIS.Desktop.Editing.Attributes.Inspector()
'使用对象ID列表将所选要素加载到检查器中
Await insp.LoadAsync(ly, selSetDict)
'如果统一修改属性
Dim modifyFeature = New EditOperation()
modifyFeature.Name = "修改属性"
Insp["MOMC"] = 24;
modifyFeatures.Modify(Insp)
if modifyFeatures.IsEmpty Then
   dim result = Await modifyFeatures.ExecuteAsync()
end if 

vb:将地图图层选择加的要素遍历:对线要素点序反转

复制代码
Dim selGeom As ArcGIS.Core.Geometry.Polyline
'获取当前地图选择要素
Dim selSet As SelectionSet = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection()
'Featurelayer ly选择的要素读入列表
Dim selSetDict As List(Of Long) = selSet.ToDictionary(ly)
Dim selSetDict As List(Of Long) = selSet.ToDictionary(ly)
For Each lva As Long In selSetDict    '图层循环
    Dim modifyFeature = New EditOperation()
    modifyFeature.Name = "线反转"
    '创建检查器类的实例
    Dim insp = New ArcGIS.Desktop.Editing.Attributes.Inspector()
    '使用对象ID列表将所选要素加载到检查器中
    Await insp.LoadAsync(ly, lva)
    '获取图形进行反向处理
    selGeom = GeometryEngine.Instance.ReverseOrientation(insp.Shape)
    insp.Shape=selGeom
   modifyFeature.Modify(insp)
   If modifyFeature.IsEmpty then
      dim result = modifyFeature.ExecuteAsync()
   End if
Next

vb:将地图图层选择加的要素遍历:转Feature对线要素点序反转

复制代码
Dim pFeature As Feature
Dim selGeom As ArcGIS.Core.Geometry.Polyline
Dim rows As RowCursor
Dim selSet As Selection = ly.GetSelection()    '获取当前图层选择要素
If selSet.GetCount = 0 Then
    MsgBox("选择的要素层未选择线要素,不能执行.")
    Exit Sub
End If
rows = selSet.Search(Nothing.false)
Do While rows.MoveNext
    pFeature = rows.Current
    selGeom = GeometryEngine.Instance.ReverseOrientation(pFeature.GetShape)
    pFeature.SetShape(selGeom)
    pFeature.Store()
Loop

3、选择要素闪烁功能

c+

复制代码
​​​​​​​public Task FlashSelectedFeaturesAsync()
{
  return QueuedTask.Run(() =>
  {
    //Get the active map view.
    var mapView = MapView.Active;
    if (mapView == null)
      return;

    //从地图中获取所选要素并过滤掉独立表选择.
    //var selectedFeatures = mapView.Map.GetSelection()
    //    .Where(kvp => kvp.Key is BasicFeatureLayer)
    //    .ToDictionary(kvp => (BasicFeatureLayer)kvp.Key, kvp => kvp.Value);

    刷新功能集合.
    //mapView.FlashFeature(selectedFeatures);

    var selectedFeatures = mapView.Map.GetSelection();

    //刷新功能集合.
    mapView.FlashFeature(selectedFeatures);
  });
}

vb

复制代码
Dim mapView = MapView.Active
If mapView IS NOTHING =FALSE THEN
       DIM  selectedFeatures = mapView.Map.GetSelection()
      '刷新功能集合.
       mapView.FlashFeature(selectedFeatures)
END IF
相关推荐
幽蓝计划11 分钟前
HarmonyOS NEXT仓颉开发语言实战案例:外卖App
开发语言·harmonyos
伍哥的传说17 分钟前
鸿蒙系统(HarmonyOS)应用开发之实现电子签名效果
开发语言·前端·华为·harmonyos·鸿蒙·鸿蒙系统
海的诗篇_1 小时前
前端开发面试题总结-原生小程序部分
前端·javascript·面试·小程序·vue·html
小张成长计划..1 小时前
数据结构-栈的实现
开发语言·数据结构
旷世奇才李先生1 小时前
Lua 安装使用教程
开发语言·lua
Zonda要好好学习1 小时前
Python入门Day2
开发语言·python
不良手残2 小时前
IDEA类和方法注释模板设置-保姆教程
java·开发语言
项目題供诗2 小时前
黑马python(二十四)
开发语言·python
就改了2 小时前
JUC小册——公平锁和非公平锁
java·开发语言
黄瓜沾糖吃2 小时前
大佬们指点一下倒计时有什么问题吗?
前端·javascript