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
相关推荐
wainyz3 分钟前
Java NIO操作
java·开发语言·nio
熊的猫11 分钟前
webpack 核心模块 — loader & plugins
前端·javascript·chrome·webpack·前端框架·node.js·ecmascript
喵叔哟11 分钟前
重构代码之用委托替代继承
开发语言·重构
lzb_kkk17 分钟前
【JavaEE】JUC的常见类
java·开发语言·java-ee
SEEONTIME17 分钟前
python-24-一篇文章彻底掌握Python HTTP库Requests
开发语言·python·http·http库requests
起名字真南35 分钟前
【OJ题解】C++实现字符串大数相乘:无BigInteger库的字符串乘积解决方案
开发语言·c++·leetcode
tyler_download1 小时前
golang 实现比特币内核:实现基于椭圆曲线的数字签名和验证
开发语言·数据库·golang
小小小~1 小时前
qt5将程序打包并使用
开发语言·qt
hlsd#1 小时前
go mod 依赖管理
开发语言·后端·golang
小春学渗透1 小时前
Day107:代码审计-PHP模型开发篇&MVC层&RCE执行&文件对比法&1day分析&0day验证
开发语言·安全·web安全·php·mvc