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
相关推荐
江城开朗的豌豆14 分钟前
JavaScript篇:回调地狱退散!6年老前端教你写出优雅异步代码
前端·javascript·面试
TE-茶叶蛋26 分钟前
Vue Fragment vs React Fragment
javascript·vue.js·react.js
我很好我还能学43 分钟前
【面试篇 9】c++生成可执行文件的四个步骤、悬挂指针、define和const区别、c++定义和声明、将引用作为返回值的好处、类的四个缺省函数
开发语言·c++
蓝婷儿1 小时前
6个月Python学习计划 Day 16 - 面向对象编程(OOP)基础
开发语言·python·学习
渣渣盟1 小时前
基于Scala实现Flink的三种基本时间窗口操作
开发语言·flink·scala
糯米导航2 小时前
Java毕业设计:办公自动化系统的设计与实现
java·开发语言·课程设计
糯米导航2 小时前
Java毕业设计:WML信息查询与后端信息发布系统开发
java·开发语言·课程设计
Carlos_sam2 小时前
Opnelayers:封装Popup
前端·javascript
MessiGo2 小时前
Javascript 编程基础(5)面向对象 | 5.1、构造函数实例化对象
开发语言·javascript·原型模式
大霞上仙2 小时前
nonlocal 与global关键字
开发语言·python