【ArcGIS Pro二次开发】(32):选择集(SelectionSet)

在ArcGIS Pro SDK中,SelectionSet类用于处理地图或图层中的【选定要素集合】。

一般情况下,当你使用【选择】工具进行要素的选择时,就会得到【Selection】的内容。

SelectionSet类提供了许多成员、属性和方法,用于管理和操作选择集。


一、SelectionSet的成员和方法

SelectionSet的3个主要成员:Count、isEmpty和item。

1、Count

获取选择集中记录的总数。返回的是一个int值。

2、isEmpty

判断当前选择集是否为空。返回的是一个bool值。

3、item

获取成员对象 ID的列表。返回的是一组long值。

SelectionSet的3个主要方法:Contains、FromDictionary和ToDictionary。

1、Contains

确定指定映射成员中的记录是否在选择集中。

2、FromDictionary

通过字典来创建一个选择集对象。

3、ToDictionary

从选择集创建映射成员及其相应对象 ID 的字典。


二、代码示例

首先要获取当前选择的要素(sel_poly为Geometry):

var selSet = MapView.Active.GetFeatures(sel_poly);

也可以不指定Geometry:

var selSet = MapView.Active.Map.GetSelection();

通过ToDictionary方法转换为字典【Dictionary】:

var selSetDict = selSet.ToDictionary();

如果选择内容比较多而且复杂,而你只想要某种类型的要素,可以作一个筛选:

var selSetDict = selSet.ToDictionary<FeatureLayer>();

视图缩放到选择要素集的范围:

MapView.Active.ZoomTo(MapView.Active.GetFeatures(sel_poly));

平移到选择要素集的范围:

var editOp = new EditOperation() { };
editOp.Move(MapView.Active.SelectFeatures(sel_poly), 500.0, 500.0);
editOp.Execute();

旋转:

var editOp = new EditOperation() { };
editOp.Rotate(MapView.Active.SelectFeatures(sel_poly), origin, 35.0);
editOp.Execute();

通过ToDictionary()和LINQ查询,来获取选择集中的第一个要素:

var selSet = MapView.Active.GetFeatures(sel_poly);
var selSetDict = selSet.ToDictionary();
var insp = new Inspector();
insp.Load(selSetDict.Keys.First(), selSetDict.Values.First());
var selGeom = insp.Shape;

通过SelectFeaturesEx方法获取指定图层的对象ID列表:

var sname = "Points of Interest";
var selSet = MapView.Active.SelectFeaturesEx(sel_poly);
var oids1 = selSet.ToDictionary().Where(kvp => kvp.Key.Name == sname).First().Value;

从对象ID列表中创建选择集:

var addToSelection = new Dictionary<MapMember, List<long>>();
addToSelection.Add(featureLayer, new List<long> { 1506, 2696, 2246, 1647, 948 });
var sset = SelectionSet.FromDictionary(addToSelection);

获取和sel_poly相交的要素类的对象ID:

var selSet = MapView.Active.GetFeatures(sel_poly);
if (selSet.Contains(featureLayer))
{
    var oids = selSet[featureLayer];
}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

规划GIS会

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值