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
相关推荐
古月-一个C++方向的小白5 小时前
C++11之lambda表达式与包装器
开发语言·c++
沐知全栈开发5 小时前
Eclipse 生成 jar 包
开发语言
呼啦啦呼啦啦啦啦啦啦5 小时前
利用pdfjs实现的pdf预览简单demo(包含翻页功能)
android·javascript·pdf
杭州杭州杭州6 小时前
Python笔记
开发语言·笔记·python
tanyongxi667 小时前
C++ AVL树实现详解:平衡二叉搜索树的原理与代码实现
开发语言·c++
阿葱(聪)8 小时前
java 在k8s中的部署流程
java·开发语言·docker·kubernetes
前端 贾公子8 小时前
vue-cli 模式下安装 uni-ui
前端·javascript·windows
浮生带你学Java8 小时前
2025Java面试题及答案整理( 2025年 7 月最新版,持续更新)
java·开发语言·数据库·面试·职场和发展
拾光拾趣录8 小时前
链表合并:双指针与递归
前端·javascript·算法
拼图2098 小时前
element-plus——图标推荐
javascript·vue.js·elementui